Skip to content

Commit b028643

Browse files
test(vitest): update configs to reflect pkg updates
1 parent c790240 commit b028643

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

vitest.config.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
import { defineConfig, coverageConfigDefaults } from "vitest/config";
22
import GithubActionsReporter from "vitest-github-actions-reporter";
3-
import type { EmptyObject } from "type-fest";
3+
4+
const isCI = !!process.env.CI;
5+
const isGitHubActionWorkflow = !!process.env.GITHUB_ACTIONS;
46

57
export default defineConfig({
68
test: {
79
/**
810
* `restoreMocks` accomplishes the following:
9-
* - clears all spies of `spy.mock.calls` and `spy.mock.results` (same as clearMocks:true)
10-
* - removes any mocked implementations (same as mockReset:true)
11-
* - restores the original implementation so fns don't return undefined like with mockReset
11+
* - Removes any mocked implementations (same as mockReset:true).
12+
* - Restores the original implementation so fns don't return undefined like with mockReset.
13+
* - Clears mock-state for spies created "manually" via `vi.spyOn` (same as clearMocks:true).
14+
* > Mock-state is NOT cleared for spies created via *automocking* (`mockReset` does this).
15+
*
16+
* `mockReset` accomplishes the following:
17+
* - Resets mock-state (call counts, arguments, etc.) for all mocks, including automocks.
1218
*/
1319
restoreMocks: true,
20+
mockReset: true,
1421
unstubGlobals: true,
1522
globals: true,
1623
silent: true,
1724
hideSkippedTests: true,
1825
watch: false,
19-
26+
bail: isCI ? 1 : 0, // If in CI, bail on first test failure, else run all tests
2027
environment: "node",
21-
setupFiles: "./vitest.setup.ts",
22-
23-
include: ["**/?(*.){test,spec}.?(c|m)[tj]s?(x)"],
24-
28+
setupFiles: ["./vitest.setup.ts"],
2529
reporters: [
2630
"default",
2731
// GithubActionsReporter is used to format test results for GitHub Actions
28-
...(process.env.GITHUB_ACTIONS ? [new GithubActionsReporter()] : []),
32+
...(isGitHubActionWorkflow ? [new GithubActionsReporter()] : []),
2933
],
30-
3134
coverage: {
3235
include: ["src/**/*.{js,ts}"],
33-
exclude: [
34-
...coverageConfigDefaults.exclude,
35-
"**/tests/**/*",
36-
"**/__mocks__/**/*",
37-
"__mocks__/**/*",
38-
],
36+
exclude: [...coverageConfigDefaults.exclude, "**/index.ts"],
3937
reporter: [
40-
...(coverageConfigDefaults.reporter as Array<[string, EmptyObject]>),
41-
// "json-summary" is used by the vitest-coverage-report GitHub Action
42-
...(process.env.GITHUB_ACTIONS ? ["json-summary"] : []),
38+
"text", // <-- for console output (even in CI, for logging/debugging purposes)
39+
"lcov", // <-- for uploading coverage info to Codecov
40+
...(isGitHubActionWorkflow
41+
? ["json-summary"] // <-- for the vitest-coverage-report GitHub Action
42+
: []),
4343
],
4444
},
4545
},

0 commit comments

Comments
 (0)