Skip to content

add failing test cases for extracting scripts from html entry points #86

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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