Skip to content

Commit 1ef2aa3

Browse files
committed
feat: jest
1 parent 94c4cf0 commit 1ef2aa3

File tree

5 files changed

+2086
-106
lines changed

5 files changed

+2086
-106
lines changed

Diff for: jest.config.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Config } from "jest";
2+
import nextJest from "next/jest.js";
3+
4+
const createJestConfig = nextJest({
5+
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
6+
dir: "./",
7+
});
8+
9+
// Add any custom config to be passed to Jest
10+
const config: Config = {
11+
coverageProvider: "v8",
12+
testEnvironment: "jsdom",
13+
testMatch: ["**/*.test.js", "**/*.test.ts", "**/*.test.jsx", "**/*.test.tsx"],
14+
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
15+
moduleNameMapper: {
16+
"^@/(.*)$": "<rootDir>/$1",
17+
},
18+
};
19+
20+
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
21+
export default createJestConfig(config);

Diff for: jest.setup.ts

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

Diff for: package.json

+82-74
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,84 @@
11
{
2-
"name": "nextchat",
3-
"private": false,
4-
"license": "mit",
5-
"scripts": {
6-
"mask": "npx tsx app/masks/build.ts",
7-
"mask:watch": "npx watch \"yarn mask\" app/masks",
8-
"dev": "concurrently -r \"yarn run mask:watch\" \"next dev\"",
9-
"build": "yarn mask && cross-env BUILD_MODE=standalone next build",
10-
"start": "next start",
11-
"lint": "next lint",
12-
"export": "yarn mask && cross-env BUILD_MODE=export BUILD_APP=1 next build",
13-
"export:dev": "concurrently -r \"yarn mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"",
14-
"app:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri dev\"",
15-
"app:build": "yarn mask && yarn tauri build",
16-
"prompts": "node ./scripts/fetch-prompts.mjs",
17-
"prepare": "husky install",
18-
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev"
19-
},
20-
"dependencies": {
21-
"@fortaine/fetch-event-source": "^3.0.6",
22-
"@hello-pangea/dnd": "^16.5.0",
23-
"@next/third-parties": "^14.1.0",
24-
"@svgr/webpack": "^6.5.1",
25-
"@vercel/analytics": "^0.1.11",
26-
"@vercel/speed-insights": "^1.0.2",
27-
"emoji-picker-react": "^4.9.2",
28-
"fuse.js": "^7.0.0",
29-
"heic2any": "^0.0.4",
30-
"html-to-image": "^1.11.11",
31-
"lodash-es": "^4.17.21",
32-
"mermaid": "^10.6.1",
33-
"nanoid": "^5.0.3",
34-
"next": "^14.1.1",
35-
"node-fetch": "^3.3.1",
36-
"react": "^18.2.0",
37-
"react-dom": "^18.2.0",
38-
"react-markdown": "^8.0.7",
39-
"react-router-dom": "^6.15.0",
40-
"rehype-highlight": "^6.0.0",
41-
"rehype-katex": "^6.0.3",
42-
"remark-breaks": "^3.0.2",
43-
"remark-gfm": "^3.0.1",
44-
"remark-math": "^5.1.1",
45-
"sass": "^1.59.2",
46-
"spark-md5": "^3.0.2",
47-
"use-debounce": "^9.0.4",
48-
"zustand": "^4.3.8"
49-
},
50-
"devDependencies": {
51-
"@tauri-apps/cli": "1.5.11",
52-
"@types/lodash-es": "^4.17.12",
53-
"@types/node": "^20.11.30",
54-
"@types/react": "^18.2.70",
55-
"@types/react-dom": "^18.2.7",
56-
"@types/react-katex": "^3.0.0",
57-
"@types/spark-md5": "^3.0.4",
58-
"concurrently": "^8.2.2",
59-
"cross-env": "^7.0.3",
60-
"eslint": "^8.49.0",
61-
"eslint-config-next": "13.4.19",
62-
"eslint-config-prettier": "^8.8.0",
63-
"eslint-plugin-prettier": "^5.1.3",
64-
"husky": "^8.0.0",
65-
"lint-staged": "^13.2.2",
66-
"prettier": "^3.0.2",
67-
"tsx": "^4.16.0",
68-
"typescript": "5.2.2",
69-
"watch": "^1.0.2",
70-
"webpack": "^5.88.1"
71-
},
72-
"resolutions": {
73-
"lint-staged/yaml": "^2.2.2"
74-
},
75-
"packageManager": "[email protected]"
2+
"name": "nextchat",
3+
"private": false,
4+
"license": "mit",
5+
"scripts": {
6+
"mask": "npx tsx app/masks/build.ts",
7+
"mask:watch": "npx watch \"yarn mask\" app/masks",
8+
"dev": "concurrently -r \"yarn run mask:watch\" \"next dev\"",
9+
"build": "yarn mask && cross-env BUILD_MODE=standalone next build",
10+
"start": "next start",
11+
"lint": "next lint",
12+
"export": "yarn mask && cross-env BUILD_MODE=export BUILD_APP=1 next build",
13+
"export:dev": "concurrently -r \"yarn mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"",
14+
"app:dev": "concurrently -r \"yarn mask:watch\" \"yarn tauri dev\"",
15+
"app:build": "yarn mask && yarn tauri build",
16+
"prompts": "node ./scripts/fetch-prompts.mjs",
17+
"prepare": "husky install",
18+
"proxy-dev": "sh ./scripts/init-proxy.sh && proxychains -f ./scripts/proxychains.conf yarn dev",
19+
"test": "jest --watch",
20+
"test:ci": "jest --ci"
21+
},
22+
"dependencies": {
23+
"@fortaine/fetch-event-source": "^3.0.6",
24+
"@hello-pangea/dnd": "^16.5.0",
25+
"@next/third-parties": "^14.1.0",
26+
"@svgr/webpack": "^6.5.1",
27+
"@vercel/analytics": "^0.1.11",
28+
"@vercel/speed-insights": "^1.0.2",
29+
"emoji-picker-react": "^4.9.2",
30+
"fuse.js": "^7.0.0",
31+
"heic2any": "^0.0.4",
32+
"html-to-image": "^1.11.11",
33+
"lodash-es": "^4.17.21",
34+
"mermaid": "^10.6.1",
35+
"nanoid": "^5.0.3",
36+
"next": "^14.1.1",
37+
"node-fetch": "^3.3.1",
38+
"react": "^18.2.0",
39+
"react-dom": "^18.2.0",
40+
"react-markdown": "^8.0.7",
41+
"react-router-dom": "^6.15.0",
42+
"rehype-highlight": "^6.0.0",
43+
"rehype-katex": "^6.0.3",
44+
"remark-breaks": "^3.0.2",
45+
"remark-gfm": "^3.0.1",
46+
"remark-math": "^5.1.1",
47+
"sass": "^1.59.2",
48+
"spark-md5": "^3.0.2",
49+
"use-debounce": "^9.0.4",
50+
"zustand": "^4.3.8"
51+
},
52+
"devDependencies": {
53+
"@tauri-apps/cli": "1.5.11",
54+
"@testing-library/jest-dom": "^6.4.8",
55+
"@testing-library/react": "^16.0.0",
56+
"@types/jest": "^29.5.12",
57+
"@types/lodash-es": "^4.17.12",
58+
"@types/node": "^20.11.30",
59+
"@types/react": "^18.2.70",
60+
"@types/react-dom": "^18.2.7",
61+
"@types/react-katex": "^3.0.0",
62+
"@types/spark-md5": "^3.0.4",
63+
"concurrently": "^8.2.2",
64+
"cross-env": "^7.0.3",
65+
"eslint": "^8.49.0",
66+
"eslint-config-next": "13.4.19",
67+
"eslint-config-prettier": "^8.8.0",
68+
"eslint-plugin-prettier": "^5.1.3",
69+
"husky": "^8.0.0",
70+
"jest": "^29.7.0",
71+
"jest-environment-jsdom": "^29.7.0",
72+
"lint-staged": "^13.2.2",
73+
"prettier": "^3.0.2",
74+
"ts-node": "^10.9.2",
75+
"tsx": "^4.16.0",
76+
"typescript": "5.2.2",
77+
"watch": "^1.0.2",
78+
"webpack": "^5.88.1"
79+
},
80+
"resolutions": {
81+
"lint-staged/yaml": "^2.2.2"
82+
},
83+
"packageManager": "[email protected]"
7684
}

Diff for: test/sum-module.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function sum(a: number, b: number) {
2+
return a + b;
3+
}
4+
5+
describe("sum module", () => {
6+
test("adds 1 + 2 to equal 3", () => {
7+
expect(sum(1, 2)).toBe(3);
8+
});
9+
});

0 commit comments

Comments
 (0)