From 4e4733dc10fd8a8ecda5b47421b390a479b826aa Mon Sep 17 00:00:00 2001 From: Alexander Akait Date: Fri, 6 Nov 2020 16:57:45 +0300 Subject: [PATCH] fix: schema (#652) --- src/loader-options.json | 2 +- src/plugin-options.json | 2 +- .../validate-loader-options.test.js.snap | 48 +++++++++++++++++++ .../validate-plugin-options.test.js.snap | 48 +++++++++++++++++++ test/cases/js-hash/webpack.config.js | 3 -- test/validate-loader-options.test.js | 3 +- test/validate-plugin-options.test.js | 3 +- 7 files changed, 100 insertions(+), 9 deletions(-) diff --git a/src/loader-options.json b/src/loader-options.json index eb870090..7e66190d 100644 --- a/src/loader-options.json +++ b/src/loader-options.json @@ -1,6 +1,6 @@ { "type": "object", - "additionalProperties": true, + "additionalProperties": false, "properties": { "publicPath": { "anyOf": [ diff --git a/src/plugin-options.json b/src/plugin-options.json index 94aa6d8e..04e5c9ed 100644 --- a/src/plugin-options.json +++ b/src/plugin-options.json @@ -1,6 +1,6 @@ { "type": "object", - "additionalProperties": true, + "additionalProperties": false, "properties": { "filename": { "anyOf": [ diff --git a/test/__snapshots__/validate-loader-options.test.js.snap b/test/__snapshots__/validate-loader-options.test.js.snap index 037f1a8b..dd4b5ffa 100644 --- a/test/__snapshots__/validate-loader-options.test.js.snap +++ b/test/__snapshots__/validate-loader-options.test.js.snap @@ -25,3 +25,51 @@ exports[`validate options should throw an error on the "publicPath" option with * options.publicPath should be a string. * options.publicPath should be an instance of function." `; + +exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin Loader has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { publicPath?, esModule?, modules? }" +`; diff --git a/test/__snapshots__/validate-plugin-options.test.js.snap b/test/__snapshots__/validate-plugin-options.test.js.snap index 1a6b986c..8d9e1b45 100644 --- a/test/__snapshots__/validate-plugin-options.test.js.snap +++ b/test/__snapshots__/validate-plugin-options.test.js.snap @@ -95,3 +95,51 @@ exports[`validate options should throw an error on the "linkType" option with "i * options.linkType should be \\"text/css\\". * options.linkType should be a boolean." `; + +exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; + +exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = ` +"Invalid options object. Mini CSS Extract Plugin has been initialized using an options object that does not match the API schema. + - options has an unknown property 'unknown'. These properties are valid: + object { filename?, chunkFilename?, ignoreOrder?, insert?, attributes?, linkType? }" +`; diff --git a/test/cases/js-hash/webpack.config.js b/test/cases/js-hash/webpack.config.js index 9cd67911..f0181102 100644 --- a/test/cases/js-hash/webpack.config.js +++ b/test/cases/js-hash/webpack.config.js @@ -10,9 +10,6 @@ module.exports = [1, 2].map((n) => { use: [ { loader: Self.loader, - options: { - hmr: false, - }, }, { loader: 'css-loader', diff --git a/test/validate-loader-options.test.js b/test/validate-loader-options.test.js index ee5cb486..14cfeda1 100644 --- a/test/validate-loader-options.test.js +++ b/test/validate-loader-options.test.js @@ -16,8 +16,7 @@ describe('validate options', () => { }, unknown: { success: [], - // TODO failed in next release - // failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], + failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], }, }; diff --git a/test/validate-plugin-options.test.js b/test/validate-plugin-options.test.js index dfae508b..0638f4a8 100644 --- a/test/validate-plugin-options.test.js +++ b/test/validate-plugin-options.test.js @@ -38,8 +38,7 @@ describe('validate options', () => { }, unknown: { success: [], - // TODO failed in next release - // failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], + failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], }, };