@@ -479,26 +479,10 @@ function buildProjectWorkerOptions(
479479 }
480480
481481 // The following nodejs compat flags enable features required for Vitest to work properly
482- ensureFlag (
483- runnerWorker . compatibilityFlags ,
484- "enable_nodejs_tty_module" ,
485- "disable_nodejs_tty_module"
486- ) ;
487- ensureFlag (
488- runnerWorker . compatibilityFlags ,
489- "enable_nodejs_fs_module" ,
490- "disable_nodejs_fs_module"
491- ) ;
492- ensureFlag (
493- runnerWorker . compatibilityFlags ,
494- "enable_nodejs_http_modules" ,
495- "disable_nodejs_http_modules"
496- ) ;
497- ensureFlag (
498- runnerWorker . compatibilityFlags ,
499- "enable_nodejs_perf_hooks_module" ,
500- "disable_nodejs_perf_hooks_module"
501- ) ;
482+ ensureFeature ( runnerWorker . compatibilityFlags , "nodejs_tty_module" ) ;
483+ ensureFeature ( runnerWorker . compatibilityFlags , "nodejs_fs_module" ) ;
484+ ensureFeature ( runnerWorker . compatibilityFlags , "nodejs_http_modules" ) ;
485+ ensureFeature ( runnerWorker . compatibilityFlags , "nodejs_perf_hooks_module" ) ;
502486
503487 // Make sure we define an unsafe eval binding and enable the fallback service
504488 runnerWorker . unsafeEvalBinding = "__VITEST_POOL_WORKERS_UNSAFE_EVAL" ;
@@ -1265,22 +1249,23 @@ export default function (ctx: Vitest): ProcessPool {
12651249}
12661250
12671251/**
1268- * Ensures that the specified compatibility feature is set correctly.
1269- * @param flags The list of current flags.
1270- * @param enableFlag The flag that enables the feature.
1271- * @param disableFlag The flag that disables the feature.
1252+ * Ensures that the specified compatibility feature is enabled for Vitest to work.
1253+ * @param compatibilityFlags The list of current compatibility flags.
1254+ * @param feature The name of the feature to enable.
12721255 */
1273- function ensureFlag ( flags : string [ ] , enableFlag : string , disableFlag : string ) {
1274- if ( ! flags . includes ( enableFlag ) ) {
1256+ function ensureFeature ( compatibilityFlags : string [ ] , feature : string ) {
1257+ const flagToEnable = `enable_${ feature } ` ;
1258+ const flagToDisable = `disable_${ feature } ` ;
1259+ if ( ! compatibilityFlags . includes ( flagToEnable ) ) {
12751260 log . debug (
1276- `Adding \`${ enableFlag } \` compatibility flag during tests as this feature is needed to support the Vitest runner.`
1261+ `Adding \`${ flagToEnable } \` compatibility flag during tests as this feature is needed to support the Vitest runner.`
12771262 ) ;
1278- flags . push ( enableFlag ) ;
1263+ compatibilityFlags . push ( flagToEnable ) ;
12791264 }
1280- if ( flags . includes ( disableFlag ) ) {
1265+ if ( compatibilityFlags . includes ( flagToDisable ) ) {
12811266 log . info (
1282- `Removing \`${ disableFlag } \` compatibility flag during tests as that feature is needed to support the Vitest runner.`
1267+ `Removing \`${ flagToDisable } \` compatibility flag during tests as that feature is needed to support the Vitest runner.`
12831268 ) ;
1284- flags . splice ( flags . indexOf ( disableFlag ) , 1 ) ;
1269+ compatibilityFlags . splice ( compatibilityFlags . indexOf ( flagToDisable ) , 1 ) ;
12851270 }
12861271}
0 commit comments