Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getLocalIdent now accepts false value #865

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/options.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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');
});
});