Skip to content

Commit 76e7ab3

Browse files
committed
setup test
1 parent c1291c9 commit 76e7ab3

File tree

8 files changed

+925
-18
lines changed

8 files changed

+925
-18
lines changed

.github/workflows/ci-typescript.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: ci-typescript
33
on:
44
push:
55
branches:
6-
- development
6+
- develop
77
pull_request:
88

99
jobs:
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
node-version-file: ".node-version"
2929
cache: "pnpm"
30-
cache-dependency-path: ./app/frontier/pnpm-lock.yaml
30+
cache-dependency-path: ./pnpm-lock.yaml
3131

3232
- name: Install dependencies
3333
run: pnpm install
@@ -37,3 +37,6 @@ jobs:
3737

3838
- name: lint
3939
run: pnpm run lint
40+
41+
- name: test
42+
run: pnpm run test

apps/user/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "next start",
9+
"test": "vitest --run",
910
"typecheck": "tsc --noEmit",
1011
"preinstall": "npx only-allow pnpm"
1112
},
@@ -21,6 +22,7 @@
2122
"@types/react-dom": "catalog:",
2223
"babel-plugin-react-compiler": "catalog:",
2324
"tailwindcss": "catalog:",
24-
"typescript": "catalog:"
25+
"typescript": "catalog:",
26+
"vitest": "catalog:"
2527
}
2628
}

apps/user/src/example.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// vitest のサンプルコード。
2+
// サンプルコードがないと vitest がエラーになるため用意している。
3+
//
4+
// TODO: 実際のテストコードができれば、このファイルは不要なので削除する。
5+
6+
function sum(a: number, b: number) {
7+
return a + b;
8+
}
9+
10+
test("adds 1 + 2 to equal 3", () => {
11+
expect(sum(1, 2)).toBe(3);
12+
});

apps/user/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
],
2121
"paths": {
2222
"@/*": ["./src/*"]
23-
}
23+
},
24+
"types": ["vitest/globals"]
2425
},
2526
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", ".next/dev/types/**/*.ts", "**/*.mts"],
2627
"exclude": ["node_modules"]

apps/user/vitest.config.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import path from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { defineConfig } from "vitest/config";
4+
5+
const dirname = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
6+
7+
export default defineConfig({
8+
test: {
9+
projects: [
10+
{
11+
test: {
12+
name: "unit",
13+
environment: "node",
14+
globals: true,
15+
include: ["src/**/*.test.ts"],
16+
},
17+
resolve: {
18+
alias: {
19+
"@": path.resolve(dirname, "./src"),
20+
},
21+
},
22+
},
23+
],
24+
},
25+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint:fix": "biome check --fix",
1212
"typecheck": "run-p typecheck:*",
1313
"typecheck:user": "pnpm user typecheck",
14-
"test": "echo \"Error: no test specified\" && exit 1",
14+
"test": "run-s test:*",
15+
"test:user": "pnpm user test",
1516
"preinstall": "npx only-allow pnpm"
1617
},
1718
"keywords": [],

0 commit comments

Comments
 (0)