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

Commit

Permalink
Merge pull request #6 from cypress-io/issue-5-dirty-cache
Browse files Browse the repository at this point in the history
Ensure cache is clean when running browserify
  • Loading branch information
chrisbreiding authored Nov 28, 2017
2 parents 86a0dd0 + 75e8b48 commit 2b2df9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ const defaultOptions = {
const preprocessor = (options = {}) => {
log('received user options', options)

// allow user to override default options
const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions)
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)

// we return function that accepts the arguments provided by
// the event 'file:preprocessor'
//
Expand Down Expand Up @@ -95,6 +91,10 @@ const preprocessor = (options = {}) => {
log(`input: ${filePath}`)
log(`output: ${outputPath}`)

// allow user to override default options
const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions)
const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions)

// we need to override and control entries
Object.assign(browserifyOptions, {
entries: [filePath],
Expand Down
22 changes: 21 additions & 1 deletion test/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ describe('browserify preprocessor', function () {
})
})

it('starts with clean cache and packageCache', function () {
browserify.reset()
browserify.returns(this.bundlerApi)

const run = preprocessor(this.options)
return run(this.file)
.then(() => {
browserify.lastCall.args[0].cache = { foo: 'bar' }
browserify.lastCall.args[0].packageCache = { foo: 'bar' }
this.file.on.withArgs('close').yield()

return run(this.file)
})
.then(() => {
expect(browserify).to.be.calledTwice
expect(browserify.lastCall.args[0].cache).to.eql({})
expect(browserify.lastCall.args[0].packageCache).to.eql({})
})
})

it('watches when shouldWatch is true', function () {
this.file.shouldWatch = true
return this.run().then(() => {
Expand Down Expand Up @@ -166,7 +186,7 @@ describe('browserify preprocessor', function () {
})

it('uses transforms if provided', function () {
const transform = [() => {}, {}]
const transform = [() => {}, {}]
this.options.browserifyOptions = { transform }
return this.run().then(() => {
expect(browserify.lastCall.args[0].transform).to.eql(transform)
Expand Down

0 comments on commit 2b2df9f

Please sign in to comment.