From 3b8ca528eee9b4cb3ff07c79b8c282733ad59c01 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 5 Aug 2021 17:02:11 +0300 Subject: [PATCH] test: resolve.roots --- .../__snapshots__/sources-option.test.js.snap | 28 ++++++++++++++++--- test/fixtures/resolve-roots.html | 1 + test/fixtures/resolve-roots.js | 3 ++ test/sources-option.test.js | 24 +++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/resolve-roots.html create mode 100644 test/fixtures/resolve-roots.js diff --git a/test/__snapshots__/sources-option.test.js.snap b/test/__snapshots__/sources-option.test.js.snap index 3938935f..a93b65d4 100644 --- a/test/__snapshots__/sources-option.test.js.snap +++ b/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); @@ -68,7 +68,7 @@ var code = \\"\\\\n\\\\n

My First Heading

\\\\n

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`] = ` "

My First Heading

@@ -517,7 +517,7 @@ ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 " `; -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 [ @@ -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 = \\"\\\\n\\"; +// Exports +export default code;" +`; + +exports[`'sources' option should work and supports \`resolve.roots\`: result 1`] = ` +" +" +`; + +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`] = ` diff --git a/test/fixtures/resolve-roots.html b/test/fixtures/resolve-roots.html new file mode 100644 index 00000000..e7e3d542 --- /dev/null +++ b/test/fixtures/resolve-roots.html @@ -0,0 +1 @@ + diff --git a/test/fixtures/resolve-roots.js b/test/fixtures/resolve-roots.js new file mode 100644 index 00000000..bdf42095 --- /dev/null +++ b/test/fixtures/resolve-roots.js @@ -0,0 +1,3 @@ +import html from './resolve-roots.html'; + +export default html; diff --git a/test/sources-option.test.js b/test/sources-option.test.js index e70d7f5a..8126c62c 100644 --- a/test/sources-option.test.js +++ b/test/sources-option.test.js @@ -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: [ @@ -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",