Skip to content

Commit

Permalink
Ensure that the cache default functions gets correctly executed (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored Jul 11, 2017
1 parent 96fa0ef commit d01aba9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/options/WebpackOptionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class WebpackOptionHelper extends OptionHelper {
options.cache = false;
}

// ensure that when we send the cache option to webpack in watch mode it is not the function
// TODO: this is workaround and should be handled in a more generic way
if (typeof options.cache === 'function') {
options.cache = options.cache(options);
}

return this.filterGruntOptions(options);
}
}
Expand Down
20 changes: 19 additions & 1 deletion tests/src/options/WebpackOptionHelper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import WebpackOptionHelper from '../../../src/options/WebpackOptionHelper';

test('cache is enabled in watch mode', (t) => {
test('cache stays enabled in watch mode', (t) => {
const options = { watch: true, cache: true };
const helper = new WebpackOptionHelper();

Expand All @@ -10,6 +10,24 @@ test('cache is enabled in watch mode', (t) => {
t.true(result.cache);
});

test('cache is enabled in watch mode by default', (t) => {
const options = { watch: true, cache: () => true };
const helper = new WebpackOptionHelper();

const result = helper.filterOptions(options);

t.true(result.cache);
});

test('cache is disabled in normal mode by default', (t) => {
const options = { watch: false, cache: () => true };
const helper = new WebpackOptionHelper();

const result = helper.filterOptions(options);

t.false(result.cache);
});

test('cache is disabled in normal mode', (t) => {
const options = { watch: false, cache: true };
const helper = new WebpackOptionHelper();
Expand Down

0 comments on commit d01aba9

Please sign in to comment.