diff --git a/.prettierignore b/.prettierignore index 7ca974bc4..decfb8994 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,6 +2,7 @@ test/*.* !test/*.js !test/**/webpack.config.js +!test/**/deprecations.js # Ignore example fixtures examples/*.* diff --git a/test/ConfigTestCases.test.js b/test/ConfigTestCases.test.js index cdfcc1d8d..7a1831acc 100644 --- a/test/ConfigTestCases.test.js +++ b/test/ConfigTestCases.test.js @@ -7,6 +7,7 @@ const mkdirp = require("mkdirp"); const rimraf = require("rimraf"); const checkArrayExpectation = require("./checkArrayExpectation"); const createLazyTestEnv = require("./helpers/createLazyTestEnv"); +const deprecationTracking = require("./helpers/deprecationTracking"); const FakeDocument = require("./helpers/FakeDocument"); const webpack = require(".."); @@ -107,6 +108,7 @@ describe("ConfigTestCases", () => { } if (testConfig.timeout) setDefaultTimeout(testConfig.timeout); + const deprecationTracker = deprecationTracking.start(); webpack(options, (err, stats) => { if (err) { const fakeStats = { @@ -168,6 +170,17 @@ describe("ConfigTestCases", () => { ) ) return; + const deprecations = deprecationTracker(); + if ( + checkArrayExpectation( + testDirectory, + { deprecations }, + "deprecation", + "Deprecation", + done + ) + ) + return; const globalContext = { console: console, diff --git a/test/configCases/custom-source-type/localization/deprecations.js b/test/configCases/custom-source-type/localization/deprecations.js new file mode 100644 index 000000000..44a05b2a7 --- /dev/null +++ b/test/configCases/custom-source-type/localization/deprecations.js @@ -0,0 +1 @@ +module.exports = [{ code: /DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_MANIFEST/ }]; diff --git a/test/configCases/loaders/issue-3320/deprecations.js b/test/configCases/loaders/issue-3320/deprecations.js new file mode 100644 index 000000000..aac174551 --- /dev/null +++ b/test/configCases/loaders/issue-3320/deprecations.js @@ -0,0 +1,10 @@ +module.exports = [ + { + code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, + message: /Using a string as loader options is deprecated \(ruleSet\[1\]\.rules\[2\]\.options\)/ + }, + { + code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, + message: /Using a string as loader options is deprecated \(ruleSet\[1\]\.rules\[3\]\.use\[0\]\.options\)/ + } +]; diff --git a/test/configCases/plugins/mini-css-extract-plugin/deprecations.js b/test/configCases/plugins/mini-css-extract-plugin/deprecations.js new file mode 100644 index 000000000..19f3a4df6 --- /dev/null +++ b/test/configCases/plugins/mini-css-extract-plugin/deprecations.js @@ -0,0 +1,14 @@ +module.exports = [ + { code: /DEP_WEBPACK_CHUNK_GROUP_GET_MODULE_INDEX_2/ }, + { code: /DEP_WEBPACK_CHUNK_MODULES_ITERABLE/ }, + { code: /DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_MANIFEST/ }, + { code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ }, + { code: /DEP_WEBPACK_MAIN_TEMPLATE_GET_ASSET_PATH/ }, + { code: /DEP_WEBPACK_MAIN_TEMPLATE_HASH_FOR_CHUNK/ }, + { code: /DEP_WEBPACK_MAIN_TEMPLATE_OUTPUT_OPTIONS/ }, + { code: /DEP_WEBPACK_MAIN_TEMPLATE_RENDER_CURRENT_HASH_CODE/ }, + { code: /DEP_WEBPACK_MAIN_TEMPLATE_RENDER_MANIFEST/ }, + { code: /DEP_WEBPACK_MAIN_TEMPLATE_REQUIRE_FN/ }, + { code: /DEP_WEBPACK_MODULE_ID/ }, + { code: /DEP_WEBPACK_MODULE_UPDATE_HASH/ } +]; diff --git a/test/configCases/plugins/profiling-plugin/deprecations.js b/test/configCases/plugins/profiling-plugin/deprecations.js new file mode 100644 index 000000000..dee16addc --- /dev/null +++ b/test/configCases/plugins/profiling-plugin/deprecations.js @@ -0,0 +1,3 @@ +module.exports = [ + { code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ } +]; diff --git a/test/configCases/rule-set/chaining/deprecations.js b/test/configCases/rule-set/chaining/deprecations.js new file mode 100644 index 000000000..6452ef041 --- /dev/null +++ b/test/configCases/rule-set/chaining/deprecations.js @@ -0,0 +1,18 @@ +module.exports = [ + { + code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, + message: /rules\[0\].use\[0\]/ + }, + { + code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, + message: /rules\[0\].use\[1\]/ + }, + { + code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, + message: /rules\[1\].use\[0\]/ + }, + { + code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, + message: /rules\[1\].use\[1\]/ + } +]; diff --git a/test/configCases/rule-set/simple-use-array-fn/deprecations.js b/test/configCases/rule-set/simple-use-array-fn/deprecations.js new file mode 100644 index 000000000..509a3520b --- /dev/null +++ b/test/configCases/rule-set/simple-use-array-fn/deprecations.js @@ -0,0 +1,5 @@ +module.exports = [ + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[0\]/ }, + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[1\]/ }, + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[2\]/ } +]; diff --git a/test/configCases/rule-set/simple-use-fn-array/deprecations.js b/test/configCases/rule-set/simple-use-fn-array/deprecations.js new file mode 100644 index 000000000..509a3520b --- /dev/null +++ b/test/configCases/rule-set/simple-use-fn-array/deprecations.js @@ -0,0 +1,5 @@ +module.exports = [ + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[0\]/ }, + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[1\]/ }, + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[2\]/ } +]; diff --git a/test/configCases/rule-set/simple/deprecations.js b/test/configCases/rule-set/simple/deprecations.js new file mode 100644 index 000000000..509a3520b --- /dev/null +++ b/test/configCases/rule-set/simple/deprecations.js @@ -0,0 +1,5 @@ +module.exports = [ + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[0\]/ }, + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[1\]/ }, + { code: /DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING/, message: /oneOf\[2\]/ } +]; diff --git a/test/configCases/source-map/source-map-with-profiling-plugin/deprecations.js b/test/configCases/source-map/source-map-with-profiling-plugin/deprecations.js new file mode 100644 index 000000000..dee16addc --- /dev/null +++ b/test/configCases/source-map/source-map-with-profiling-plugin/deprecations.js @@ -0,0 +1,3 @@ +module.exports = [ + { code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ } +]; diff --git a/test/helpers/deprecationTracking.js b/test/helpers/deprecationTracking.js new file mode 100644 index 000000000..02b92ab91 --- /dev/null +++ b/test/helpers/deprecationTracking.js @@ -0,0 +1,40 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ + +"use strict"; + +const util = require("util"); + +let interception = undefined; + +const originalDeprecate = util.deprecate; +util.deprecate = (fn, message, code) => { + const original = originalDeprecate(fn, message, code); + + return function(...args) { + if (interception) { + interception.set(`${code}: ${message}`, { code, message }); + return fn.apply(this, args); + } else { + return original.apply(this, args); + } + }; +}; + +exports.start = handler => { + interception = new Map(); + + return () => { + const map = interception; + interception = undefined; + return Array.from(map) + .sort(([a], [b]) => { + if (a < b) return -1; + if (a > b) return 1; + return 0; + }) + .map(([key, data]) => data); + }; +};