From 05f5a5bc58969dc6a4c7b8df1da32988075361ed Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 10 Dec 2018 16:06:47 +0300 Subject: [PATCH] fix: `getLocalIdent` now accepts `false` value --- src/options.json | 9 +++++- test/__snapshots__/errors.test.js.snap | 2 ++ .../getLocalIdent-option.test.js.snap | 30 +++++++++++++++++++ test/errors.test.js | 5 ++-- test/getLocalIdent-option.test.js | 23 ++++++++++++++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/options.json b/src/options.json index 9100eefa8..45494ec73 100644 --- a/src/options.json +++ b/src/options.json @@ -52,7 +52,14 @@ "type": "string" }, "getLocalIdent": { - "instanceof": "Function" + "anyOf": [ + { + "type": "boolean" + }, + { + "instanceof": "Function" + } + ] }, "sourceMap": { "type": "boolean" diff --git a/test/__snapshots__/errors.test.js.snap b/test/__snapshots__/errors.test.js.snap index 210dfcfbc..e04c3b084 100644 --- a/test/__snapshots__/errors.test.js.snap +++ b/test/__snapshots__/errors.test.js.snap @@ -78,7 +78,9 @@ options.hashPrefix should be string exports[`validation 10`] = ` "CSS Loader Invalid Options +options.getLocalIdent should be boolean options.getLocalIdent should pass \\"instanceof\\" keyword validation +options.getLocalIdent should match some schema in anyOf " `; diff --git a/test/__snapshots__/getLocalIdent-option.test.js.snap b/test/__snapshots__/getLocalIdent-option.test.js.snap index 3204e4608..16ce6a7bc 100644 --- a/test/__snapshots__/getLocalIdent-option.test.js.snap +++ b/test/__snapshots__/getLocalIdent-option.test.js.snap @@ -30,6 +30,36 @@ Array [ exports[`getLocalIdent option should accepts arguments: warnings 1`] = `Array []`; +exports[`getLocalIdent option should allow to use \`false\` value: errors 1`] = `Array []`; + +exports[`getLocalIdent option should allow to use \`false\` value: locals 1`] = ` +Object { + "abc": "before_abc__1hk_after", + "def": "before_def__3oo_after", + "ghi": "before_ghi__2ZR_after", + "jkl": "before_jkl__aQ1_after", +} +`; + +exports[`getLocalIdent option should allow to use \`false\` value: module (evaluated) 1`] = ` +Array [ + Array [ + 1, + ".before_abc__1hk_after .before_def__3oo_after { + color: red; +} + +.before_ghi__2ZR_after .before_jkl__aQ1_after { + color: blue; +} +", + "", + ], +] +`; + +exports[`getLocalIdent option should allow to use \`false\` value: warnings 1`] = `Array []`; + exports[`getLocalIdent option should respect \`context\` option: errors 1`] = `Array []`; exports[`getLocalIdent option should respect \`context\` option: locals 1`] = ` diff --git a/test/errors.test.js b/test/errors.test.js index 14b87d36a..6c3d3970b 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -58,9 +58,8 @@ it('validation', () => { expect(() => validate({ hashPrefix: true })).toThrowErrorMatchingSnapshot(); expect(() => validate({ getLocalIdent: () => {} })).not.toThrow(); - expect(() => - validate({ getLocalIdent: true }) - ).toThrowErrorMatchingSnapshot(); + expect(() => validate({ getLocalIdent: false })).not.toThrow(); + expect(() => validate({ getLocalIdent: [] })).toThrowErrorMatchingSnapshot(); expect(() => validate({ sourceMap: true })).not.toThrow(); expect(() => validate({ sourceMap: false })).not.toThrow(); diff --git a/test/getLocalIdent-option.test.js b/test/getLocalIdent-option.test.js index b7c3fbbbc..1c5601719 100644 --- a/test/getLocalIdent-option.test.js +++ b/test/getLocalIdent-option.test.js @@ -104,4 +104,27 @@ describe('getLocalIdent option', () => { expect(stats.compilation.warnings).toMatchSnapshot('warnings'); expect(stats.compilation.errors).toMatchSnapshot('errors'); }); + + it('should allow to use `false` value', async () => { + const config = { + loader: { + options: { + context: path.resolve(__dirname, 'fixtures/modules'), + modules: true, + localIdentName: 'before_[local]__[hash:base64:3]_after', + getLocalIdent: false, + }, + }, + }; + const testId = './modules/getLocalIdent.css'; + const stats = await webpack(testId, config); + const { modules } = stats.toJson(); + const module = modules.find((m) => m.id === testId); + const evaluatedModule = evaluated(module.source); + + expect(evaluatedModule).toMatchSnapshot('module (evaluated)'); + expect(evaluatedModule.locals).toMatchSnapshot('locals'); + expect(stats.compilation.warnings).toMatchSnapshot('warnings'); + expect(stats.compilation.errors).toMatchSnapshot('errors'); + }); });