Skip to content

Commit

Permalink
Add jest test configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepsinn committed Sep 16, 2024
1 parent 1575354 commit 08e4d22
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
Empty file removed apps/nextjs/.eslintrc.json
Empty file.
16 changes: 16 additions & 0 deletions apps/nextjs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const nextJest = require("next/jest")

const createJestConfig = nextJest({
dir: "./",
})

const customJestConfig = {
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/$1",
},
setupFiles: ["./jest.polyfills.js"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testEnvironment: "jest-environment-jsdom",
}

module.exports = createJestConfig(customJestConfig)
36 changes: 36 additions & 0 deletions apps/nextjs/jest.polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// jest.polyfills.js
/**
* @note The block below contains polyfills for Node.js globals
* required for Jest to function when running JSDOM tests.
* These HAVE to be require's and HAVE to be in this exact
* order, since "undici" depends on the "TextEncoder" global API.
*
* Consider migrating to a more modern test runner if
* you don't want to deal with this.
*/

const { TextDecoder, TextEncoder } = require("node:util")

Object.defineProperties(globalThis, {
TextDecoder: { value: TextDecoder },
TextEncoder: { value: TextEncoder },
})

//const { TransformStream, ReadableStream } = require('web-streams-polyfill');
// Object.defineProperties(globalThis, {
// TransformStream: { value: TransformStream },
// ReadableStream: { value: ReadableStream },
// });
// Break API requests during tests
//const { Blob, File } = require('node:buffer')
// const { fetch, Headers, FormData, Request, Response } = require('undici')
//
// Object.defineProperties(globalThis, {
// fetch: { value: fetch, writable: true },
// Blob: { value: Blob },
// File: { value: File },
// Headers: { value: Headers },
// FormData: { value: FormData },
// Request: { value: Request },
// Response: { value: Response },
// })
2 changes: 2 additions & 0 deletions apps/nextjs/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom"
3 changes: 1 addition & 2 deletions apps/nextjs/tests/fdai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* @jest-environment node
*/
import {foodOrDrugCostBenefitAnalysis, safeUnapprovedDrugs} from "@/lib/fdaiAgent";
beforeAll(async () => {
});

describe("FDAi Tests", () => {
it("cost-benefit analysis", async () => {
const result = await foodOrDrugCostBenefitAnalysis("NMN");
Expand Down
11 changes: 8 additions & 3 deletions apps/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
],
"paths": {
"@/*": ["./*"]
},
"types": ["node", "jest", "@testing-library/jest-dom"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"trigger.config.ts"
],
"exclude": ["node_modules"]
}
32 changes: 4 additions & 28 deletions apps/nextjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9950,16 +9950,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -10031,14 +10022,7 @@ stringify-entities@^4.0.0:
character-entities-html4 "^2.0.0"
character-entities-legacy "^3.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -11046,16 +11030,8 @@ widest-line@^4.0.1:
dependencies:
string-width "^5.0.1"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down

0 comments on commit 08e4d22

Please sign in to comment.