Skip to content

Commit 0a9ee46

Browse files
committed
[vitest] Fully replace jest
1 parent b8aa5d7 commit 0a9ee46

File tree

158 files changed

+13938
-94859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+13938
-94859
lines changed

coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tests":7143,"assertions":32970,"lines":{"total":2326,"covered":2326,"skipped":0,"pct":100},"statements":{"total":2515,"covered":2515,"skipped":0,"pct":100},"functions":{"total":1005,"covered":1005,"skipped":0,"pct":100},"branches":{"total":876,"covered":876,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
1+
{"tests":7143,"assertions":32130,"lines":{"total":2326,"covered":2326,"skipped":0,"pct":100},"statements":{"total":2515,"covered":2515,"skipped":0,"pct":100},"functions":{"total":1005,"covered":1005,"skipped":0,"pct":100},"branches":{"total":876,"covered":876,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}

eslint.config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import jsLint from '@eslint/js';
22
import importLint from 'eslint-plugin-import';
3-
import jestLint from 'eslint-plugin-jest';
43
import jsdocLint from 'eslint-plugin-jsdoc';
54
import reactLint from 'eslint-plugin-react';
65
import hooksLint from 'eslint-plugin-react-hooks';
@@ -20,7 +19,6 @@ export default tsLint.config(
2019

2120
jsLint.configs.recommended,
2221
importLint.flatConfigs.recommended,
23-
jestLint.configs['flat/recommended'],
2422
jsdocLint.configs['flat/recommended'],
2523
reactLint.configs.flat.recommended,
2624
reactLint.configs.flat['jsx-runtime'],
@@ -142,11 +140,6 @@ export default tsLint.config(
142140

143141
'react-hooks/exhaustive-deps': 2,
144142
'react-hooks/rules-of-hooks': 2,
145-
146-
// --
147-
148-
'jest/expect-expect': [2, {assertFunctionNames: ['expect*']}],
149-
'jest/no-conditional-expect': 2,
150143
},
151144
},
152145

gulpfile.mjs

Lines changed: 25 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ const tsCheck = async (dir) => {
454454
analyzeTsConfig(`${path.resolve(dir)}/tsconfig.json`, [
455455
'--excludeDeclarationFiles',
456456
'--excludePathsFromReport=' +
457-
'jest/reporter.js;jest/environment.js;build.ts;ui-react/common.ts;' +
457+
'build.ts;ui-react/common.ts;' +
458458
ALL_MODULES.map((module) => `${module}.ts`).join(';'),
459459
]).unusedExports,
460460
)
@@ -563,73 +563,34 @@ const compileModule = async (module, dir = DIST_DIR, min = false) => {
563563
}
564564
};
565565

566-
// coverageMode = 0: none; 1: screen; 2: json; 3: html
567-
const test = async (
568-
dirs,
569-
{coverageMode, countAsserts, puppeteer, serialTests} = {},
570-
) => {
571-
const {default: jest} = await import('jest');
572-
await makeDir(TMP_DIR);
573-
const {
574-
results: {success},
575-
} = await jest.runCLI(
576-
{
577-
roots: dirs,
578-
setupFilesAfterEnv: ['./test/jest/setup'],
579-
...(puppeteer
580-
? {
581-
setupFilesAfterEnv: ['expect-puppeteer'],
582-
preset: 'jest-puppeteer',
583-
detectOpenHandles: true,
584-
maxWorkers: 2,
585-
}
586-
: {testEnvironment: './test/jest/environment'}),
587-
...(coverageMode > 0
588-
? {
589-
collectCoverage: true,
590-
coverageProvider: 'babel',
591-
collectCoverageFrom: [
592-
`${DIST_DIR}/index.js`,
593-
`${DIST_DIR}/ui-react/index.js`,
594-
// Other modules cannot be fully exercised in isolation.
595-
],
596-
coverageReporters: ['text-summary']
597-
.concat(coverageMode > 1 ? ['json-summary'] : [])
598-
.concat(coverageMode > 2 ? ['lcov'] : []),
599-
coverageDirectory: 'tmp',
600-
}
601-
: {}),
602-
...(countAsserts
603-
? {
604-
testEnvironment: './test/jest/environment',
605-
reporters: ['default', './test/jest/reporter'],
606-
runInBand: true,
607-
}
608-
: {}),
609-
...(serialTests ? {runInBand: true} : {}),
610-
},
611-
[''],
612-
);
613-
if (!success) {
566+
const test = async (dirs, coverage) => {
567+
await clearDir(TMP_DIR);
568+
569+
const {startVitest} = await import('vitest/node');
570+
const vitest = await startVitest('test', [...dirs], {
571+
watch: false,
572+
retry: 3,
573+
coverage: {enabled: coverage},
574+
});
575+
await vitest.close();
576+
577+
if (vitest.state.getCountOfFailedTests() > 0) {
614578
await removeDir(TMP_DIR);
615579
throw 'Test failed';
616580
}
617-
if (coverageMode == 2) {
581+
582+
if (coverage) {
618583
await promises.writeFile(
619584
'coverage.json',
620585
JSON.stringify({
621-
...(countAsserts
622-
? JSON.parse(await promises.readFile('./tmp/counts.json'))
623-
: {}),
624-
...JSON.parse(await promises.readFile('./tmp/coverage-summary.json'))
625-
.total,
586+
...JSON.parse(await promises.readFile('./tmp/counts.json')),
587+
...JSON.parse(
588+
await promises.readFile('./tmp/coverage/coverage-summary.json'),
589+
).total,
626590
}),
627591
UTF8,
628592
);
629593
}
630-
if (coverageMode < 3) {
631-
await removeDir(TMP_DIR);
632-
}
633594
};
634595

635596
const compileModulesForProd = async () => {
@@ -710,7 +671,7 @@ export const ts = async () => {
710671
export const compileForProd = () => compileModulesForProd();
711672

712673
export const testUnit = async () => {
713-
await test(['test/unit'], {coverageMode: 1, serialTests: true});
674+
await test(['test/unit'], true);
714675
};
715676

716677
export const testBun = () =>
@@ -721,23 +682,14 @@ export const testBun = () =>
721682
);
722683

723684
export const testUnitFast = async () => {
724-
await test(['test/unit/core'], {coverageMode: 1});
725-
};
726-
export const testUnitCountAsserts = async () => {
727-
await test(['test/unit'], {coverageMode: 2, countAsserts: true});
728-
};
729-
export const testUnitSaveCoverage = async () => {
730-
await test(['test/unit/core'], {coverageMode: 3});
685+
await test(['test/unit/core']);
731686
};
687+
732688
export const compileAndTestUnit = series(compileForTest, testUnit);
733689
export const compileAndTestUnitFast = series(compileForTest, testUnitFast);
734-
export const compileAndTestUnitSaveCoverage = series(
735-
compileForTest,
736-
testUnitSaveCoverage,
737-
);
738690

739691
export const testPerf = async () => {
740-
await test(['test/perf'], {serialTests: true});
692+
await test(['test/perf']);
741693
};
742694
export const compileAndTestPerf = series(compileForTest, testPerf);
743695

@@ -749,7 +701,7 @@ export const compileDocs = () => compileDocsAndAssets();
749701

750702
export const compileForProdAndDocs = series(compileForProd, compileDocs);
751703

752-
export const testE2e = () => test(['test/e2e'], {puppeteer: true});
704+
export const testE2e = () => test(['test/e2e']);
753705

754706
export const compileAndTestE2e = series(compileForProdAndDocs, testE2e);
755707

@@ -777,7 +729,7 @@ export const prePublishPackage = series(
777729
compileForTest,
778730
parallel(lint, spell, ts),
779731
testBun,
780-
testUnitCountAsserts,
732+
testUnit,
781733
testPerf,
782734
compileForProd,
783735
testProd,

jest-puppeteer.config.cjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

jest.config.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)