-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.js
More file actions
77 lines (74 loc) · 3.94 KB
/
Copy pathvitest.config.js
File metadata and controls
77 lines (74 loc) · 3.94 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
import { defineConfig } from 'vitest/config';
import {
UNDERPOST_TESTING,
coverageIncludeFactory,
coverageReportKey,
coverageThresholdFactory,
testFootprintFactory,
testProjectsFactory,
vitestProjectSelector,
} from './src/server/build/testing.js';
import { loadProductContexts } from './src/server/build/catalog.js';
const allureResultsDirectory = process.env[UNDERPOST_TESTING.allureResultsEnvKey];
const batchReport = process.env[UNDERPOST_TESTING.batchReportEnvKey];
const batchResults = process.env[UNDERPOST_TESTING.batchResultsEnvKey];
const footprint = testFootprintFactory(process.env[UNDERPOST_TESTING.footprintEnvKey]);
const coverageThreshold = coverageThresholdFactory(process.env);
const productContexts = await loadProductContexts();
const coverageInclude = coverageIncludeFactory(process.argv, productContexts);
const coverageReportDirectory = coverageReportKey(vitestProjectSelector(process.argv));
// Spread into every tier: a Vitest project inherits nothing from the root
// `test` block, and only `coverage` and `reporters` are read from it.
const projectDefaults = {
// Mocha's `describe`/`it` and the hooks stay global, so the suites read the
// same either side of the migration and carry no runner import.
globals: true,
environment: 'node',
// A tier is only meaningful if its failures are attributable to it, and a
// suite that reads `dd.routes` or binds a fixed port cannot share a worker
// with another doing the same.
fileParallelism: false,
...(allureResultsDirectory ? { setupFiles: ['allure-vitest/setup'] } : {}),
};
export default defineConfig({
test: {
...footprint.vitest,
reporters: [
'default',
...(allureResultsDirectory ? [['allure-vitest/reporter', { resultsDir: allureResultsDirectory }]] : []),
// A batch of `node bin test`: the runner merges every blob of the run at the end.
...(batchReport ? [['blob', { outputFile: batchReport }]] : []),
// The failure report of the runner reads these results.
...(batchResults ? [['json', { outputFile: batchResults }]] : []),
],
coverage: {
provider: 'v8',
reportsDirectory: UNDERPOST_TESTING.coverageDirectory,
// `lcovonly` is what Coveralls ingests, `json` is what a merged multi-job
// report is assembled from, `text` is what a local run reads, and `html` is
// what a deploy publishes — under the selection's own directory, so the
// report a deploy declares is the run it names and never the last run made.
reporter: ['text', 'lcovonly', 'json', ['html', { subdir: coverageReportDirectory }]],
// The directory holds one report per selection, so a run must not empty it; the
// runner (`src/cli/test.js`) clears its own selection's report before it starts.
clean: false,
// Written even when the run fails: the coverage workflows upload the report
// from a job the threshold step is meant to fail, and without it the badge
// freezes at the last passing build instead of moving with the tree.
reportOnFailure: true,
// The tiers in the selection decide what is measured, so a partial run
// reports the slice it drives and the whole run reports the whole of it —
// rather than every module the CLI barrel drags into a worker on import.
include: coverageInclude,
// Only the suites themselves: an `include` whitelist already keeps
// dependencies, bundles and generated assets out, and a directory pattern
// here is not anchored to the root — `test/**` also excluded the API
// surfaces named `test`, so the tier covering them reported nothing.
exclude: ['**/*.{test,spec}.js'],
// Absent unless the run opted in, so a single-tier run reports its slice
// instead of failing against a number it never measured.
...(coverageThreshold === null ? {} : { thresholds: { lines: coverageThreshold } }),
},
projects: testProjectsFactory(projectDefaults, productContexts, footprint),
},
});