forked from Anidetrix/rollup-plugin-styles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: relace import-cwd with resolve
- Loading branch information
Showing
10 changed files
with
77 additions
and
72 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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "this is fixture"; |
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,40 +1,57 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import path from "path"; | ||
import loadModule from "../src/utils/load-module"; | ||
import { getInlineMap, getExtractedMap, stripMap, MapModifier } from "../src/utils/sourcemap-utils"; | ||
import path from "path"; | ||
|
||
process.env.STYLES_TEST = "true"; | ||
|
||
test("wrong util path", () => { | ||
const wrong = loadModule("totallyWRONGPATH/here" as any); | ||
expect(wrong).toBeUndefined(); | ||
}); | ||
describe("load-module", () => { | ||
test("wrong path", async () => { | ||
const wrong = await loadModule("totallyWRONGPATH/here"); | ||
expect(wrong).toBeUndefined(); | ||
}); | ||
|
||
test("inline map", () => { | ||
let code = ".foo {color: red;}"; | ||
const wrongMap = getInlineMap(code); | ||
expect(wrongMap).toBeUndefined(); | ||
code += | ||
"/*# sourceMappingURL=data:application/json;base64,e1RISVM6SVNBU09VUkNFTUFQU0lNVUxBVElPTn0= */"; | ||
const correctMap = getInlineMap(code); | ||
expect(correctMap).toBe("{THIS:ISASOURCEMAPSIMULATION}"); | ||
}); | ||
test("correct cwd path", async () => { | ||
const correct = await loadModule("test/fixtures/utils/fixture"); | ||
expect(correct).toBe("this is fixture"); | ||
}); | ||
|
||
test("file map", async () => { | ||
const code = ".foo {color: red;}/*# sourceMappingURL=fixture.css.map */"; | ||
const wrongMap = await getExtractedMap(code, path.resolve("this/is/nonexistant/path.css")); | ||
expect(wrongMap).toBeUndefined(); | ||
const correctMap = await getExtractedMap(code, path.resolve("test/fixtures/utils/pointless.css")); | ||
expect(correctMap).toBe("{THIS:ISASOURCEMAPSIMULATION}"); | ||
test("correct path with custom basepath", async () => { | ||
const correct = await loadModule("fixture", path.join(__dirname, "fixtures", "utils")); | ||
expect(correct).toBe("this is fixture"); | ||
}); | ||
}); | ||
|
||
test("strip map", () => { | ||
const code = ".foo {color: red;}/*# sourceMappingURL=fixture.css.map */"; | ||
expect(stripMap(code)).toBe(".foo {color: red;}"); | ||
}); | ||
describe("sourcemap-utils", () => { | ||
test("inline map", () => { | ||
let code = ".foo {color: red;}"; | ||
const wrongMap = getInlineMap(code); | ||
expect(wrongMap).toBeUndefined(); | ||
code += | ||
"/*# sourceMappingURL=data:application/json;base64,e1RISVM6SVNBU09VUkNFTUFQU0lNVUxBVElPTn0= */"; | ||
const correctMap = getInlineMap(code); | ||
expect(correctMap).toBe("{THIS:ISASOURCEMAPSIMULATION}"); | ||
}); | ||
|
||
test("file map", async () => { | ||
const code = ".foo {color: red;}/*# sourceMappingURL=fixture.css.map */"; | ||
const wrongMap = await getExtractedMap(code, path.resolve("this/is/nonexistant/path.css")); | ||
expect(wrongMap).toBeUndefined(); | ||
const correctMap = await getExtractedMap( | ||
code, | ||
path.resolve("test/fixtures/utils/pointless.css"), | ||
); | ||
expect(correctMap).toBe("{THIS:ISASOURCEMAPSIMULATION}"); | ||
}); | ||
|
||
test("strip map", () => { | ||
const code = ".foo {color: red;}/*# sourceMappingURL=fixture.css.map */"; | ||
expect(stripMap(code)).toBe(".foo {color: red;}"); | ||
}); | ||
|
||
test("map modifier", () => { | ||
const map = JSON.stringify({ sources: ["../a/b/../foo/bar.css", "../b/a/../bar/foo.css"] }); | ||
const relativeSrc = JSON.stringify(new MapModifier(map).relative().toObject().sources); | ||
expect(relativeSrc).toBe(JSON.stringify(["../a/foo/bar.css", "../b/bar/foo.css"])); | ||
test("map modifier", () => { | ||
const map = JSON.stringify({ sources: ["../a/b/../foo/bar.css", "../b/a/../bar/foo.css"] }); | ||
const relativeSrc = JSON.stringify(new MapModifier(map).relative().toObject().sources); | ||
expect(relativeSrc).toBe(JSON.stringify(["../a/foo/bar.css", "../b/bar/foo.css"])); | ||
}); | ||
}); |
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