From ad9fc4fe3d3d2390d7d12870beebdff2555e5c33 Mon Sep 17 00:00:00 2001 From: Will Soto Date: Fri, 16 Oct 2020 09:44:02 -0400 Subject: [PATCH] Fix --file not being respected (#84) Any files that were added via --file were being blown away when Webpack's entrypoints were being added. In order to resolve this, the entrypoints now get added via Mocha's addFile method. Closes #20 Signed-off-by: Will --- src/runner/TestRunner.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runner/TestRunner.ts b/src/runner/TestRunner.ts index 677f128..0346460 100644 --- a/src/runner/TestRunner.ts +++ b/src/runner/TestRunner.ts @@ -4,6 +4,7 @@ import _ from 'lodash' import chokidar from 'chokidar' import minimatch from 'minimatch' import { Configuration as WebpackConfig, Compiler, Stats } from 'webpack' +import Mocha from 'mocha' import createCompiler from '../webpack/compiler/createCompiler' import createWatchCompiler, { @@ -49,9 +50,6 @@ type MochaRunner = { resetTimeout: (ms: number) => void } } -type Mocha = { - run: (cb: (failures: number) => void) => MochaRunner -} export default class TestRunner extends EventEmitter { entries: Array @@ -84,8 +82,12 @@ export default class TestRunner extends EventEmitter { buildStats.affectedFiles.forEach(filePath => { delete require.cache[filePath] }) - // pass webpack's entry files to mocha - ;(mocha as any).files = buildStats.entries + // Pass webpack's entry files to mocha. + // Make sure to add them via `addFile` otherwise they blow away any other files + // that might have been added via `--file` + buildStats.entries.forEach(entry => { + mocha.addFile(entry) + }) return mocha }