Skip to content

Commit e17bf59

Browse files
authored
[Bug] Use silent mode during tests (unless debugging!) + test workflow optimization (pagefaultgames#4154)
* add :silent to all tests but disable it if the runner is in debug mode! * fix: use `--silent` instead of `:silent` Cause the previous was npm scrpt specific (whops) * remove env and replace with logic in each call * reduce redundancy by checking out once * move pre-test into `needs` after `checkout` * use cache approach in pre-test * add node.js install step to `setup` job * WIP: setup -> pre-test -> all other tests with using cache * use matrix approach for tests * fix matrix approach for tests * fix wrong use of env var in `run-test-template.yml` * test: out-comment `run-tests` to see whats wrong * test: see if this works * let's try using matrix again... * make `node-version` input a string * remove `node-version` input for now * test: without a matrix fornow * change usage of reuseable workflow call * fix call of matrix.project * try using working-dir * try setup for pre-tests * remove `runs-on` from run-tests * fix some identations for run-tests * add pre-test as requirement for running tests * use `1` instead of `'1'` to check `runner.debug` * add `options` input. Possible fix for debug = not silent * try again... * not as an ENV but inside * move 2nd ${{ !runner.debug && '--silent' }} check into test-template * fix printing `false` instead of empty-string on runner-debug check * try a yml array approach * test running with file include path * make `project` always `main` for now * remove all extra vitest workspaces * adopt `shards` workflow in vitest * fix workflow reference in tests.yml * add missing `$` in test-shard-template.yml` * chore: fix vitest.config.ts after merge man.. cant trust these machines * make `project` a variable. try to use inputs on job names * adjust `test-shard-template` job name
1 parent 14ace40 commit e17bf59

File tree

4 files changed

+90
-176
lines changed

4 files changed

+90
-176
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test Template
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
project:
7+
required: true
8+
type: string
9+
shard:
10+
required: true
11+
type: number
12+
totalShards:
13+
required: true
14+
type: number
15+
16+
jobs:
17+
test:
18+
name: Shard ${{ inputs.shard }} of ${{ inputs.totalShards }}
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check out Git repository
22+
uses: actions/checkout@v4
23+
- name: Set up Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
- name: Install Node.js dependencies
28+
run: npm ci
29+
- name: Run tests
30+
run: npx vitest --project ${{ inputs.project }} --shard=${{ inputs.shard }}/${{ inputs.totalShards }} ${{ !runner.debug && '--silent' || '' }}

.github/workflows/tests.yml

+20-78
Original file line numberDiff line numberDiff line change
@@ -15,91 +15,33 @@ on:
1515
types: [checks_requested]
1616

1717
jobs:
18-
run-misc-tests: # Define a job named "run-tests"
19-
name: Run misc tests # Human-readable name for the job
20-
runs-on: ubuntu-latest # Specify the latest Ubuntu runner for the job
21-
22-
steps:
23-
- name: Check out Git repository # Step to check out the repository
24-
uses: actions/checkout@v4 # Use the checkout action version 4
25-
26-
- name: Set up Node.js # Step to set up Node.js environment
27-
uses: actions/setup-node@v4 # Use the setup-node action version 4
28-
with:
29-
node-version: 20 # Specify Node.js version 20
30-
31-
- name: Install Node.js dependencies # Step to install Node.js dependencies
32-
run: npm ci # Use 'npm ci' to install dependencies
33-
34-
- name: pre-test # pre-test to check overrides
35-
run: npx vitest run --project pre
36-
- name: test misc
37-
run: npx vitest --project misc
38-
39-
run-abilities-tests:
40-
name: Run abilities tests
41-
runs-on: ubuntu-latest
42-
steps:
43-
- name: Check out Git repository
44-
uses: actions/checkout@v4
45-
- name: Set up Node.js
46-
uses: actions/setup-node@v4
47-
with:
48-
node-version: 20
49-
- name: Install Node.js dependencies
50-
run: npm ci
51-
- name: pre-test
52-
run: npx vitest run --project pre
53-
- name: test abilities
54-
run: npx vitest --project abilities
55-
56-
run-items-tests:
57-
name: Run items tests
58-
runs-on: ubuntu-latest
59-
steps:
60-
- name: Check out Git repository
61-
uses: actions/checkout@v4
62-
- name: Set up Node.js
63-
uses: actions/setup-node@v4
64-
with:
65-
node-version: 20
66-
- name: Install Node.js dependencies
67-
run: npm ci
68-
- name: pre-test
69-
run: npx vitest run --project pre
70-
- name: test items
71-
run: npx vitest --project items
72-
73-
run-moves-tests:
74-
name: Run moves tests
75-
runs-on: ubuntu-latest
18+
pre-test:
19+
name: Run Pre-test
20+
runs-on: ubuntu-latest
7621
steps:
7722
- name: Check out Git repository
7823
uses: actions/checkout@v4
79-
- name: Set up Node.js
80-
uses: actions/setup-node@v4
8124
with:
82-
node-version: 20
83-
- name: Install Node.js dependencies
84-
run: npm ci
85-
- name: pre-test
86-
run: npx vitest run --project pre
87-
- name: test moves
88-
run: npx vitest --project moves
89-
90-
run-battle-tests:
91-
name: Run battle tests
92-
runs-on: ubuntu-latest
93-
steps:
94-
- name: Check out Git repository
95-
uses: actions/checkout@v4
25+
path: tests-action
9626
- name: Set up Node.js
9727
uses: actions/setup-node@v4
9828
with:
9929
node-version: 20
10030
- name: Install Node.js dependencies
31+
working-directory: tests-action
10132
run: npm ci
102-
- name: pre-test
103-
run: npx vitest run --project pre
104-
- name: test battle
105-
run: npx vitest --project battle
33+
- name: Run Pre-test
34+
working-directory: tests-action
35+
run: npx vitest run --project pre ${{ !runner.debug && '--silent' || '' }}
36+
37+
run-tests:
38+
name: Run Tests
39+
needs: [pre-test]
40+
strategy:
41+
matrix:
42+
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
43+
uses: ./.github/workflows/test-shard-template.yml
44+
with:
45+
project: main
46+
shard: ${{ matrix.shard }}
47+
totalShards: 10

vitest.config.ts

+40-44
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
1-
import { defineProject, UserWorkspaceConfig } from 'vitest/config';
2-
import { defaultConfig } from './vite.config';
3-
4-
export const defaultProjectTestConfig: UserWorkspaceConfig["test"] = {
5-
setupFiles: ['./src/test/fontFace.setup.ts', './src/test/vitest.setup.ts'],
6-
server: {
7-
deps: {
8-
inline: ['vitest-canvas-mock'],
9-
//@ts-ignore
10-
optimizer: {
11-
web: {
12-
include: ['vitest-canvas-mock'],
13-
}
14-
}
15-
}
16-
},
17-
environment: 'jsdom' as const,
18-
environmentOptions: {
19-
jsdom: {
20-
resources: 'usable',
21-
},
22-
},
23-
threads: false,
24-
trace: true,
25-
restoreMocks: true,
26-
watch: false,
27-
coverage: {
28-
provider: 'istanbul' as const,
29-
reportsDirectory: 'coverage' as const,
30-
reporters: ['text-summary', 'html'],
31-
},
32-
}
1+
import { defineProject } from "vitest/config";
2+
import { defaultConfig } from "./vite.config";
333

344
export default defineProject(({ mode }) => ({
35-
...defaultConfig,
36-
test: {
37-
...defaultProjectTestConfig,
38-
name: "main",
39-
include: ["./src/test/**/*.{test,spec}.ts"],
40-
exclude: ["./src/test/pre.test.ts"],
41-
},
42-
esbuild: {
43-
pure: mode === 'production' ? [ 'console.log' ] : [],
44-
keepNames: true,
45-
},
46-
}))
5+
...defaultConfig,
6+
test: {
7+
setupFiles: ["./src/test/fontFace.setup.ts", "./src/test/vitest.setup.ts"],
8+
server: {
9+
deps: {
10+
inline: ["vitest-canvas-mock"],
11+
//@ts-ignore
12+
optimizer: {
13+
web: {
14+
include: ["vitest-canvas-mock"],
15+
},
16+
},
17+
},
18+
},
19+
environment: "jsdom" as const,
20+
environmentOptions: {
21+
jsdom: {
22+
resources: "usable",
23+
},
24+
},
25+
threads: false,
26+
trace: true,
27+
restoreMocks: true,
28+
watch: false,
29+
coverage: {
30+
provider: "istanbul" as const,
31+
reportsDirectory: "coverage" as const,
32+
reporters: ["text-summary", "html"],
33+
},
34+
name: "main",
35+
include: ["./src/test/**/*.{test,spec}.ts"],
36+
exclude: ["./src/test/pre.test.ts"],
37+
},
38+
esbuild: {
39+
pure: mode === "production" ? ["console.log"] : [],
40+
keepNames: true,
41+
},
42+
}));

vitest.workspace.ts

-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { defineWorkspace } from "vitest/config";
22
import { defaultConfig } from "./vite.config";
3-
import { defaultProjectTestConfig } from "./vitest.config";
43

54
export default defineWorkspace([
65
{
@@ -11,58 +10,5 @@ export default defineWorkspace([
1110
environment: "jsdom",
1211
},
1312
},
14-
{
15-
...defaultConfig,
16-
test: {
17-
...defaultProjectTestConfig,
18-
name: "misc",
19-
include: [
20-
"src/test/achievements/**/*.{test,spec}.ts",
21-
"src/test/arena/**/*.{test,spec}.ts",
22-
"src/test/battlerTags/**/*.{test,spec}.ts",
23-
"src/test/eggs/**/*.{test,spec}.ts",
24-
"src/test/field/**/*.{test,spec}.ts",
25-
"src/test/inputs/**/*.{test,spec}.ts",
26-
"src/test/localization/**/*.{test,spec}.ts",
27-
"src/test/phases/**/*.{test,spec}.ts",
28-
"src/test/settingMenu/**/*.{test,spec}.ts",
29-
"src/test/sprites/**/*.{test,spec}.ts",
30-
"src/test/ui/**/*.{test,spec}.ts",
31-
"src/test/*.{test,spec}.ts",
32-
],
33-
},
34-
},
35-
{
36-
...defaultConfig,
37-
test: {
38-
...defaultProjectTestConfig,
39-
name: "abilities",
40-
include: ["src/test/abilities/**/*.{test,spec}.ts"],
41-
},
42-
},
43-
{
44-
...defaultConfig,
45-
test: {
46-
...defaultProjectTestConfig,
47-
name: "battle",
48-
include: ["src/test/battle/**/*.{test,spec}.ts"],
49-
},
50-
},
51-
{
52-
...defaultConfig,
53-
test: {
54-
...defaultProjectTestConfig,
55-
name: "items",
56-
include: ["src/test/items/**/*.{test,spec}.ts"],
57-
},
58-
},
59-
{
60-
...defaultConfig,
61-
test: {
62-
...defaultProjectTestConfig,
63-
name: "moves",
64-
include: ["src/test/moves/**/*.{test,spec}.ts"],
65-
},
66-
},
6713
"./vitest.config.ts",
6814
]);

0 commit comments

Comments
 (0)