Skip to content

Commit

Permalink
test: resolve.roots (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Aug 5, 2021
1 parent da20c99 commit 3aefedd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
28 changes: 24 additions & 4 deletions test/__snapshots__/sources-option.test.js.snap
@@ -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
@@ -0,0 +1 @@
<img src="/image3.png"/>
3 changes: 3 additions & 0 deletions test/fixtures/resolve-roots.js
@@ -0,0 +1,3 @@
import html from './resolve-roots.html';

export default html;
24 changes: 23 additions & 1 deletion test/sources-option.test.js
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

0 comments on commit 3aefedd

Please sign in to comment.