feat: jest

This commit is contained in:
Dogtiti 2024-08-06 18:03:27 +08:00
parent 94c4cf0624
commit 1ef2aa35e9
5 changed files with 2083 additions and 103 deletions

21
jest.config.ts Normal file
View File

@ -0,0 +1,21 @@
import type { Config } from "jest";
import nextJest from "next/jest.js";
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});
// Add any custom config to be passed to Jest
const config: Config = {
coverageProvider: "v8",
testEnvironment: "jsdom",
testMatch: ["**/*.test.js", "**/*.test.ts", "**/*.test.jsx", "**/*.test.tsx"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/$1",
},
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config);

2
jest.setup.ts Normal file
View File

@ -0,0 +1,2 @@
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";

View File

@ -1,76 +1,84 @@
{ {
"name": "nextchat", "name": "nextchat",
"private": false, "private": false,
"license": "mit", "license": "mit",
"scripts": { "scripts": {
"mask": "npx tsx app/masks/build.ts", "mask": "npx tsx app/masks/build.ts",
"mask:watch": "npx watch \"yarn mask\" app/masks", "mask:watch": "npx watch \"yarn mask\" app/masks",
"dev": "concurrently -r \"yarn run mask:watch\" \"next dev\"", "dev": "concurrently -r \"yarn run mask:watch\" \"next dev\"",
"build": "yarn mask && cross-env BUILD_MODE=standalone next build", "build": "yarn mask && cross-env BUILD_MODE=standalone next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",
"export": "yarn mask && cross-env BUILD_MODE=export BUILD_APP=1 next build", "export": "yarn mask && cross-env BUILD_MODE=export BUILD_APP=1 next build",
"export:dev": "concurrently -r \"yarn mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"", "export:dev": "concurrently -r \"yarn mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"",
"app:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri dev\"", "app:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri dev\"",
"app:build": "yarn mask && yarn tauri build", "app:build": "yarn mask && yarn tauri build",
"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",
"dependencies": { "test:ci": "jest --ci"
"@fortaine/fetch-event-source": "^3.0.6", },
"@hello-pangea/dnd": "^16.5.0", "dependencies": {
"@next/third-parties": "^14.1.0", "@fortaine/fetch-event-source": "^3.0.6",
"@svgr/webpack": "^6.5.1", "@hello-pangea/dnd": "^16.5.0",
"@vercel/analytics": "^0.1.11", "@next/third-parties": "^14.1.0",
"@vercel/speed-insights": "^1.0.2", "@svgr/webpack": "^6.5.1",
"emoji-picker-react": "^4.9.2", "@vercel/analytics": "^0.1.11",
"fuse.js": "^7.0.0", "@vercel/speed-insights": "^1.0.2",
"heic2any": "^0.0.4", "emoji-picker-react": "^4.9.2",
"html-to-image": "^1.11.11", "fuse.js": "^7.0.0",
"lodash-es": "^4.17.21", "heic2any": "^0.0.4",
"mermaid": "^10.6.1", "html-to-image": "^1.11.11",
"nanoid": "^5.0.3", "lodash-es": "^4.17.21",
"next": "^14.1.1", "mermaid": "^10.6.1",
"node-fetch": "^3.3.1", "nanoid": "^5.0.3",
"react": "^18.2.0", "next": "^14.1.1",
"react-dom": "^18.2.0", "node-fetch": "^3.3.1",
"react-markdown": "^8.0.7", "react": "^18.2.0",
"react-router-dom": "^6.15.0", "react-dom": "^18.2.0",
"rehype-highlight": "^6.0.0", "react-markdown": "^8.0.7",
"rehype-katex": "^6.0.3", "react-router-dom": "^6.15.0",
"remark-breaks": "^3.0.2", "rehype-highlight": "^6.0.0",
"remark-gfm": "^3.0.1", "rehype-katex": "^6.0.3",
"remark-math": "^5.1.1", "remark-breaks": "^3.0.2",
"sass": "^1.59.2", "remark-gfm": "^3.0.1",
"spark-md5": "^3.0.2", "remark-math": "^5.1.1",
"use-debounce": "^9.0.4", "sass": "^1.59.2",
"zustand": "^4.3.8" "spark-md5": "^3.0.2",
}, "use-debounce": "^9.0.4",
"devDependencies": { "zustand": "^4.3.8"
"@tauri-apps/cli": "1.5.11", },
"@types/lodash-es": "^4.17.12", "devDependencies": {
"@types/node": "^20.11.30", "@tauri-apps/cli": "1.5.11",
"@types/react": "^18.2.70", "@testing-library/jest-dom": "^6.4.8",
"@types/react-dom": "^18.2.7", "@testing-library/react": "^16.0.0",
"@types/react-katex": "^3.0.0", "@types/jest": "^29.5.12",
"@types/spark-md5": "^3.0.4", "@types/lodash-es": "^4.17.12",
"concurrently": "^8.2.2", "@types/node": "^20.11.30",
"cross-env": "^7.0.3", "@types/react": "^18.2.70",
"eslint": "^8.49.0", "@types/react-dom": "^18.2.7",
"eslint-config-next": "13.4.19", "@types/react-katex": "^3.0.0",
"eslint-config-prettier": "^8.8.0", "@types/spark-md5": "^3.0.4",
"eslint-plugin-prettier": "^5.1.3", "concurrently": "^8.2.2",
"husky": "^8.0.0", "cross-env": "^7.0.3",
"lint-staged": "^13.2.2", "eslint": "^8.49.0",
"prettier": "^3.0.2", "eslint-config-next": "13.4.19",
"tsx": "^4.16.0", "eslint-config-prettier": "^8.8.0",
"typescript": "5.2.2", "eslint-plugin-prettier": "^5.1.3",
"watch": "^1.0.2", "husky": "^8.0.0",
"webpack": "^5.88.1" "jest": "^29.7.0",
}, "jest-environment-jsdom": "^29.7.0",
"resolutions": { "lint-staged": "^13.2.2",
"lint-staged/yaml": "^2.2.2" "prettier": "^3.0.2",
}, "ts-node": "^10.9.2",
"packageManager": "yarn@1.22.19" "tsx": "^4.16.0",
"typescript": "5.2.2",
"watch": "^1.0.2",
"webpack": "^5.88.1"
},
"resolutions": {
"lint-staged/yaml": "^2.2.2"
},
"packageManager": "yarn@1.22.19"
} }

9
test/sum-module.test.ts Normal file
View File

@ -0,0 +1,9 @@
function sum(a: number, b: number) {
return a + b;
}
describe("sum module", () => {
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
});

1998
yarn.lock

File diff suppressed because it is too large Load Diff