Skip to content

Commit b6f5d75

Browse files
authored
Merge pull request ChatGPTNextWeb#6344 from vangie/fix/jest-setup-esm
test: fix unit test failures
2 parents f7cde17 + 0d41a17 commit b6f5d75

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

jest.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const config: Config = {
1515
moduleNameMapper: {
1616
"^@/(.*)$": "<rootDir>/$1",
1717
},
18+
extensionsToTreatAsEsm: [".ts", ".tsx"],
19+
injectGlobals: true,
1820
};
1921

2022
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async

jest.setup.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
// Learn more: https://github.com/testing-library/jest-dom
22
import "@testing-library/jest-dom";
3+
import { jest } from "@jest/globals";
34

45
global.fetch = jest.fn(() =>
56
Promise.resolve({
67
ok: true,
78
status: 200,
8-
json: () => Promise.resolve({}),
9+
json: () => Promise.resolve([]),
910
headers: new Headers(),
1011
redirected: false,
1112
statusText: "OK",
1213
type: "basic",
1314
url: "",
14-
clone: function () {
15-
return this;
16-
},
1715
body: null,
1816
bodyUsed: false,
1917
arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
2018
blob: () => Promise.resolve(new Blob()),
2119
formData: () => Promise.resolve(new FormData()),
2220
text: () => Promise.resolve(""),
23-
}),
21+
} as Response),
2422
);

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"prompts": "node ./scripts/fetch-prompts.mjs",
1818
"prepare": "husky install",
1919
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev",
20-
"test": "jest --watch",
21-
"test:ci": "jest --ci"
20+
"test": "node --no-warnings --experimental-vm-modules $(yarn bin jest) --watch",
21+
"test:ci": "node --no-warnings --experimental-vm-modules $(yarn bin jest) --ci"
2222
},
2323
"dependencies": {
2424
"@fortaine/fetch-event-source": "^3.0.6",

test/vision-model-checker.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jest } from "@jest/globals";
12
import { isVisionModel } from "../app/utils";
23

34
describe("isVisionModel", () => {
@@ -50,7 +51,7 @@ describe("isVisionModel", () => {
5051

5152
test("should identify models from VISION_MODELS env var", () => {
5253
process.env.VISION_MODELS = "custom-vision-model,another-vision-model";
53-
54+
5455
expect(isVisionModel("custom-vision-model")).toBe(true);
5556
expect(isVisionModel("another-vision-model")).toBe(true);
5657
expect(isVisionModel("unrelated-model")).toBe(false);
@@ -64,4 +65,4 @@ describe("isVisionModel", () => {
6465
expect(isVisionModel("unrelated-model")).toBe(false);
6566
expect(isVisionModel("gpt-4-vision")).toBe(true);
6667
});
67-
});
68+
});

0 commit comments

Comments
 (0)