Skip to content

Commit 6268a18

Browse files
committed
refactor: dedupe options.engine warnings strings
1 parent 9b11d95 commit 6268a18

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

bin/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ const setEnv = (name, value) => {
205205
process.env[name] = value === undefined ? '' : value
206206
}
207207

208+
const engineName = `${options.engine} engine` // used for warnings to user
208209
const engineOptions = ENGINES.get(options.engine)
209210
assert(engineOptions, `Unknown engine: ${options.engine}`)
210211
Object.assign(options, engineOptions)
@@ -225,15 +226,15 @@ if (haveModuleMocks && engineOptions.haveIsOk) {
225226

226227
if (options.pure) {
227228
if (options.bundle) {
228-
assert(!options.coverage, `Can not use --coverage with ${options.engine} engine`)
229-
assert(!options.babel, `Can not use --babel with ${options.engine} engine`) // TODO?
229+
assert(!options.coverage, `Can not use --coverage with ${engineName}`)
230+
assert(!options.babel, `Can not use --babel with ${engineName}`) // TODO?
230231
}
231232

232233
const requiresNodeCoverage = options.coverage && options.coverageEngine === 'node'
233234
assert(!requiresNodeCoverage, '"--coverage-engine node" requires "--engine node:test" (default)')
234-
assert(!options.writeSnapshots, `Can not use write snapshots with ${options.engine} engine`)
235-
assert(!options.forceExit, `Can not use --force-exit with ${options.engine} engine yet`) // TODO
236-
assert(!options.watch, `Can not use --watch with with ${options.engine} engine`)
235+
assert(!options.writeSnapshots, `Can not use write snapshots with ${engineName}`)
236+
assert(!options.forceExit, `Can not use --force-exit with ${engineName} yet`) // TODO
237+
assert(!options.watch, `Can not use --watch with with ${engineName}`)
237238
assert(options.testNamePattern.length === 0, '--test-name-pattern requires node:test engine now')
238239
} else if (options.engine === 'node:test') {
239240
const reporter = resolveRequire('./reporter.js')
@@ -317,9 +318,9 @@ if (options.esbuild && !options.bundle) {
317318
if (options.hasImportLoader) {
318319
args.push('--import', resolveImport('../loaders/esbuild.js'))
319320
} else if (options.engine === process.env.EXODUS_TEST_ENGINE) {
320-
console.warn(`Warning: ${options.engine} engine does not support --esbuild option`)
321+
console.warn(`Warning: ${engineName} does not support --esbuild option`)
321322
} else {
322-
console.error(`Error: ${options.engine} engine does not support --esbuild option`)
323+
console.error(`Error: ${engineName} does not support --esbuild option`)
323324
process.exit(1)
324325
}
325326
}
@@ -339,7 +340,7 @@ if (options.typescript) {
339340
// TODO: switch to native --experimental-strip-types where available
340341
args.push('--import', resolveImport('../loaders/typescript.js'))
341342
} else if (options.ts !== 'auto') {
342-
throw new Error(`Processing --typescript is not possible with engine ${options.engine}`)
343+
throw new Error(`Processing --typescript is not possible with ${engineName}`)
343344
}
344345
}
345346

@@ -509,7 +510,7 @@ if (options.pure) {
509510
}
510511

511512
setEnv('EXODUS_TEST_CONTEXT', 'pure')
512-
warnHuman(`${options.engine} engine is experimental and may not work an expected`)
513+
warnHuman(`${engineName} is experimental and may not work an expected`)
513514

514515
const runOne = async (inputFile) => {
515516
const bundled = buildFile ? await buildFile(inputFile) : undefined

0 commit comments

Comments
 (0)