Skip to content

Commit 7dd33d6

Browse files
committed
WIP adding asserts for warnings/deprecations
1 parent d26b955 commit 7dd33d6

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

lib/WebpackConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,6 @@ class WebpackConfig {
526526
}
527527

528528
createSharedEntry(name, file) {
529-
logger.deprecation('Encore.createSharedEntry() is deprecated and will be removed in a future version, please use Encore.splitEntryChunks() or Encore.addCacheGroup() instead.');
530-
531529
if (this.shouldSplitEntryChunks) {
532530
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');
533531
}
@@ -537,6 +535,8 @@ class WebpackConfig {
537535
throw new Error('createSharedEntry() cannot be called multiple times: you can only create *one* shared entry.');
538536
}
539537

538+
logger.deprecation('Encore.createSharedEntry() is deprecated and will be removed in a future version, please use Encore.splitEntryChunks() or Encore.addCacheGroup() instead.');
539+
540540
if (Array.isArray(file)) {
541541
throw new Error('Argument 2 to createSharedEntry() must be a single string file: not an array of files. Try creating one file that requires/imports all the modules that should be included.');
542542
}

test/WebpackConfig.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('WebpackConfig object', () => {
141141
const config = createConfig();
142142

143143
config.setPublicPath('foo');
144-
loggerAssert.assertWarning('TODO');
144+
loggerAssert.assertWarning('The value passed to setPublicPath() should *usually* start with "/" or be a full URL');
145145
});
146146
});
147147

@@ -205,7 +205,7 @@ describe('WebpackConfig object', () => {
205205
const config = createConfig();
206206

207207
config.setManifestKeyPrefix('/foo/');
208-
loggerAssert.assertWarning('TODO');
208+
loggerAssert.assertWarning('The value passed to setManifestKeyPrefix "/foo/" starts with "/". This is allowed, but since the key prefix does not normally start with a "/"');
209209
});
210210
});
211211

@@ -380,6 +380,7 @@ describe('WebpackConfig object', () => {
380380
it('Calling twice throws an error', () => {
381381
const config = createConfig();
382382
config.createSharedEntry('vendor', 'jquery');
383+
loggerAssert.assertDeprecation('Encore.createSharedEntry() is deprecated');
383384

384385
expect(() => {
385386
config.createSharedEntry('vendor2', './main');
@@ -606,7 +607,7 @@ describe('WebpackConfig object', () => {
606607

607608
it('Calling with "includeNodeModules" option', () => {
608609
const config = createConfig();
609-
config.configureBabel(() => {}, { include_node_modules: ['foo', 'bar'] });
610+
config.configureBabel(() => {}, { includeNodeModules: ['foo', 'bar'] });
610611

611612
expect(config.babelOptions.exclude).to.be.a('Function');
612613

@@ -662,7 +663,6 @@ describe('WebpackConfig object', () => {
662663
const config = createConfig();
663664
config.runtimeConfig.babelRcFileExists = true;
664665
config.configureBabel(null, { includeNodeModules: ['foo'] });
665-
loggerAssert.assertWarning('TODO');
666666
});
667667

668668
it('Calling with a non-whitelisted option when .babelrc is present displays a warning', () => {
@@ -1322,6 +1322,7 @@ describe('WebpackConfig object', () => {
13221322

13231323
config.configureLoaderRule('eslint', callback);
13241324
expect(config.loaderConfigurationCallbacks['eslint']).to.equal(callback);
1325+
loggerAssert.assertWarning('Be careful when using Encore.configureLoaderRule');
13251326
});
13261327

13271328
it('Call method with a not supported loader', () => {
@@ -1330,6 +1331,7 @@ describe('WebpackConfig object', () => {
13301331
expect(() => {
13311332
config.configureLoaderRule('reason');
13321333
}).to.throw('Loader "reason" is not configurable. Valid loaders are "javascript", "css", "images", "fonts", "sass", "less", "stylus", "vue", "eslint", "typescript", "handlebars" and the aliases "js", "ts", "scss".');
1334+
loggerAssert.assertWarning('Be careful when using Encore.configureLoaderRule');
13331335
});
13341336

13351337
it('Call method with not a valid callback', () => {
@@ -1338,10 +1340,12 @@ describe('WebpackConfig object', () => {
13381340
expect(() => {
13391341
config.configureLoaderRule('eslint');
13401342
}).to.throw('Argument 2 to configureLoaderRule() must be a callback function.');
1343+
loggerAssert.assertWarning('Be careful when using Encore.configureLoaderRule');
13411344

13421345
expect(() => {
13431346
config.configureLoaderRule('eslint', {});
13441347
}).to.throw('Argument 2 to configureLoaderRule() must be a callback function.');
1348+
loggerAssert.assertWarning('Be careful when using Encore.configureLoaderRule');
13451349
});
13461350
});
13471351

test/_unsilencedLogsCheck.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ beforeEach(function() {
1717

1818
afterEach(function() {
1919
if (logger.getDeprecations().length > 0) {
20-
this.test.error(new Error(`There were ${logger.getWarnings().length} unexpected deprecation log messages: \n${logger.getDeprecations().join('\n')}`));
20+
this.test.error(new Error(`There were ${logger.getDeprecations().length} unexpected deprecation log messages: \n${logger.getDeprecations().join('\n')}`));
2121
}
2222

2323
if (logger.getWarnings().length > 0) {

test/config-generator.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const loggerAssert = require('./helpers/logger-assert');
2222

2323
const isWindows = (process.platform === 'win32');
2424

25-
function createConfig(runtimeConfig = null) {
25+
function createConfig(runtimeConfig = null, disableSingleRuntimeChunk = true) {
2626
runtimeConfig = runtimeConfig ? runtimeConfig : new RuntimeConfig();
2727

2828
if (null === runtimeConfig.context) {
@@ -37,7 +37,12 @@ function createConfig(runtimeConfig = null) {
3737
runtimeConfig.babelRcFileExists = false;
3838
}
3939

40-
return new WebpackConfig(runtimeConfig);
40+
const config = new WebpackConfig(runtimeConfig);
41+
if (disableSingleRuntimeChunk) {
42+
config.disableSingleRuntimeChunk();
43+
}
44+
45+
return config;
4146
}
4247

4348
function findPlugin(pluginConstructor, plugins) {
@@ -167,6 +172,7 @@ describe('The config-generator function', () => {
167172
// pretend we're installed to a subdirectory
168173
config.setPublicPath('/subdirectory/build');
169174
config.setManifestKeyPrefix('/build');
175+
loggerAssert.assertWarning('The value passed to setManifestKeyPrefix "/build" starts with "/"');
170176

171177
const actualConfig = configGenerator(config);
172178

@@ -1085,7 +1091,7 @@ describe('The config-generator function', () => {
10851091
});
10861092

10871093
it('Not set + createSharedEntry()', () => {
1088-
const config = createConfig();
1094+
const config = createConfig(null, false);
10891095
config.outputPath = '/tmp/public/build';
10901096
config.setPublicPath('/build/');
10911097
config.createSharedEntry('foo', 'bar.js');
@@ -1096,7 +1102,7 @@ describe('The config-generator function', () => {
10961102
});
10971103

10981104
it('Not set without createSharedEntry()', () => {
1099-
const config = createConfig();
1105+
const config = createConfig(null, false);
11001106
config.outputPath = '/tmp/public/build';
11011107
config.setPublicPath('/build/');
11021108

@@ -1133,6 +1139,10 @@ describe('The config-generator function', () => {
11331139
config.enableSingleRuntimeChunk();
11341140
});
11351141

1142+
afterEach(function() {
1143+
loggerAssert.assertWarning('Be careful when using Encore.configureLoaderRule');
1144+
});
1145+
11361146
it('configure rule for "javascript"', () => {
11371147
config.configureLoaderRule('javascript', (loaderRule) => {
11381148
loaderRule.test = /\.m?js$/;

test/helpers/logger-assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function assertDeprecation(expectedMessage) {
2121

2222
function assertLogMessage(messages, description, expectedMessage) {
2323
if (messages.length === 0) {
24-
throw new Error(`Found zero log ${description}s. And so, expected ${description} ${expectedMessage} was not logged.`);
24+
throw new Error(`Found zero log ${description}s. And so, expected "${description} ${expectedMessage}" was not logged.`);
2525
}
2626

2727
let isFound = false;

0 commit comments

Comments
 (0)