Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add test for original issue
  • Loading branch information
alexander-akait committed Jul 14, 2021
commit 33c1ea30042aa8d05874940a46d9243a746bf4ce
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ export default async function loader(content, map, meta) {
const urlPluginImports = [];

if (shouldUseURLPlugin(options)) {
const urlResolver = this.getResolve({
conditionNames: ["asset"],
mainFields: ["asset"],
mainFiles: [],
extensions: [],
});
// const urlResolver = this.getResolve({
// conditionNames: ["asset"],
// mainFields: ["asset"],
// mainFiles: [],
// extensions: [],
// });

plugins.push(
urlParser({
Expand All @@ -100,7 +100,7 @@ export default async function loader(content, map, meta) {
context: this.context,
rootContext: this.rootContext,
filter: getFilter(options.url.filter, this.resourcePath),
resolver: urlResolver,
// resolver: urlResolver,
urlHandler: (url) => stringifyRequest(this, url),
})
);
Expand Down
31 changes: 31 additions & 0 deletions test/__snapshots__/url-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4405,3 +4405,34 @@ Warning
(228:3) Unable to find uri in 'background-image: image-set(url('') 1x)'",
]
`;

exports[`"url" option should work with using 'resolve.extensions': errors 1`] = `Array []`;

exports[`"url" option should work with using 'resolve.extensions': module 1`] = `
"// Imports
import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\";
import ___CSS_LOADER_GET_URL_IMPORT___ from \\"../../../src/runtime/getUrl.js\\";
var ___CSS_LOADER_URL_IMPORT_0___ = new URL(\\"./image\\", import.meta.url);
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]});
var ___CSS_LOADER_URL_REPLACEMENT_0___ = ___CSS_LOADER_GET_URL_IMPORT___(___CSS_LOADER_URL_IMPORT_0___);
// Module
___CSS_LOADER_EXPORT___.push([module.id, \\"div {\\\\n background: url(\\" + ___CSS_LOADER_URL_REPLACEMENT_0___ + \\");\\\\n}\\\\n\\", \\"\\"]);
// Exports
export default ___CSS_LOADER_EXPORT___;
"
`;

exports[`"url" option should work with using 'resolve.extensions': result 1`] = `
Array [
Array [
"./url/resolve-extensions.css",
"div {
background: url(replaced_file_protocol_/webpack/public/path/image.svg);
}
",
"",
],
]
`;

exports[`"url" option should work with using 'resolve.extensions': warnings 1`] = `Array []`;
3 changes: 3 additions & 0 deletions test/fixtures/url/resolve-extensions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
div {
background: url("./image");
}
5 changes: 5 additions & 0 deletions test/fixtures/url/resolve-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import css from './resolve-extensions.css';

__export__ = css;

export default css;
22 changes: 22 additions & 0 deletions test/url-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,26 @@ describe('"url" option', () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should work with using 'resolve.extensions'", async () => {
const compiler = getCompiler(
"./url/resolve-extensions.js",
{},
{
resolve: {
extensions: [".svg", "..."],
},
}
);
const stats = await compile(compiler);

expect(
getModuleSource("./url/resolve-extensions.css", stats)
).toMatchSnapshot("module");
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
"result"
);
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});