-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvitest.config.js
More file actions
109 lines (103 loc) · 3.57 KB
/
Copy pathvitest.config.js
File metadata and controls
109 lines (103 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @import {TestProjectConfiguration} from 'vitest/config'
*/
import { vitestPlugin as mockApiPlugin } from '@clevercloud/doublure/vitest';
import { playwright } from '@vitest/browser-playwright';
import { defaultExclude, defineConfig } from 'vitest/config';
import { e2eProxyPlugin } from './test/setup/e2e-proxy.browser.js';
/**
* The same `*.spec.js` files run in both Node and the browser. `*.node.spec.js` and
* `*.browser.spec.js` are escape hatches to restrict a spec to a single environment.
*/
const excludeForNode = [...defaultExclude, '**/*.browser.spec.js'];
const excludeForBrowser = [...defaultExclude, '**/*.node.spec.js'];
/**
* Local-only escape hatch (can be set via mise) to run a single environment, e.g. from the WebStorm
* gutter where Vitest runs every matching project with no `--project` flag — logging the e2e
* users in once per environment. Unset => all projects, so CI and the `npm run test:*` scripts
* (which pass explicit `--project` flags) are unaffected.
*
* @type {'browser' | 'node' | undefined}
*/
const TEST_RUNTIME = /** @type {'browser' | 'node' | undefined} */ (process.env.TEST_RUNTIME);
if (TEST_RUNTIME != null && TEST_RUNTIME !== 'node' && TEST_RUNTIME !== 'browser') {
throw new Error(`Invalid env TEST_RUNTIME="${TEST_RUNTIME}": expected "node" or "browser" (or unset to run both).`);
}
/** @type {TestProjectConfiguration[]} */
const allProjects = [
// ---------- UNIT ----------
{
test: {
name: 'node-unit',
environment: 'node',
globals: true,
setupFiles: ['./test/setup/vite-matchers.js'],
include: ['test/unit/**/*.spec.js'],
exclude: excludeForNode,
// The browser-unit mock server / node mock servers are shared per run
fileParallelism: false,
maxConcurrency: 1,
},
},
{
plugins: [mockApiPlugin()],
test: {
name: 'browser-unit',
globals: true,
setupFiles: ['./test/setup/vite-matchers.js'],
include: ['test/unit/**/*.spec.js'],
exclude: excludeForBrowser,
fileParallelism: false,
maxConcurrency: 1,
browser: { enabled: true, provider: playwright(), headless: true, instances: [{ browser: 'chromium' }] },
},
},
// ---------- E2E ----------
{
test: {
name: 'node-e2e',
environment: 'node',
globals: true,
setupFiles: ['./test/setup/vite-matchers.js', './test/setup/hydrate-users.node.js'],
globalSetup: ['./test/setup/global-setup.node.js'],
include: ['test/e2e/**/*.spec.js'],
exclude: excludeForNode,
testTimeout: 30000,
hookTimeout: 30000,
fileParallelism: false,
maxConcurrency: 1,
},
},
{
plugins: [e2eProxyPlugin()],
test: {
name: 'browser-e2e',
globals: true,
setupFiles: ['./test/setup/vite-matchers.js'],
include: ['test/e2e/**/*.spec.js'],
exclude: excludeForBrowser,
testTimeout: 30000,
hookTimeout: 30000,
fileParallelism: false,
maxConcurrency: 1,
browser: { enabled: true, provider: playwright(), headless: true, instances: [{ browser: 'chromium' }] },
},
},
];
// When `TEST_RUNTIME` is set, keep only that runtime's projects (names start with the runtime,
// e.g. `node-e2e` / `browser-unit`). Unset => all projects.
const projects =
TEST_RUNTIME == null
? allProjects
: allProjects.filter(
(project) =>
typeof project === 'object' &&
'test' in project &&
typeof project.test?.name === 'string' &&
project.test.name.startsWith(`${TEST_RUNTIME}-`),
);
export default defineConfig({
test: {
projects,
},
});