forked from rocicorp/mono
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.config.ts
More file actions
81 lines (76 loc) · 2.48 KB
/
vitest.config.ts
File metadata and controls
81 lines (76 loc) · 2.48 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
import {defineConfig, mergeConfig} from 'vitest/config';
import config, {CI} from '../shared/src/tool/vitest-config.ts';
function nameFromURL(url: string) {
// importer looks like file://....../packages/NAME/... and we want the NAME
return url.match(/\/packages\/([^/]+)/)?.[1] ?? 'unknown';
}
export function configForVersion(version: number, url: string) {
const name = nameFromURL(url);
const merged = mergeConfig(config, {
test: {
name: `${name}/pg-${version}`,
browser: {enabled: false},
silent: 'passed-only',
globalSetup: [`../zero-cache/test/pg-${version}.ts`],
coverage: {
enabled: !CI, // Don't run coverage in continuous integration.
reporter: [['html'], ['clover', {file: 'coverage.xml'}]],
include: ['src/**'],
},
testTimeout: 20000,
hookTimeout: 20000,
},
});
// Override include to only pg tests (mergeConfig merges arrays, we want to replace)
merged.test.include = ['src/**/*.pg.test.?(c|m)[jt]s?(x)'];
merged.test.exclude = [];
return merged;
}
export function configForNoPg(url: string) {
const name = nameFromURL(url);
return mergeConfig(config, {
test: {
name: `${name}/no-pg`,
include: ['src/**/*.test.?(c|m)[jt]s?(x)'],
exclude: ['src/**/*.pg.test.?(c|m)[jt]s?(x)'],
browser: {enabled: false},
silent: 'passed-only',
coverage: {
enabled: !CI, // Don't run coverage in continuous integration.
reporter: [['html'], ['clover', {file: 'coverage.xml'}]],
include: ['src/**'],
},
},
});
}
// To run tests against a custom Postgres instance (e.g. Aurora), specify
// the connection string in the CUSTOM_PG environment variable, and optionally
// limit the test runner to the "custom-pg" project:
//
// CUSTOM_PG=postgresql://... npm run test -- --project custom-pg
export function configForCustomPg(url: string) {
if (process.env['CUSTOM_PG']) {
const name = nameFromURL(url);
return [
mergeConfig(config, {
test: {
name: `${name}/custom-pg`,
browser: {enabled: false},
silent: 'passed-only',
include: ['src/**/*.pg.test.?(c|m)[jt]s?(x)'],
exclude: [],
provide: {
// Referenced by ./src/test/db.ts
pgConnectionString: process.env['CUSTOM_PG'],
},
},
}),
];
}
return [];
}
export default defineConfig({
test: {
projects: ['vitest.config.*.ts', ...configForCustomPg(import.meta.url)],
},
});