Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 2b2df9f

Browse files
Merge pull request #6 from cypress-io/issue-5-dirty-cache
Ensure cache is clean when running browserify
2 parents 86a0dd0 + 75e8b48 commit 2b2df9f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ const defaultOptions = {
6060
const preprocessor = (options = {}) => {
6161
log('received user options', options)
6262

63-
// allow user to override default options
64-
const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions)
65-
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)
66-
6763
// we return function that accepts the arguments provided by
6864
// the event 'file:preprocessor'
6965
//
@@ -95,6 +91,10 @@ const preprocessor = (options = {}) => {
9591
log(`input: ${filePath}`)
9692
log(`output: ${outputPath}`)
9793

94+
// allow user to override default options
95+
const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions)
96+
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)
97+
9898
// we need to override and control entries
9999
Object.assign(browserifyOptions, {
100100
entries: [filePath],

test/index_spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ describe('browserify preprocessor', function () {
119119
})
120120
})
121121

122+
it('starts with clean cache and packageCache', function () {
123+
browserify.reset()
124+
browserify.returns(this.bundlerApi)
125+
126+
const run = preprocessor(this.options)
127+
return run(this.file)
128+
.then(() => {
129+
browserify.lastCall.args[0].cache = { foo: 'bar' }
130+
browserify.lastCall.args[0].packageCache = { foo: 'bar' }
131+
this.file.on.withArgs('close').yield()
132+
133+
return run(this.file)
134+
})
135+
.then(() => {
136+
expect(browserify).to.be.calledTwice
137+
expect(browserify.lastCall.args[0].cache).to.eql({})
138+
expect(browserify.lastCall.args[0].packageCache).to.eql({})
139+
})
140+
})
141+
122142
it('watches when shouldWatch is true', function () {
123143
this.file.shouldWatch = true
124144
return this.run().then(() => {
@@ -166,7 +186,7 @@ describe('browserify preprocessor', function () {
166186
})
167187

168188
it('uses transforms if provided', function () {
169-
const transform = [() => {}, {}]
189+
const transform = [() => {}, {}]
170190
this.options.browserifyOptions = { transform }
171191
return this.run().then(() => {
172192
expect(browserify.lastCall.args[0].transform).to.eql(transform)

0 commit comments

Comments
 (0)