Skip to content

Commit db9a20b

Browse files
test: added
1 parent 59b4de7 commit db9a20b

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/__snapshots__/url-option.test.js.snap

+27
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,33 @@ Warning
774774
]
775775
`;
776776

777+
exports[`"url" option should work with 'false' aliases when the 'esModule' option is 'false': errors 1`] = `Array []`;
778+
779+
exports[`"url" option should work with 'false' aliases when the 'esModule' option is 'false': module 1`] = `
780+
"// Imports
781+
var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../src/runtime/api.js\\");
782+
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]});
783+
// Module
784+
___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n background-image: url(/logo.png);\\\\n}\\", \\"\\"]);
785+
// Exports
786+
module.exports = ___CSS_LOADER_EXPORT___;
787+
"
788+
`;
789+
790+
exports[`"url" option should work with 'false' aliases when the 'esModule' option is 'false': result 1`] = `
791+
Array [
792+
Array [
793+
"./url/false-alias.css",
794+
".class {
795+
background-image: url(/logo.png);
796+
}",
797+
"",
798+
],
799+
]
800+
`;
801+
802+
exports[`"url" option should work with 'false' aliases when the 'esModule' option is 'false': warnings 1`] = `Array []`;
803+
777804
exports[`"url" option should work with 'false' aliases: errors 1`] = `Array []`;
778805

779806
exports[`"url" option should work with 'false' aliases: module 1`] = `

test/url-option.test.js

+44
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,50 @@ describe('"url" option', () => {
416416
expect(getErrors(stats)).toMatchSnapshot("errors");
417417
});
418418

419+
it("should work with 'false' aliases when the 'esModule' option is 'false'", async () => {
420+
const compiler = getCompiler(
421+
"./url/false-alias.js",
422+
{},
423+
{
424+
module: {
425+
rules: [
426+
{
427+
test: /\.css$/i,
428+
loader: path.resolve(__dirname, "../src"),
429+
options: {
430+
esModule: false,
431+
},
432+
},
433+
{
434+
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/i,
435+
resourceQuery: /^(?!.*\?ignore-asset-modules).*$/,
436+
type: "asset/resource",
437+
},
438+
{
439+
resourceQuery: /\?ignore-asset-modules$/,
440+
type: "javascript/auto",
441+
},
442+
],
443+
},
444+
resolve: {
445+
alias: {
446+
"/logo.png": false,
447+
},
448+
},
449+
}
450+
);
451+
const stats = await compile(compiler);
452+
453+
expect(getModuleSource("./url/false-alias.css", stats)).toMatchSnapshot(
454+
"module"
455+
);
456+
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
457+
"result"
458+
);
459+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
460+
expect(getErrors(stats)).toMatchSnapshot("errors");
461+
});
462+
419463
it("should throw an error on unresolved import", async () => {
420464
const compiler = getCompiler("./url/url-unresolved.js");
421465
const stats = await compile(compiler);

0 commit comments

Comments
 (0)