test: fix unit test failures

This commit is contained in:
Vangie Du 2025-03-07 14:49:17 +08:00
parent f7cde17919
commit 0d41a17ef6
4 changed files with 10 additions and 9 deletions

View File

@ -15,6 +15,8 @@ const config: Config = {
moduleNameMapper: { moduleNameMapper: {
"^@/(.*)$": "<rootDir>/$1", "^@/(.*)$": "<rootDir>/$1",
}, },
extensionsToTreatAsEsm: [".ts", ".tsx"],
injectGlobals: true,
}; };
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async

View File

@ -1,24 +1,22 @@
// Learn more: https://github.com/testing-library/jest-dom // Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom"; import "@testing-library/jest-dom";
import { jest } from "@jest/globals";
global.fetch = jest.fn(() => global.fetch = jest.fn(() =>
Promise.resolve({ Promise.resolve({
ok: true, ok: true,
status: 200, status: 200,
json: () => Promise.resolve({}), json: () => Promise.resolve([]),
headers: new Headers(), headers: new Headers(),
redirected: false, redirected: false,
statusText: "OK", statusText: "OK",
type: "basic", type: "basic",
url: "", url: "",
clone: function () {
return this;
},
body: null, body: null,
bodyUsed: false, bodyUsed: false,
arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)), arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
blob: () => Promise.resolve(new Blob()), blob: () => Promise.resolve(new Blob()),
formData: () => Promise.resolve(new FormData()), formData: () => Promise.resolve(new FormData()),
text: () => Promise.resolve(""), text: () => Promise.resolve(""),
}), } as Response),
); );

View File

@ -17,8 +17,8 @@
"prompts": "node ./scripts/fetch-prompts.mjs", "prompts": "node ./scripts/fetch-prompts.mjs",
"prepare": "husky install", "prepare": "husky install",
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev", "proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev",
"test": "jest --watch", "test": "node --no-warnings --experimental-vm-modules $(yarn bin jest) --watch",
"test:ci": "jest --ci" "test:ci": "node --no-warnings --experimental-vm-modules $(yarn bin jest) --ci"
}, },
"dependencies": { "dependencies": {
"@fortaine/fetch-event-source": "^3.0.6", "@fortaine/fetch-event-source": "^3.0.6",

View File

@ -1,3 +1,4 @@
import { jest } from "@jest/globals";
import { isVisionModel } from "../app/utils"; import { isVisionModel } from "../app/utils";
describe("isVisionModel", () => { describe("isVisionModel", () => {