-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11a7271
commit 70f812a
Showing
6 changed files
with
2,770 additions
and
5,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
const src = require("../dist/cjs/index.js") | ||
import { describe, test, expect } from "vitest" | ||
import { replaceScript } from "../dist/esm/index.js" | ||
|
||
describe("Replace Script", () => { | ||
test("It should inline external scripts and preserve other script attributes", () => { | ||
const outputMod = "<script module>\n\n</script>" | ||
expect(src.replaceScript(`<script module src="./foo.js"></script>`, "foo.js", "")).toEqual(outputMod) | ||
expect(src.replaceScript(`<script src="./foo.js" module></script>`, "foo.js", "")).toEqual(outputMod) | ||
expect(replaceScript(`<script module src="./foo.js"></script>`, "foo.js", "")).toEqual(outputMod) | ||
expect(replaceScript(`<script src="./foo.js" module></script>`, "foo.js", "")).toEqual(outputMod) | ||
const outAsync = "<script async module>\n\n</script>" | ||
expect(src.replaceScript(`<script async src="./foo.js" module></script>`, "foo.js", "")).toEqual(outAsync) | ||
expect(src.replaceScript(`<script src="./foo.js" async module></script>`, "foo.js", "")).toEqual(outAsync) | ||
expect(replaceScript(`<script async src="./foo.js" module></script>`, "foo.js", "")).toEqual(outAsync) | ||
expect(replaceScript(`<script src="./foo.js" async module></script>`, "foo.js", "")).toEqual(outAsync) | ||
const outCrossOrigin = `<script async type="module" crossorigin>\n\n</script>` | ||
expect(src.replaceScript(`<script async type="module" crossorigin src="/assets/foo.js"></script>`, "assets/foo.js", "")).toEqual(outCrossOrigin) | ||
expect(replaceScript(`<script async type="module" crossorigin src="/assets/foo.js"></script>`, "assets/foo.js", "")).toEqual(outCrossOrigin) | ||
const outPolyfill = `<script type="module">\n` | ||
// Removing polyfill without minification | ||
expect(src.replaceScript(`<script type="module" crossorigin>\n(function polyfill() {stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill) | ||
expect(replaceScript(`<script type="module" crossorigin>\n(function polyfill() {stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill) | ||
// Removing polyfill with minification | ||
expect(src.replaceScript(`<script type="module" crossorigin>\n(function(){stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill) | ||
expect(replaceScript(`<script type="module" crossorigin>\n(function(){stuff here\nfoo})();`, "", "", true)).toEqual(outPolyfill) | ||
}) | ||
}) |
Oops, something went wrong.