Skip to content

Commit

Permalink
chore: fix jest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrrt committed Jan 1, 2024
1 parent eea63cd commit 5545cd0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {

moduleFileExtensions: ["ts", "js"],
transform: {
"^.+\\.(ts)$": "ts-jest",
Expand All @@ -19,4 +18,5 @@ module.exports = {
"<rootDir>/lib/**/*.ts",
"<rootDir>/lib/**/**/*.ts"
],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
}
7 changes: 7 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fetch = require('node-fetch');
const { Headers } = fetch;

if (!global.fetch) {
global.fetch = fetch;
global.Headers = Headers;
}
9 changes: 0 additions & 9 deletions src/vendors/jwks/jwks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ import {
import { JwtAlgorithmsEnum as Algs, JwtKeyTypes as Kty } from "../../enums";
import { default as nock } from "nock";

// TODO: move this to jest config
import fetch, { Headers } from "node-fetch";

// https://stackoverflow.com/a/75956506/8483084
if (!globalThis.fetch) {
globalThis.fetch = fetch;
globalThis.Headers = Headers;
}

import * as c from "../../constants";
import { SignJWT, jwtVerify } from "jose";
const AUTHDOG_API_ROOT = "https://api.authdog.xyz";
Expand Down
9 changes: 0 additions & 9 deletions src/vendors/jwt/jwt-verify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ import * as c from "../../constants";
import { getKeyPair, signJwtWithPrivateKey } from "./jwt-sign";
import nock from "nock";

// TODO: move this to jest config
import fetch, { Headers } from "node-fetch";

// https://stackoverflow.com/a/75956506/8483084
if (!globalThis.fetch) {
globalThis.fetch = fetch;
globalThis.Headers = Headers;
}

const DUMMY_HS256_TOKEN =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
const DUMMY_NON_JWT_TOKEN = "hello-i-am-not-a-jwt";
Expand Down

0 comments on commit 5545cd0

Please sign in to comment.