Skip to content

Commit 3aefedd

Browse files
test: resolve.roots (#396)
1 parent da20c99 commit 3aefedd

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

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

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

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

7474
<h1>My First Heading</h1>
@@ -517,7 +517,7 @@ ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
517517
</div>"
518518
`;
519519

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

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

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

3817+
exports[`'sources' option should work and supports \`resolve.roots\`: errors 1`] = `Array []`;
3818+
3819+
exports[`'sources' option should work and supports \`resolve.roots\`: module 1`] = `
3820+
"// Imports
3821+
import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\";
3822+
var ___HTML_LOADER_IMPORT_0___ = new URL(\\"/image3.png\\", import.meta.url);
3823+
// Module
3824+
var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___);
3825+
var code = \\"<img src=\\\\\\"\\" + ___HTML_LOADER_REPLACEMENT_0___ + \\"\\\\\\"/>\\\\n\\";
3826+
// Exports
3827+
export default code;"
3828+
`;
3829+
3830+
exports[`'sources' option should work and supports \`resolve.roots\`: result 1`] = `
3831+
"<img src=\\"replaced_file_protocol_/webpack/public/path/image3.png\\"/>
3832+
"
3833+
`;
3834+
3835+
exports[`'sources' option should work and supports \`resolve.roots\`: warnings 1`] = `Array []`;
3836+
38173837
exports[`'sources' option should work by default with CommonJS module syntax and ES module syntax from other loader: errors 1`] = `Array []`;
38183838

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

test/fixtures/resolve-roots.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="/image3.png"/>

test/fixtures/resolve-roots.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import html from './resolve-roots.html';
2+
3+
export default html;

test/sources-option.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe("'sources' option", () => {
8585
expect(getErrors(stats)).toMatchSnapshot("errors");
8686
});
8787

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

334+
it("should work and supports `resolve.roots`", async () => {
335+
const compiler = getCompiler(
336+
"resolve-roots.js",
337+
{},
338+
{
339+
resolve: {
340+
roots: [path.resolve(__dirname, "fixtures/nested/")],
341+
},
342+
}
343+
);
344+
const stats = await compile(compiler);
345+
346+
expect(getModuleSource("./resolve-roots.html", stats)).toMatchSnapshot(
347+
"module"
348+
);
349+
expect(
350+
execute(readAsset("main.bundle.js", compiler, stats))
351+
).toMatchSnapshot("result");
352+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
353+
expect(getErrors(stats)).toMatchSnapshot("errors");
354+
});
355+
334356
it("should work by default with CommonJS module syntax", async () => {
335357
const compiler = getCompiler(
336358
"simple.js",

0 commit comments

Comments
 (0)