Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the cache default functions gets correctly executed #150

Merged
merged 1 commit into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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