Skip to content

Commit

Permalink
Fix --file not being respected (#84)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
willsoto authored Oct 16, 2020
1 parent 556836c commit ad9fc4f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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<string>
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit ad9fc4f

Please sign in to comment.