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

test: resolve.roots #396

Merged
merged 1 commit into from
Aug 5, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 24 additions & 4 deletions test/__snapshots__/sources-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`'sources' option should allow to add more attributes ti default values: errors 1`] = `Array []`;
exports[`'sources' option should allow to add more attributes to default values: errors 1`] = `Array []`;

exports[`'sources' option should allow to add more attributes ti default values: module 1`] = `
exports[`'sources' option should allow to add more attributes to default values: module 1`] = `
"// Imports
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
var ___HTML_LOADER_IMPORT_0___ = new URL(\\"./image.png\\", import.meta.url);
Expand Down Expand Up @@ -68,7 +68,7 @@ var code = \\"<!doctype html>\\\\n\\\\n<h1>My First Heading</h1>\\\\n<p>My first
export default code;"
`;

exports[`'sources' option should allow to add more attributes ti default values: result 1`] = `
exports[`'sources' option should allow to add more attributes to default values: result 1`] = `
"<!doctype html>

<h1>My First Heading</h1>
Expand Down Expand Up @@ -517,7 +517,7 @@ ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
</div>"
`;

exports[`'sources' option should allow to add more attributes ti default values: warnings 1`] = `Array []`;
exports[`'sources' option should allow to add more attributes to default values: warnings 1`] = `Array []`;

exports[`'sources' option should handle "sources" tags: errors 1`] = `
Array [
Expand Down Expand Up @@ -3814,6 +3814,26 @@ ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4

exports[`'sources' option should work and override the "img" tag logic with "...": warnings 1`] = `Array []`;

exports[`'sources' option should work and supports \`resolve.roots\`: errors 1`] = `Array []`;

exports[`'sources' option should work and supports \`resolve.roots\`: module 1`] = `
"// Imports
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
var ___HTML_LOADER_IMPORT_0___ = new URL(\\"/image3.png\\", import.meta.url);
// Module
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
var code = \\"<img src=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"\\\\\\"/>\\\\n\\";
// Exports
export default code;"
`;

exports[`'sources' option should work and supports \`resolve.roots\`: result 1`] = `
"<img src=\\"replaced_file_protocol_/webpack/public/path/image3.png\\"/>
"
`;

exports[`'sources' option should work and supports \`resolve.roots\`: warnings 1`] = `Array []`;

exports[`'sources' option should work by default with CommonJS module syntax and ES module syntax from other loader: errors 1`] = `Array []`;

exports[`'sources' option should work by default with CommonJS module syntax and ES module syntax from other loader: module 1`] = `
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/resolve-roots.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img src="/image3.png"/>
3 changes: 3 additions & 0 deletions test/fixtures/resolve-roots.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import html from './resolve-roots.html';

export default html;
24 changes: 23 additions & 1 deletion test/sources-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("'sources' option", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should allow to add more attributes ti default values", async () => {
it("should allow to add more attributes to default values", async () => {
const compiler = getCompiler("simple.js", {
sources: {
list: [
Expand Down Expand Up @@ -331,6 +331,28 @@ describe("'sources' option", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should work and supports `resolve.roots`", async () => {
const compiler = getCompiler(
"resolve-roots.js",
{},
{
resolve: {
roots: [path.resolve(__dirname, "fixtures/nested/")],
},
}
);
const stats = await compile(compiler);

expect(getModuleSource("./resolve-roots.html", stats)).toMatchSnapshot(
"module"
);
expect(
execute(readAsset("main.bundle.js", compiler, stats))
).toMatchSnapshot("result");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should work by default with CommonJS module syntax", async () => {
const compiler = getCompiler(
"simple.js",
Expand Down