Skip to content

Commit 4b7cabe

Browse files
committed
added a small test
1 parent ecd4cd5 commit 4b7cabe

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { describe, expect, test } from "vitest";
2+
3+
import { patchCode } from "../ast/util";
4+
import { abortControllerRule } from "./next-minimal";
5+
6+
const appPageRuntimeProdJs = `let p = new AbortController;
7+
async function h(e3, t3) {
8+
let { flightRouterState: r3, nextUrl: a2, prefetchKind: i2 } = t3, u2 = { [n2.hY]: "1", [n2.B]: encodeURIComponent(JSON.stringify(r3)) };
9+
i2 === o.ob.AUTO && (u2[n2._V] = "1"), a2 && (u2[n2.kO] = a2);
10+
try {
11+
var c2;
12+
let t4 = i2 ? i2 === o.ob.TEMPORARY ? "high" : "low" : "auto";
13+
"export" === process.env.__NEXT_CONFIG_OUTPUT && ((e3 = new URL(e3)).pathname.endsWith("/") ? e3.pathname += "index.txt" : e3.pathname += ".txt");
14+
let r4 = await m(e3, u2, t4, p.signal), a3 = d(r4.url), h2 = r4.redirected ? a3 : void 0, g = r4.headers.get("content-type") || "", v = !!(null == (c2 = r4.headers.get("vary")) ? void 0 : c2.includes(n2.kO)), b = !!r4.headers.get(n2.jc), S = r4.headers.get(n2.UK), _ = null !== S ? parseInt(S, 10) : -1, w = g.startsWith(n2.al);
15+
if ("export" !== process.env.__NEXT_CONFIG_OUTPUT || w || (w = g.startsWith("text/plain")), !w || !r4.ok || !r4.body)
16+
return e3.hash && (a3.hash = e3.hash), f(a3.toString());
17+
let k = b ? function(e4) {
18+
let t5 = e4.getReader();
19+
return new ReadableStream({ async pull(e5) {
20+
for (; ; ) {
21+
let { done: r5, value: n3 } = await t5.read();
22+
if (!r5) {
23+
e5.enqueue(n3);
24+
continue;
25+
}
26+
return;
27+
}
28+
} });
29+
}(r4.body) : r4.body, E = await y(k);
30+
if ((0, l.X)() !== E.b)
31+
return f(r4.url);
32+
return { flightData: (0, s.aj)(E.f), canonicalUrl: h2, couldBeIntercepted: v, prerendered: E.S, postponed: b, staleTime: _ };
33+
} catch (t4) {
34+
return p.signal.aborted || console.error("Failed to fetch RSC payload for " + e3 + ". Falling back to browser navigation.", t4), { flightData: e3.toString(), canonicalUrl: void 0, couldBeIntercepted: false, prerendered: false, postponed: false, staleTime: -1 };
35+
}
36+
}
37+
`;
38+
39+
describe("Abort controller", () => {
40+
test("minimal", () => {
41+
expect(patchCode(appPageRuntimeProdJs,abortControllerRule )).toBe(
42+
`let p = {signal:{aborted: false}};
43+
async function h(e3, t3) {
44+
let { flightRouterState: r3, nextUrl: a2, prefetchKind: i2 } = t3, u2 = { [n2.hY]: "1", [n2.B]: encodeURIComponent(JSON.stringify(r3)) };
45+
i2 === o.ob.AUTO && (u2[n2._V] = "1"), a2 && (u2[n2.kO] = a2);
46+
try {
47+
var c2;
48+
let t4 = i2 ? i2 === o.ob.TEMPORARY ? "high" : "low" : "auto";
49+
"export" === process.env.__NEXT_CONFIG_OUTPUT && ((e3 = new URL(e3)).pathname.endsWith("/") ? e3.pathname += "index.txt" : e3.pathname += ".txt");
50+
let r4 = await m(e3, u2, t4, p.signal), a3 = d(r4.url), h2 = r4.redirected ? a3 : void 0, g = r4.headers.get("content-type") || "", v = !!(null == (c2 = r4.headers.get("vary")) ? void 0 : c2.includes(n2.kO)), b = !!r4.headers.get(n2.jc), S = r4.headers.get(n2.UK), _ = null !== S ? parseInt(S, 10) : -1, w = g.startsWith(n2.al);
51+
if ("export" !== process.env.__NEXT_CONFIG_OUTPUT || w || (w = g.startsWith("text/plain")), !w || !r4.ok || !r4.body)
52+
return e3.hash && (a3.hash = e3.hash), f(a3.toString());
53+
let k = b ? function(e4) {
54+
let t5 = e4.getReader();
55+
return new ReadableStream({ async pull(e5) {
56+
for (; ; ) {
57+
let { done: r5, value: n3 } = await t5.read();
58+
if (!r5) {
59+
e5.enqueue(n3);
60+
continue;
61+
}
62+
return;
63+
}
64+
} });
65+
}(r4.body) : r4.body, E = await y(k);
66+
if ((0, l.X)() !== E.b)
67+
return f(r4.url);
68+
return { flightData: (0, s.aj)(E.f), canonicalUrl: h2, couldBeIntercepted: v, prerendered: E.S, postponed: b, staleTime: _ };
69+
} catch (t4) {
70+
return p.signal.aborted || console.error("Failed to fetch RSC payload for " + e3 + ". Falling back to browser navigation.", t4), { flightData: e3.toString(), canonicalUrl: void 0, couldBeIntercepted: false, prerendered: false, postponed: false, staleTime: -1 };
71+
}
72+
}
73+
`);
74+
});
75+
})

0 commit comments

Comments
 (0)