Skip to content

Commit

Permalink
add failing test cases for extracting scripts from html entry points
Browse files Browse the repository at this point in the history
fails to extract scripts for html entry points
raises an exception when those scripts are ES modules
pertains to peerigon#79
  • Loading branch information
lmmarsano committed Jun 15, 2020
1 parent 8500840 commit 6205e48
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/extractLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ describe("extractLoader", () => {
/<img src="hi-dist\.jpg">/
);
}));
it("should extract the script.html as file, emit the referenced script and rewrite the url", () =>
compile({testModule: "script.html"}).then(() => {
const scriptHtml = path.resolve(__dirname, "dist/script-dist.html");
const scriptJs = path.resolve(__dirname, "dist/simple-dist.js");

expect(scriptHtml).to.be.a.file();
expect(scriptJs).to.be.a.file();
expect(scriptHtml).to.have.content.that.match(
/<script src="simple-dist\.js">/
);
}));
it("should extract the esm.html as file, emit the referenced es module and rewrite the url", () =>
compile({testModule: "esm.html"}).then(() => {
const esmHtml = path.resolve(__dirname, "dist/esm-dist.html");
const esmJs = path.resolve(__dirname, "dist/esm-dist.js");

expect(esmHtml).to.be.a.file();
expect(esmJs).to.be.a.file();
expect(esmHtml).to.have.content.that.match(
/<script src="esm-dist\.js">/
);
}));
it("should extract the img.css as file, emit the referenced img and rewrite the url", () =>
compile({testModule: "img.css"}).then(() => {
const imgCss = path.resolve(__dirname, "dist/img-dist.css");
Expand Down
10 changes: 10 additions & 0 deletions test/modules/esm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<script src="esm.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions test/modules/esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'btoa'
10 changes: 10 additions & 0 deletions test/modules/script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<script src="simple.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion test/support/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function compile({testModule, publicPath, loaderOptions}) {
{
loader: "html-loader",
options: {
attrs: ["img:src", "link:href"],
attrs: ["img:src", "link:href", "script:src"],
interpolate: true,
},
},
Expand Down

0 comments on commit 6205e48

Please sign in to comment.