Skip to content

Commit 1d7a464

Browse files
authoredMay 28, 2019
feat: modules options now accepts object config (#937)
BREAKING CHANGE: - `localIdentName` option was removed in favor `modules.localIdentName` option - `context` option was remove in favor `modules.context` option - `hashPrefix` option was removed in favor `modules.hashPrefix` option - `getLocalIdent` option was removed in favor `modules.getLocalIdent` option - `localIdentRegExp` option was removed in favor `modules.localIdentRegExp` option
1 parent 38ff645 commit 1d7a464

12 files changed

+5633
-2677
lines changed
 

‎README.md

+178-59
Large diffs are not rendered by default.

‎src/options.json

+37-27
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,45 @@
2929
{
3030
"type": "string",
3131
"enum": ["local", "global"]
32-
}
33-
]
34-
},
35-
"localIdentName": {
36-
"type": "string"
37-
},
38-
"localIdentRegExp": {
39-
"anyOf": [
40-
{
41-
"type": "string"
4232
},
4333
{
44-
"instanceof": "RegExp"
45-
}
46-
]
47-
},
48-
"context": {
49-
"type": "string"
50-
},
51-
"hashPrefix": {
52-
"type": "string"
53-
},
54-
"getLocalIdent": {
55-
"anyOf": [
56-
{
57-
"type": "boolean"
58-
},
59-
{
60-
"instanceof": "Function"
34+
"type": "object",
35+
"additionalProperties": false,
36+
"properties": {
37+
"mode": {
38+
"type": "string",
39+
"enum": ["local", "global"]
40+
},
41+
"localIdentName": {
42+
"type": "string"
43+
},
44+
"localIdentRegExp": {
45+
"anyOf": [
46+
{
47+
"type": "string"
48+
},
49+
{
50+
"instanceof": "RegExp"
51+
}
52+
]
53+
},
54+
"context": {
55+
"type": "string"
56+
},
57+
"hashPrefix": {
58+
"type": "string"
59+
},
60+
"getLocalIdent": {
61+
"anyOf": [
62+
{
63+
"type": "boolean"
64+
},
65+
{
66+
"instanceof": "Function"
67+
}
68+
]
69+
}
70+
}
6171
}
6272
]
6373
},

‎src/utils.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,41 @@ function getImports(messages, importUrlPrefix, loaderContext, callback) {
267267
}
268268

269269
function getModulesPlugins(options, loaderContext) {
270-
const mode = typeof options.modules === 'boolean' ? 'local' : options.modules;
270+
let modulesOptions = {
271+
mode: 'local',
272+
localIdentName: '[hash:base64]',
273+
getLocalIdent,
274+
context: null,
275+
hashPrefix: '',
276+
localIdentRegExp: null,
277+
};
278+
279+
if (
280+
typeof options.modules === 'boolean' ||
281+
typeof options.modules === 'string'
282+
) {
283+
modulesOptions.mode =
284+
typeof options.modules === 'string' ? options.modules : 'local';
285+
} else {
286+
modulesOptions = Object.assign({}, modulesOptions, options.modules);
287+
}
271288

272289
return [
273290
modulesValues,
274-
localByDefault({ mode }),
291+
localByDefault({ mode: modulesOptions.mode }),
275292
extractImports(),
276293
modulesScope({
277294
generateScopedName: function generateScopedName(exportName) {
278-
const localIdentName = options.localIdentName || '[hash:base64]';
279-
const customGetLocalIdent = options.getLocalIdent || getLocalIdent;
280-
281-
return customGetLocalIdent(loaderContext, localIdentName, exportName, {
282-
regExp: options.localIdentRegExp,
283-
hashPrefix: options.hashPrefix || '',
284-
context: options.context,
285-
});
295+
return modulesOptions.getLocalIdent(
296+
loaderContext,
297+
modulesOptions.localIdentName,
298+
exportName,
299+
{
300+
context: modulesOptions.context,
301+
hashPrefix: modulesOptions.hashPrefix,
302+
regExp: modulesOptions.localIdentRegExp,
303+
}
304+
);
286305
},
287306
}),
288307
];

‎test/__snapshots__/errors.test.js.snap

-117
This file was deleted.

‎test/__snapshots__/getLocalIdent-option.test.js.snap

-150
This file was deleted.

‎test/__snapshots__/localIdentName-option.test.js.snap

-1,433
This file was deleted.

‎test/__snapshots__/modules-option.test.js.snap

+4,868-548
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`validate options 1`] = `
4+
"CSS Loader Invalid Options
5+
6+
options.url should be boolean
7+
options.url should pass \\"instanceof\\" keyword validation
8+
options.url should match some schema in anyOf
9+
"
10+
`;
11+
12+
exports[`validate options 2`] = `
13+
"CSS Loader Invalid Options
14+
15+
options.import should be boolean
16+
options.import should pass \\"instanceof\\" keyword validation
17+
options.import should match some schema in anyOf
18+
"
19+
`;
20+
21+
exports[`validate options 3`] = `
22+
"CSS Loader Invalid Options
23+
24+
options.modules should be boolean
25+
options.modules should be equal to one of the allowed values
26+
options.modules should be object
27+
options.modules should match some schema in anyOf
28+
"
29+
`;
30+
31+
exports[`validate options 4`] = `
32+
"CSS Loader Invalid Options
33+
34+
options.modules should be boolean
35+
options.modules should be equal to one of the allowed values
36+
options.modules should be object
37+
options.modules should match some schema in anyOf
38+
"
39+
`;
40+
41+
exports[`validate options 5`] = `
42+
"CSS Loader Invalid Options
43+
44+
options.modules should be boolean
45+
options.modules should be equal to one of the allowed values
46+
options.modules should be object
47+
options.modules should match some schema in anyOf
48+
"
49+
`;
50+
51+
exports[`validate options 6`] = `
52+
"CSS Loader Invalid Options
53+
54+
options.modules should be boolean
55+
options.modules should be string
56+
options.modules should be equal to one of the allowed values
57+
options.modules.mode should be string
58+
options.modules.mode should be equal to one of the allowed values
59+
options.modules should match some schema in anyOf
60+
"
61+
`;
62+
63+
exports[`validate options 7`] = `
64+
"CSS Loader Invalid Options
65+
66+
options.modules should be boolean
67+
options.modules should be string
68+
options.modules should be equal to one of the allowed values
69+
options.modules.mode should be equal to one of the allowed values
70+
options.modules should match some schema in anyOf
71+
"
72+
`;
73+
74+
exports[`validate options 8`] = `
75+
"CSS Loader Invalid Options
76+
77+
options.modules should be boolean
78+
options.modules should be string
79+
options.modules should be equal to one of the allowed values
80+
options.modules.mode should be equal to one of the allowed values
81+
options.modules should match some schema in anyOf
82+
"
83+
`;
84+
85+
exports[`validate options 9`] = `
86+
"CSS Loader Invalid Options
87+
88+
options.modules should be boolean
89+
options.modules should be string
90+
options.modules should be equal to one of the allowed values
91+
options.modules.mode should be equal to one of the allowed values
92+
options.modules should match some schema in anyOf
93+
"
94+
`;
95+
96+
exports[`validate options 10`] = `
97+
"CSS Loader Invalid Options
98+
99+
options.modules should be boolean
100+
options.modules should be string
101+
options.modules should be equal to one of the allowed values
102+
options.modules.localIdentName should be string
103+
options.modules should match some schema in anyOf
104+
"
105+
`;
106+
107+
exports[`validate options 11`] = `
108+
"CSS Loader Invalid Options
109+
110+
options.modules should be boolean
111+
options.modules should be string
112+
options.modules should be equal to one of the allowed values
113+
options.modules.context should be string
114+
options.modules should match some schema in anyOf
115+
"
116+
`;
117+
118+
exports[`validate options 12`] = `
119+
"CSS Loader Invalid Options
120+
121+
options.modules should be boolean
122+
options.modules should be string
123+
options.modules should be equal to one of the allowed values
124+
options.modules.hashPrefix should be string
125+
options.modules should match some schema in anyOf
126+
"
127+
`;
128+
129+
exports[`validate options 13`] = `
130+
"CSS Loader Invalid Options
131+
132+
options.modules should be boolean
133+
options.modules should be string
134+
options.modules should be equal to one of the allowed values
135+
options.modules.getLocalIdent should be boolean
136+
options.modules.getLocalIdent should pass \\"instanceof\\" keyword validation
137+
options.modules.getLocalIdent should match some schema in anyOf
138+
options.modules should match some schema in anyOf
139+
"
140+
`;
141+
142+
exports[`validate options 14`] = `
143+
"CSS Loader Invalid Options
144+
145+
options.modules should be boolean
146+
options.modules should be string
147+
options.modules should be equal to one of the allowed values
148+
options.modules.localIdentRegExp should be string
149+
options.modules.localIdentRegExp should pass \\"instanceof\\" keyword validation
150+
options.modules.localIdentRegExp should match some schema in anyOf
151+
options.modules should match some schema in anyOf
152+
"
153+
`;
154+
155+
exports[`validate options 15`] = `
156+
"CSS Loader Invalid Options
157+
158+
options.sourceMap should be boolean
159+
"
160+
`;
161+
162+
exports[`validate options 16`] = `
163+
"CSS Loader Invalid Options
164+
165+
options.camelCase should be boolean
166+
options.camelCase should be equal to one of the allowed values
167+
options.camelCase should match some schema in anyOf
168+
"
169+
`;
170+
171+
exports[`validate options 17`] = `
172+
"CSS Loader Invalid Options
173+
174+
options.importLoaders should be boolean
175+
options.importLoaders should be number
176+
options.importLoaders should match some schema in anyOf
177+
"
178+
`;
179+
180+
exports[`validate options 18`] = `
181+
"CSS Loader Invalid Options
182+
183+
options.exportOnlyLocals should be boolean
184+
"
185+
`;

‎test/getLocalIdent-option.test.js

-130
This file was deleted.

‎test/localIdentName-option.test.js

-178
This file was deleted.

‎test/modules-option.test.js

+295-12
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,32 @@ const testCases = fs.readdirSync(testCasesPath);
88

99
describe('modules', () => {
1010
[false, true].forEach((exportOnlyLocalsValue) => {
11-
[true, 'local', 'global', false].forEach((modulesValue) => {
11+
[
12+
true,
13+
false,
14+
'local',
15+
'global',
16+
{ mode: 'local' },
17+
{ mode: 'global' },
18+
].forEach((modulesValue) => {
1219
testCases.forEach((name) => {
1320
it(`case \`${name}\`: (export \`${
1421
exportOnlyLocalsValue ? 'only locals' : 'all'
15-
}\`) (\`modules\` value is \`${modulesValue})\``, async () => {
22+
}\`) (\`modules\` value is \`${
23+
modulesValue.mode
24+
? `object with mode ${modulesValue.mode}`
25+
: modulesValue
26+
})\``, async () => {
1627
const config = {
1728
loader: {
1829
options: {
19-
modules: modulesValue,
30+
modules: modulesValue.mode
31+
? {
32+
mode: modulesValue.mode,
33+
localIdentName: '_[local]',
34+
}
35+
: modulesValue,
2036
exportOnlyLocals: exportOnlyLocalsValue,
21-
localIdentName: '_[local]',
2237
},
2338
},
2439
};
@@ -37,6 +52,271 @@ describe('modules', () => {
3752
});
3853
});
3954

55+
it('should respects localIdentName option', async () => {
56+
const config = {
57+
loader: {
58+
options: {
59+
modules: {
60+
localIdentName: '[name]--[local]--[hash:base64:5]',
61+
context: path.resolve(__dirname),
62+
},
63+
},
64+
},
65+
};
66+
const testId = './modules/localIdentName.css';
67+
const stats = await webpack(testId, config);
68+
const { modules } = stats.toJson();
69+
const module = modules.find((m) => m.id === testId);
70+
const evaluatedModule = evaluated(module.source, modules);
71+
72+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
73+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
74+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
75+
expect(stats.compilation.errors).toMatchSnapshot('errors');
76+
});
77+
78+
it('should respects context option', async () => {
79+
const config = {
80+
loader: {
81+
options: {
82+
modules: {
83+
localIdentName: '[hash:base64:8]',
84+
context: path.resolve(__dirname),
85+
},
86+
},
87+
},
88+
};
89+
const testId = './modules/localIdentName.css';
90+
const stats = await webpack(testId, config);
91+
const { modules } = stats.toJson();
92+
const module = modules.find((m) => m.id === testId);
93+
const evaluatedModule = evaluated(module.source, modules);
94+
95+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
96+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
97+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
98+
expect(stats.compilation.errors).toMatchSnapshot('errors');
99+
});
100+
101+
it('should respects path in localIdentName option', async () => {
102+
const config = {
103+
loader: {
104+
options: {
105+
modules: {
106+
localIdentName: '[path]--[name]--[local]',
107+
context: path.resolve(__dirname),
108+
},
109+
},
110+
},
111+
};
112+
const testId = './modules/localIdentName.css';
113+
const stats = await webpack(testId, config);
114+
const { modules } = stats.toJson();
115+
const module = modules.find((m) => m.id === testId);
116+
const evaluatedModule = evaluated(module.source, modules);
117+
118+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
119+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
120+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
121+
expect(stats.compilation.errors).toMatchSnapshot('errors');
122+
});
123+
124+
it('should respects hashPrefix option with localIdentName option', async () => {
125+
const config = {
126+
loader: {
127+
options: {
128+
modules: {
129+
localIdentName: '[local]--[hash]',
130+
hashPrefix: 'x',
131+
},
132+
},
133+
},
134+
};
135+
const testId = './modules/localIdentName.css';
136+
const stats = await webpack(testId, config);
137+
const { modules } = stats.toJson();
138+
const module = modules.find((m) => m.id === testId);
139+
const evaluatedModule = evaluated(module.source, modules);
140+
141+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
142+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
143+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
144+
expect(stats.compilation.errors).toMatchSnapshot('errors');
145+
});
146+
147+
it('should prefixes leading hyphen + digit with underscore with localIdentName option', async () => {
148+
const config = {
149+
loader: {
150+
options: {
151+
modules: {
152+
localIdentName: '-1[local]',
153+
},
154+
},
155+
},
156+
};
157+
const testId = './modules/localIdentName.css';
158+
const stats = await webpack(testId, config);
159+
const { modules } = stats.toJson();
160+
const module = modules.find((m) => m.id === testId);
161+
const evaluatedModule = evaluated(module.source, modules);
162+
163+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
164+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
165+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
166+
expect(stats.compilation.errors).toMatchSnapshot('errors');
167+
});
168+
169+
it('should prefixes two leading hyphens with underscore with localIdentName option', async () => {
170+
const config = {
171+
loader: {
172+
options: {
173+
modules: {
174+
localIdentName: '--[local]',
175+
},
176+
},
177+
},
178+
};
179+
const testId = './modules/localIdentName.css';
180+
const stats = await webpack(testId, config);
181+
const { modules } = stats.toJson();
182+
const module = modules.find((m) => m.id === testId);
183+
const evaluatedModule = evaluated(module.source, modules);
184+
185+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
186+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
187+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
188+
expect(stats.compilation.errors).toMatchSnapshot('errors');
189+
});
190+
191+
it('should saves underscore prefix in exported class names with localIdentName option', async () => {
192+
const config = {
193+
loader: {
194+
options: {
195+
modules: {
196+
localIdentName: '[local]',
197+
},
198+
},
199+
},
200+
};
201+
const testId = './modules/localIdentName.css';
202+
const stats = await webpack(testId, config);
203+
const { modules } = stats.toJson();
204+
const module = modules.find((m) => m.id === testId);
205+
const evaluatedModule = evaluated(module.source, modules);
206+
207+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
208+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
209+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
210+
expect(stats.compilation.errors).toMatchSnapshot('errors');
211+
});
212+
213+
it('should correctly replace escaped symbols in selector with localIdentName option', async () => {
214+
const config = {
215+
loader: {
216+
options: {
217+
modules: {
218+
localIdentName: '[local]--[hash:base64:4]',
219+
},
220+
importLoaders: 2,
221+
},
222+
},
223+
};
224+
const testId = './modules/localIdentName.css';
225+
const stats = await webpack(testId, config);
226+
const { modules } = stats.toJson();
227+
const module = modules.find((m) => m.id === testId);
228+
const evaluatedModule = evaluated(module.source, modules);
229+
230+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
231+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
232+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
233+
expect(stats.compilation.errors).toMatchSnapshot('errors');
234+
});
235+
236+
it('should respects getLocalIdent option (local mode)', async () => {
237+
const config = {
238+
loader: {
239+
options: {
240+
modules: {
241+
getLocalIdent() {
242+
return 'foo';
243+
},
244+
},
245+
},
246+
},
247+
};
248+
const testId = './modules/getLocalIdent.css';
249+
const stats = await webpack(testId, config);
250+
const { modules } = stats.toJson();
251+
const module = modules.find((m) => m.id === testId);
252+
const evaluatedModule = evaluated(module.source);
253+
254+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
255+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
256+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
257+
expect(stats.compilation.errors).toMatchSnapshot('errors');
258+
});
259+
260+
it('should accepts all arguments for getLocalIdent option', async () => {
261+
const config = {
262+
loader: {
263+
options: {
264+
modules: {
265+
localIdentRegExp: 'regExp',
266+
context: 'context',
267+
hashPrefix: 'hash',
268+
getLocalIdent(loaderContext, localIdentName, localName, options) {
269+
expect(loaderContext).toBeDefined();
270+
expect(typeof localIdentName).toBe('string');
271+
expect(typeof localName).toBe('string');
272+
expect(options).toBeDefined();
273+
274+
expect(options.regExp).toBe('regExp');
275+
expect(options.context).toBe('context');
276+
expect(options.hashPrefix).toBe('hash');
277+
278+
return 'foo';
279+
},
280+
},
281+
},
282+
},
283+
};
284+
const testId = './modules/getLocalIdent.css';
285+
const stats = await webpack(testId, config);
286+
const { modules } = stats.toJson();
287+
const module = modules.find((m) => m.id === testId);
288+
const evaluatedModule = evaluated(module.source);
289+
290+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
291+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
292+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
293+
expect(stats.compilation.errors).toMatchSnapshot('errors');
294+
});
295+
296+
it('should respects getLocalIdent option (global mode)', async () => {
297+
const config = {
298+
loader: {
299+
options: {
300+
modules: {
301+
getLocalIdent() {
302+
return 'foo';
303+
},
304+
},
305+
},
306+
},
307+
};
308+
const testId = './modules/getLocalIdent.css';
309+
const stats = await webpack(testId, config);
310+
const { modules } = stats.toJson();
311+
const module = modules.find((m) => m.id === testId);
312+
const evaluatedModule = evaluated(module.source);
313+
314+
expect(evaluatedModule).toMatchSnapshot('module (evaluated)');
315+
expect(evaluatedModule.locals).toMatchSnapshot('locals');
316+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
317+
expect(stats.compilation.errors).toMatchSnapshot('errors');
318+
});
319+
40320
it('composes should supports resolving', async () => {
41321
const config = {
42322
loader: { options: { import: true, modules: true } },
@@ -60,17 +340,19 @@ describe('modules', () => {
60340
test: /source\.css$/,
61341
options: {
62342
importLoaders: false,
63-
modules: true,
64-
localIdentName: 'b--[local]',
343+
modules: {
344+
localIdentName: 'b--[local]',
345+
},
65346
},
66347
},
67348
additionalLoader: {
68349
test: /dep\.css$/,
69350
loader: path.resolve(__dirname, '../src/index.js'),
70351
options: {
71352
importLoaders: false,
72-
modules: true,
73-
localIdentName: 'a--[local]',
353+
modules: {
354+
localIdentName: 'a--[local]',
355+
},
74356
},
75357
},
76358
};
@@ -92,11 +374,12 @@ describe('modules', () => {
92374
loader: {
93375
test: /\.s[ca]ss$/i,
94376
options: {
95-
modules: true,
377+
modules: {
378+
localIdentName: '[local]',
379+
getLocalIdent: (context, localIdentName, localName) =>
380+
`prefix-${localName}`,
381+
},
96382
importLoaders: 1,
97-
localIdentName: '[local]',
98-
getLocalIdent: (context, localIdentName, localName) =>
99-
`prefix-${localName}`,
100383
},
101384
},
102385
sassLoader: true,

‎test/errors.test.js ‎test/validate-options.test.js

+41-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import loader from '../src/cjs';
22

3-
it('validation', () => {
3+
it('validate options', () => {
44
const validate = (options) =>
55
loader.call(
66
Object.assign(
@@ -34,32 +34,60 @@ it('validation', () => {
3434
expect(() => validate({ modules: false })).not.toThrow();
3535
expect(() => validate({ modules: 'global' })).not.toThrow();
3636
expect(() => validate({ modules: 'local' })).not.toThrow();
37+
expect(() => validate({ modules: { mode: 'local' } })).not.toThrow();
38+
expect(() => validate({ modules: { mode: 'global' } })).not.toThrow();
3739
expect(() => validate({ modules: 'true' })).toThrowErrorMatchingSnapshot();
3840
expect(() => validate({ modules: 'globals' })).toThrowErrorMatchingSnapshot();
3941
expect(() => validate({ modules: 'locals' })).toThrowErrorMatchingSnapshot();
42+
expect(() =>
43+
validate({ modules: { mode: true } })
44+
).toThrowErrorMatchingSnapshot();
45+
expect(() =>
46+
validate({ modules: { mode: 'true' } })
47+
).toThrowErrorMatchingSnapshot();
48+
expect(() =>
49+
validate({ modules: { mode: 'locals' } })
50+
).toThrowErrorMatchingSnapshot();
51+
expect(() =>
52+
validate({ modules: { mode: 'globals' } })
53+
).toThrowErrorMatchingSnapshot();
4054

4155
expect(() =>
42-
validate({ localIdentName: '[path][name]__[local]--[hash:base64:5]' })
56+
validate({
57+
modules: { localIdentName: '[path][name]__[local]--[hash:base64:5]' },
58+
})
4359
).not.toThrow();
4460
expect(() =>
45-
validate({ localIdentName: true })
61+
validate({ modules: { localIdentName: true } })
4662
).toThrowErrorMatchingSnapshot();
4763

48-
expect(() => validate({ localIdentRegExp: 'page-(.*)\\.js' })).not.toThrow();
49-
expect(() => validate({ localIdentRegExp: /page-(.*)\.js/ })).not.toThrow();
64+
expect(() => validate({ modules: { context: 'context' } })).not.toThrow();
5065
expect(() =>
51-
validate({ localIdentRegExp: true })
66+
validate({ modules: { context: true } })
5267
).toThrowErrorMatchingSnapshot();
5368

54-
expect(() => validate({ context: 'context' })).not.toThrow();
55-
expect(() => validate({ context: true })).toThrowErrorMatchingSnapshot();
69+
expect(() => validate({ modules: { hashPrefix: 'hash' } })).not.toThrow();
70+
expect(() =>
71+
validate({ modules: { hashPrefix: true } })
72+
).toThrowErrorMatchingSnapshot();
5673

57-
expect(() => validate({ hashPrefix: 'hash' })).not.toThrow();
58-
expect(() => validate({ hashPrefix: true })).toThrowErrorMatchingSnapshot();
74+
expect(() =>
75+
validate({ modules: { getLocalIdent: () => {} } })
76+
).not.toThrow();
77+
expect(() => validate({ modules: { getLocalIdent: false } })).not.toThrow();
78+
expect(() =>
79+
validate({ modules: { getLocalIdent: [] } })
80+
).toThrowErrorMatchingSnapshot();
5981

60-
expect(() => validate({ getLocalIdent: () => {} })).not.toThrow();
61-
expect(() => validate({ getLocalIdent: false })).not.toThrow();
62-
expect(() => validate({ getLocalIdent: [] })).toThrowErrorMatchingSnapshot();
82+
expect(() =>
83+
validate({ modules: { localIdentRegExp: 'page-(.*)\\.js' } })
84+
).not.toThrow();
85+
expect(() =>
86+
validate({ modules: { localIdentRegExp: /page-(.*)\.js/ } })
87+
).not.toThrow();
88+
expect(() =>
89+
validate({ modules: { localIdentRegExp: true } })
90+
).toThrowErrorMatchingSnapshot();
6391

6492
expect(() => validate({ sourceMap: true })).not.toThrow();
6593
expect(() => validate({ sourceMap: false })).not.toThrow();

0 commit comments

Comments
 (0)
Please sign in to comment.