mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
test(javascript): consolidate artifact graph and resolution coverage
This commit is contained in:
1 parent
b2af0d77e0
commit
1ff7be8c70
22 files changed
+595
-1590
No files matched your search
@@ -35,22 +35,16 @@ const resolve = (declaredPath: string, htmlBaseHref: string) =>
|
||||
files,
|
||||
jsonDocuments,
|
||||
});
|
||||
const documentUrl = "https://artifact.test/renderer/index.html";
|
||||
describe("HTML base href URL components", () => {
|
||||
it.each(["?base=1", "#base-fragment"])(
|
||||
"keeps the document pathname for suffix-only base href %s",
|
||||
(base) => {
|
||||
const resolvedBase = new URL(base, documentUrl);
|
||||
expect(new URL("app.js", resolvedBase).pathname).toBe("/renderer/app.js");
|
||||
expect(resolve("app.js", base)).toMatchObject({
|
||||
resolved_path: "renderer/app.js",
|
||||
resolution_status: "resolved",
|
||||
});
|
||||
|
||||
const emptyPathReference = "?script=1#fragment";
|
||||
expect(new URL(emptyPathReference, resolvedBase).pathname).toBe(
|
||||
"/renderer/index.html",
|
||||
);
|
||||
expect(resolve(emptyPathReference, base)).toMatchObject({
|
||||
declared_path: emptyPathReference,
|
||||
resolved_path: "renderer/index.html",
|
||||
@@ -64,12 +58,6 @@ describe("HTML base href URL components", () => {
|
||||
"/assets/#/wrong/",
|
||||
"/assets/index.html?cache=/wrong/",
|
||||
])("ignores query and fragment path-looking characters in %s", (base) => {
|
||||
expect(
|
||||
new URL(
|
||||
"app.js",
|
||||
new URL(base, "https://artifact.test/renderer/index.html"),
|
||||
).pathname,
|
||||
).toBe("/assets/app.js");
|
||||
expect(resolve("app.js", base)).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "assets/app.js",
|
||||
@@ -93,15 +81,8 @@ describe("HTML base href dot segments", () => {
|
||||
["a/..", "renderer/app.js"],
|
||||
["..", "app.js"],
|
||||
])(
|
||||
"resolves %s against the document directory like the URL parser",
|
||||
"resolves %s against the document directory",
|
||||
(base, expected) => {
|
||||
// A relative reference resolves against the base URL's directory, which
|
||||
// drops a trailing "." or ".." segment instead of stepping through it.
|
||||
expect(
|
||||
decodeURIComponent(
|
||||
new URL("app.js", new URL(base, documentUrl)).pathname,
|
||||
).replace(/^\/+/, ""),
|
||||
).toBe(expected);
|
||||
expect(resolve("app.js", base)).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: expected,
|
||||
@@ -128,10 +109,6 @@ describe("HTML base href dot segments", () => {
|
||||
});
|
||||
describe("HTML base href empty segments", () => {
|
||||
it("lets the script reference remove an empty segment from the base", () => {
|
||||
// URL resolution keeps the base's empty segment until `..` removes it.
|
||||
expect(
|
||||
new URL("../app.js", new URL("./assets//", documentUrl)).pathname,
|
||||
).toBe("/renderer/assets/app.js");
|
||||
expect(resolve("../app.js", "./assets//")).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "renderer/assets/app.js",
|
||||
@@ -169,10 +146,6 @@ describe("HTML base href path syntax", () => {
|
||||
});
|
||||
});
|
||||
describe("HTML reference URL text", () => {
|
||||
const urlPath = (declared: string, base: string) =>
|
||||
decodeURIComponent(
|
||||
new URL(declared.trim(), new URL(base.trim(), documentUrl)).pathname,
|
||||
).replace(/^\/+/, "");
|
||||
it.each([
|
||||
["%61pp.js", "/assets/", "assets/app.js"],
|
||||
[" app.js ", "/assets/", "assets/app.js"],
|
||||
@@ -182,9 +155,8 @@ describe("HTML reference URL text", () => {
|
||||
["app.js", " /%61ssets/ ", "assets/app.js"],
|
||||
["/%61ssets/app.js", "", "assets/app.js"],
|
||||
])(
|
||||
"resolves %j against base %j like the URL parser",
|
||||
"resolves %j against base %j",
|
||||
(declared, base, expected) => {
|
||||
if (base !== "") expect(urlPath(declared, base)).toBe(expected);
|
||||
expect(resolve(declared, base)).toMatchObject({
|
||||
declared_path: declared,
|
||||
resolution_status: "resolved",
|
||||
@@ -229,7 +201,7 @@ describe("HTML reference URL text", () => {
|
||||
});
|
||||
},
|
||||
);
|
||||
it.each(["%2e%2e/app.js", "a%2fapp.js", "%2\nfapp.js", "%2\ne%2\te/app.js"])(
|
||||
it.each(["%2e%2e/app.js", "a%2fapp.js", "%2\ne%2\te/app.js"])(
|
||||
"still rejects encoded dot and separator bytes in %j",
|
||||
(declared) => {
|
||||
expect(resolve(declared, "")).toMatchObject({
|
||||
|
||||
Reference in new issue
Block a user