@@ -14,7 +14,8 @@ import { buildJS, watchJS } from './rollup.js';
14
14
* @param {string } options.bootstrapFile - Entry point for the test bundle that initializes the environment
15
15
* @param {string } options.rollupConfig - Rollup config that generates the test bundle using
16
16
* `${outputDir}/test-inputs.js` as an entry point
17
- * @param {string } options.karmaConfig - Karma config file
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
18
19
* @param {string } options.outputDir - Directory in which to generate test bundle. Defaults to
19
20
* `build/scripts`
20
21
* @param {string } options.testsPattern - Minimatch pattern that specifies which test files to
@@ -26,6 +27,7 @@ export async function runTests({
26
27
rollupConfig,
27
28
outputDir = 'build/scripts' ,
28
29
karmaConfig,
30
+ vitestConfig,
29
31
testsPattern,
30
32
} ) {
31
33
// Parse command-line options for test execution.
@@ -64,30 +66,45 @@ export async function runTests({
64
66
await watchJS ( rollupConfig ) ;
65
67
}
66
68
67
- // Run the tests.
68
- log ( 'Starting Karma...' ) ;
69
- const { default : karma } = await import ( 'karma' ) ;
70
- const parsedConfig = await karma . config . parseConfig (
71
- path . resolve ( karmaConfig ) ,
72
- { singleRun } ,
73
- ) ;
69
+ // Run the tests with vitest. Karma takes precedence if both are defined
70
+ if ( vitestConfig && ! karmaConfig ) {
71
+ log ( 'Starting vitest...' ) ;
72
+ const [ { startVitest } , vitestOptions ] = await Promise . all ( [
73
+ import ( 'vitest/node' ) ,
74
+ import ( path . resolve ( vitestConfig ) ) ,
75
+ ] ) ;
76
+ await startVitest ( 'test' , [ ] , {
77
+ watch : live ,
78
+ ...vitestOptions ,
79
+ } ) ;
80
+ }
74
81
75
- return new Promise ( ( resolve , reject ) => {
76
- new karma . Server ( parsedConfig , exitCode => {
77
- if ( exitCode === 0 ) {
78
- resolve ( ) ;
79
- } else {
80
- reject ( new Error ( `Karma run failed with status ${ exitCode } ` ) ) ;
81
- }
82
- } ) . start ( ) ;
82
+ // Run the tests with karma.
83
+ if ( karmaConfig ) {
84
+ log ( 'Starting Karma...' ) ;
85
+ const { default : karma } = await import ( 'karma' ) ;
86
+ const parsedConfig = await karma . config . parseConfig (
87
+ path . resolve ( karmaConfig ) ,
88
+ { singleRun } ,
89
+ ) ;
83
90
84
- process . on ( 'SIGINT' , ( ) => {
85
- // Give Karma a chance to handle SIGINT and cleanup, but forcibly
86
- // exit if it takes too long.
87
- setTimeout ( ( ) => {
88
- resolve ( ) ;
89
- process . exit ( 1 ) ;
90
- } , 5000 ) ;
91
+ return new Promise ( ( resolve , reject ) => {
92
+ new karma . Server ( parsedConfig , exitCode => {
93
+ if ( exitCode === 0 ) {
94
+ resolve ( ) ;
95
+ } else {
96
+ reject ( new Error ( `Karma run failed with status ${ exitCode } ` ) ) ;
97
+ }
98
+ } ) . start ( ) ;
99
+
100
+ process . on ( 'SIGINT' , ( ) => {
101
+ // Give Karma a chance to handle SIGINT and cleanup, but forcibly
102
+ // exit if it takes too long.
103
+ setTimeout ( ( ) => {
104
+ resolve ( ) ;
105
+ process . exit ( 1 ) ;
106
+ } , 5000 ) ;
107
+ } ) ;
91
108
} ) ;
92
- } ) ;
109
+ }
93
110
}
0 commit comments