Skip to content

Commit d01aba9

Browse files
authored
Ensure that the cache default functions gets correctly executed (#150)
1 parent 96fa0ef commit d01aba9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/options/WebpackOptionHelper.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class WebpackOptionHelper extends OptionHelper {
2525
options.cache = false;
2626
}
2727

28+
// ensure that when we send the cache option to webpack in watch mode it is not the function
29+
// TODO: this is workaround and should be handled in a more generic way
30+
if (typeof options.cache === 'function') {
31+
options.cache = options.cache(options);
32+
}
33+
2834
return this.filterGruntOptions(options);
2935
}
3036
}

tests/src/options/WebpackOptionHelper.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import WebpackOptionHelper from '../../../src/options/WebpackOptionHelper';
33

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

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

13+
test('cache is enabled in watch mode by default', (t) => {
14+
const options = { watch: true, cache: () => true };
15+
const helper = new WebpackOptionHelper();
16+
17+
const result = helper.filterOptions(options);
18+
19+
t.true(result.cache);
20+
});
21+
22+
test('cache is disabled in normal mode by default', (t) => {
23+
const options = { watch: false, cache: () => true };
24+
const helper = new WebpackOptionHelper();
25+
26+
const result = helper.filterOptions(options);
27+
28+
t.false(result.cache);
29+
});
30+
1331
test('cache is disabled in normal mode', (t) => {
1432
const options = { watch: false, cache: true };
1533
const helper = new WebpackOptionHelper();

0 commit comments

Comments
 (0)