From 75e8b48a92bdf25970d18f72d09a821c9d15f95d Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Tue, 28 Nov 2017 10:41:40 -0500 Subject: [PATCH] fix: ensure cache is clean when running browserify --- index.js | 8 ++++---- test/index_spec.js | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7bb771b..2319817 100644 --- a/index.js +++ b/index.js @@ -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' // @@ -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], diff --git a/test/index_spec.js b/test/index_spec.js index b2efe83..b4bebcb 100644 --- a/test/index_spec.js +++ b/test/index_spec.js @@ -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(() => { @@ -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)