Skip to content

Commit

Permalink
fix: getLocalIdent now accepts false value (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Dec 10, 2018
1 parent 634ab49 commit 1825e8a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/options.json
Expand Up @@ -52,7 +52,14 @@
"type": "string"
},
"getLocalIdent": {
"instanceof": "Function"
"anyOf": [
{
"type": "boolean"
},
{
"instanceof": "Function"
}
]
},
"sourceMap": {
"type": "boolean"
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/errors.test.js.snap
Expand Up @@ -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
"
`;

Expand Down
30 changes: 30 additions & 0 deletions test/__snapshots__/getLocalIdent-option.test.js.snap
Expand Up @@ -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`] = `
Expand Down
5 changes: 2 additions & 3 deletions test/errors.test.js
Expand Up @@ -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();
Expand Down
23 changes: 23 additions & 0 deletions test/getLocalIdent-option.test.js
Expand Up @@ -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');
});
});

0 comments on commit 1825e8a

Please sign in to comment.