Skip to content

Commit 0cdd520

Browse files
committed
fix: update tests for valid/invalid getJSON values
1 parent 0009dd9 commit 0cdd520

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

src/options.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
"type": "boolean"
172172
},
173173
"getJSON": {
174-
"description": "Output CSS modules mapping through a callback.",
174+
"description": "Allows outputting of CSS modules mapping through a callback.",
175175
"link": "https://github.com/webpack-contrib/css-loader#getJSON",
176176
"instanceof": "Function"
177177
}

src/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,8 @@ function getModulesOptions(rawOptions, exportType, loaderContext) {
593593
? "camelCaseOnly"
594594
: "asIs",
595595
exportOnlyLocals: false,
596+
// eslint-disable-next-line no-undefined
597+
getJSON: undefined,
596598
...rawModulesOptions,
597599
useExportsAs: rawModulesOptions.exportLocalsConvention === "asIs",
598600
};

test/__snapshots__/validate-options.test.js.snap

+29-15
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ exports[`validate options should throw an error on the "importLoaders" option wi
8585
exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = `
8686
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
8787
- options.modules should be one of these:
88-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
88+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
8989
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
9090
-> Read more at https://github.com/webpack-contrib/css-loader#modules
9191
Details:
@@ -109,7 +109,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
109109
exports[`validate options should throw an error on the "modules" option with "{"exportLocalsConvention":"unknown"}" value 1`] = `
110110
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
111111
- options.modules should be one of these:
112-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
112+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
113113
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
114114
-> Read more at https://github.com/webpack-contrib/css-loader#modules
115115
Details:
@@ -130,6 +130,20 @@ exports[`validate options should throw an error on the "modules" option with "{"
130130
-> Read more at https://github.com/webpack-contrib/css-loader#exportonlylocals"
131131
`;
132132

133+
exports[`validate options should throw an error on the "modules" option with "{"getJSON":"invalid"}" value 1`] = `
134+
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
135+
- options.modules.getJSON should be an instance of function.
136+
-> Allows outputting of CSS modules mapping through a callback.
137+
-> Read more at https://github.com/webpack-contrib/css-loader#getJSON"
138+
`;
139+
140+
exports[`validate options should throw an error on the "modules" option with "{"getJSON":true}" value 1`] = `
141+
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
142+
- options.modules.getJSON should be an instance of function.
143+
-> Allows outputting of CSS modules mapping through a callback.
144+
-> Read more at https://github.com/webpack-contrib/css-loader#getJSON"
145+
`;
146+
133147
exports[`validate options should throw an error on the "modules" option with "{"getLocalIdent":[]}" value 1`] = `
134148
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
135149
- options.modules.getLocalIdent should be an instance of function.
@@ -161,7 +175,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
161175
exports[`validate options should throw an error on the "modules" option with "{"localIdentRegExp":true}" value 1`] = `
162176
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
163177
- options.modules should be one of these:
164-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
178+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
165179
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
166180
-> Read more at https://github.com/webpack-contrib/css-loader#modules
167181
Details:
@@ -177,7 +191,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
177191
exports[`validate options should throw an error on the "modules" option with "{"mode":"globals"}" value 1`] = `
178192
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
179193
- options.modules should be one of these:
180-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
194+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
181195
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
182196
-> Read more at https://github.com/webpack-contrib/css-loader#modules
183197
Details:
@@ -194,7 +208,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
194208
exports[`validate options should throw an error on the "modules" option with "{"mode":"locals"}" value 1`] = `
195209
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
196210
- options.modules should be one of these:
197-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
211+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
198212
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
199213
-> Read more at https://github.com/webpack-contrib/css-loader#modules
200214
Details:
@@ -211,7 +225,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
211225
exports[`validate options should throw an error on the "modules" option with "{"mode":"pures"}" value 1`] = `
212226
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
213227
- options.modules should be one of these:
214-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
228+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
215229
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
216230
-> Read more at https://github.com/webpack-contrib/css-loader#modules
217231
Details:
@@ -228,7 +242,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
228242
exports[`validate options should throw an error on the "modules" option with "{"mode":true}" value 1`] = `
229243
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
230244
- options.modules should be one of these:
231-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
245+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
232246
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
233247
-> Read more at https://github.com/webpack-contrib/css-loader#modules
234248
Details:
@@ -252,57 +266,57 @@ exports[`validate options should throw an error on the "modules" option with "{"
252266
exports[`validate options should throw an error on the "modules" option with "globals" value 1`] = `
253267
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
254268
- options.modules should be one of these:
255-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
269+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
256270
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
257271
-> Read more at https://github.com/webpack-contrib/css-loader#modules
258272
Details:
259273
* options.modules should be a boolean.
260274
* options.modules should be one of these:
261275
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\"
262276
* options.modules should be an object:
263-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
277+
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }"
264278
`;
265279

266280
exports[`validate options should throw an error on the "modules" option with "locals" value 1`] = `
267281
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
268282
- options.modules should be one of these:
269-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
283+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
270284
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
271285
-> Read more at https://github.com/webpack-contrib/css-loader#modules
272286
Details:
273287
* options.modules should be a boolean.
274288
* options.modules should be one of these:
275289
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\"
276290
* options.modules should be an object:
277-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
291+
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }"
278292
`;
279293

280294
exports[`validate options should throw an error on the "modules" option with "pures" value 1`] = `
281295
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
282296
- options.modules should be one of these:
283-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
297+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
284298
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
285299
-> Read more at https://github.com/webpack-contrib/css-loader#modules
286300
Details:
287301
* options.modules should be a boolean.
288302
* options.modules should be one of these:
289303
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\"
290304
* options.modules should be an object:
291-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
305+
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }"
292306
`;
293307

294308
exports[`validate options should throw an error on the "modules" option with "true" value 1`] = `
295309
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
296310
- options.modules should be one of these:
297-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
311+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }
298312
-> Allows to enable/disable CSS Modules or ICSS and setup configuration.
299313
-> Read more at https://github.com/webpack-contrib/css-loader#modules
300314
Details:
301315
* options.modules should be a boolean.
302316
* options.modules should be one of these:
303317
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\"
304318
* options.modules should be an object:
305-
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }"
319+
object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, hashStrategy?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals?, getJSON? }"
306320
`;
307321

308322
exports[`validate options should throw an error on the "sourceMap" option with "true" value 1`] = `

test/validate-options.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ describe("validate options", () => {
5353
{ namedExport: false },
5454
{ exportOnlyLocals: true },
5555
{ exportOnlyLocals: false },
56+
{
57+
getJSON: (resourcePath) => resourcePath,
58+
},
5659
],
5760
failure: [
5861
"true",
@@ -73,6 +76,8 @@ describe("validate options", () => {
7376
{ exportLocalsConvention: "unknown" },
7477
{ namedExport: "invalid" },
7578
{ exportOnlyLocals: "invalid" },
79+
{ getJSON: true },
80+
{ getJSON: "invalid" },
7681
],
7782
},
7883
sourceMap: {

0 commit comments

Comments
 (0)