Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit c240d71

Browse files
committed
fix: don’t hook into ‘compile’ event when ‘shouldWatch’ is false
1 parent 8206bf3 commit c240d71

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,22 @@ const preprocessor = (options = {}) => {
149149
latestBundle = createDeferred()
150150
bundles[filePath] = latestBundle.promise.tap(() => {
151151
log('- compile finished for', filePath)
152-
// when the bundling is finished, we call `util.fileUpdated`
153-
// to let Cypress know to re-run the spec
152+
// when the bundling is finished, emit 'rerun' to let Cypress
153+
// know to rerun the spec
154154
file.emit('rerun')
155155
})
156156
}
157157

158-
if (compiler.hooks) {
159-
compiler.hooks.compile.tap(plugin, onCompile)
160-
} else {
161-
compiler.plugin('compile', onCompile)
162-
}
163-
158+
// when we should watch, we hook into the 'compile' hook so we know when
159+
// to rerun the tests
164160
if (file.shouldWatch) {
165161
log('watching')
162+
163+
if (compiler.hooks) {
164+
compiler.hooks.compile.tap(plugin, onCompile)
165+
} else {
166+
compiler.plugin('compile', onCompile)
167+
}
166168
}
167169

168170
const bundler = file.shouldWatch ? compiler.watch(watchOptions, handle) : compiler.run(handle)

test/index_spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,23 @@ describe('webpack preprocessor', function () {
142142
})
143143
})
144144

145-
it('emits `rerun` when there is an update', function () {
145+
it('emits "rerun" when shouldWatch is true and there is an update', function () {
146+
this.file.shouldWatch = true
147+
this.compilerApi.watch.yields(null, this.statsApi)
146148
this.compilerApi.plugin.withArgs('compile').yields()
147149
return this.run().then(() => {
148150
expect(this.file.emit).to.be.calledWith('rerun')
149151
})
150152
})
151153

154+
it('does not emit "rerun" when shouldWatch is false', function () {
155+
this.file.shouldWatch = false
156+
this.compilerApi.plugin.withArgs('compile').yields()
157+
return this.run().then(() => {
158+
expect(this.file.emit).not.to.be.calledWith('rerun')
159+
})
160+
})
161+
152162
it('closes bundler when shouldWatch is true and `close` is emitted', function () {
153163
this.file.shouldWatch = true
154164
this.compilerApi.watch.yields(null, this.statsApi)

0 commit comments

Comments
 (0)