Skip to content

Commit 03bb306

Browse files
committed
Drop support for karma and assume all projects will use vitest for tests
1 parent 76aa443 commit 03bb306

File tree

4 files changed

+35
-843
lines changed

4 files changed

+35
-843
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This project assumes our standard tech stack for frontend projects:
1313
- [Gulp](https://gulpjs.com) for running tasks [1]
1414
- [Rollup](https://rollupjs.org/guide/en/) for building JavaScript bundles
1515
- [Sass](https://sass-lang.com) for authoring styles
16-
- [Karma](https://karma-runner.github.io/latest/index.html) for running tests
16+
- [Vitest](https://vitest.dev/) for running tests
1717

1818
[1] Gulp is not required as the task runner, but is how most of our projects
1919
are currently set up.
@@ -24,9 +24,9 @@ The typical structure of a Hypothesis frontend project looks like:
2424

2525
```sh
2626
gulpfile.mjs # Gulp tasks
27+
vitest.config.js # Vitest config file
2728

2829
src/ # Source files ("$PROJECT_NAME/static/scripts" in Python projects)
29-
karma.config.js # Karma config file
3030
tests/
3131
bootstrap.js # JS module that configures test environment
3232

@@ -67,7 +67,7 @@ gulp.task('watch-css', () => gulp.watch('src/**/*.scss', 'build-css'));
6767
gulp.task('watch', gulp.parallel('watch-js', 'watch-css'));
6868
gulp.task('test', () => runTests({
6969
bootstrapFile: 'src/tests/bootstrap.js',
70-
karmaConfig: 'src/karma.config.js',
70+
vitestConfig: 'vitest.config.js',
7171
rollupConfig: 'rollup-tests.config.mjs',
7272
testsPattern: '**/*-test.js',
7373
});
@@ -100,14 +100,14 @@ apps to serve static assets.
100100
### Running tests
101101
102102
`runTests(config)` - Build a JavaScript bundle of tests from a set of input files
103-
and run them in Karma.
103+
and run them in Vitest.
104104
105105
The test bundle is created by first finding all test files that match the
106106
`testsPattern` argument and generating an entry point,
107107
`build/scripts/test-inputs.js`, which imports all of the test files. The
108108
bundle is then built by passing the config specified by `rollupConfig` to
109-
Rollup. Once the bundle has been generated, Karma is started using the config
110-
file specified by `karmaConfig`, which should load the test bundle.
109+
Rollup. Once the bundle has been generated, Vitest is started using the config
110+
file specified by `vitestConfig`, which should load the test bundle.
111111
112112
This command supports filtering which tests are run
113113
by using the `--grep <file pattern>` CLI argument. If the `--live` CLI flag is

lib/tests.js

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import log from 'fancy-log';
88
import { buildJS, watchJS } from './rollup.js';
99

1010
/**
11-
* Build a bundle of tests and run them using Karma.
11+
* Build a bundle of tests and run them using Vitest.
1212
*
1313
* @param {object} options
1414
* @param {string} options.bootstrapFile - Entry point for the test bundle that initializes the environment
1515
* @param {string} options.rollupConfig - Rollup config that generates the test bundle using
1616
* `${outputDir}/test-inputs.js` as an entry point
17-
* @param {string} [options.karmaConfig] - Karma config file. Will use karma to run tests
18-
* @param {string} [options.vitestConfig] - Vitest config file. Will use vitest to run tests
17+
* @param {string} options.vitestConfig - Vitest config file.
1918
* @param {string} options.outputDir - Directory in which to generate test bundle. Defaults to
2019
* `build/scripts`
2120
* @param {string} options.testsPattern - Minimatch pattern that specifies which test files to
@@ -26,7 +25,6 @@ export async function runTests({
2625
bootstrapFile,
2726
rollupConfig,
2827
outputDir = 'build/scripts',
29-
karmaConfig,
3028
vitestConfig,
3129
testsPattern,
3230
}) {
@@ -67,43 +65,14 @@ export async function runTests({
6765
await watchJS(rollupConfig);
6866
}
6967

70-
if (karmaConfig) {
71-
// Run the tests with karma.
72-
log('Starting Karma...');
73-
const { default: karma } = await import('karma');
74-
const parsedConfig = await karma.config.parseConfig(
75-
path.resolve(karmaConfig),
76-
{ singleRun },
77-
);
78-
79-
return new Promise((resolve, reject) => {
80-
new karma.Server(parsedConfig, exitCode => {
81-
if (exitCode === 0) {
82-
resolve();
83-
} else {
84-
reject(new Error(`Karma run failed with status ${exitCode}`));
85-
}
86-
}).start();
87-
88-
process.on('SIGINT', () => {
89-
// Give Karma a chance to handle SIGINT and cleanup, but forcibly
90-
// exit if it takes too long.
91-
setTimeout(() => {
92-
resolve();
93-
process.exit(1);
94-
}, 5000);
95-
});
96-
});
97-
} else if (vitestConfig) {
98-
// Run the tests with vitest. Karma takes precedence if both are defined
99-
log('Starting vitest...');
100-
const [{ startVitest }, vitestOptions] = await Promise.all([
101-
import('vitest/node'),
102-
import(path.resolve(vitestConfig)),
103-
]);
104-
await startVitest('test', [], {
105-
watch: live,
106-
...vitestOptions,
107-
});
108-
}
68+
// Run the tests with vitest
69+
log('Starting vitest...');
70+
const [{ startVitest }, vitestOptions] = await Promise.all([
71+
import('vitest/node'),
72+
import(path.resolve(vitestConfig)),
73+
]);
74+
await startVitest('test', [], {
75+
watch: live,
76+
...vitestOptions,
77+
});
10978
}

package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
"devDependencies": {
1515
"@types/fancy-log": "^2.0.0",
1616
"@types/glob": "^8.0.0",
17-
"@types/karma": "^6.3.1",
1817
"@types/node": "^22.0.0",
1918
"@types/sass": "^1.16.1",
2019
"@types/tailwindcss": "^3.0.2",
2120
"autoprefixer": "^10.3.7",
2221
"eslint": "^9.23.0",
23-
"karma": "^6.3.4",
2422
"postcss": "^8.3.9",
2523
"prettier": "^3.0.0",
2624
"rollup": "^4.0.2",
@@ -36,7 +34,6 @@
3634
},
3735
"peerDependencies": {
3836
"autoprefixer": "^10.3.7",
39-
"karma": "^6.3.4",
4037
"postcss": "^8.3.9",
4138
"rollup": "^4.0.2",
4239
"sass": "^1.43.2",
@@ -47,9 +44,6 @@
4744
"autoprefixer": {
4845
"optional": true
4946
},
50-
"karma": {
51-
"optional": true
52-
},
5347
"postcss": {
5448
"optional": true
5549
},
@@ -58,9 +52,6 @@
5852
},
5953
"tailwindcss": {
6054
"optional": true
61-
},
62-
"vitest": {
63-
"optional": true
6455
}
6556
},
6657
"prettier": {

0 commit comments

Comments
 (0)