mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
fix(javascript): qualify response consumers with uncertain receivers
This commit is contained in:
1 parent
286d599e9f
commit
a8d714f0e3
3 files changed
+35
-4
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
|
||||
|
||||
const consumers = (source: string) =>
|
||||
analyzeJavaScriptSemantics(source).requestOperations.filter(
|
||||
({ kind }) => kind === "response-consumer",
|
||||
);
|
||||
|
||||
it.each([
|
||||
'let response = await fetch("data:text/plain,original"); response = {text: () => "replacement"}; response.text();',
|
||||
'async function load(response) { response.text(); response = await fetch("data:text/plain,original"); }',
|
||||
])(
|
||||
"qualifies a response candidate when its request does not prove the receiver: %s",
|
||||
(source) => {
|
||||
const result = consumers(source);
|
||||
expect(result).toMatchObject([{ endpoint: null, resolution: "partial" }]);
|
||||
expect(result[0]?.linkedRequestIds).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps a response whose request definitely reaches the read complete", () => {
|
||||
expect(
|
||||
consumers(
|
||||
'async function load(response) { response = await fetch("data:text/plain,original"); response.text(); }',
|
||||
),
|
||||
).toMatchObject([
|
||||
{ endpoint: "data:text/plain,original", resolution: "complete" },
|
||||
]);
|
||||
});
|
||||
@@ -443,8 +443,7 @@ const collectResponseConsumers = (
|
||||
.sort(compareUnicodeCodePoints),
|
||||
endpoint: soleWrite ? (uniqueRequest?.operation.endpoint ?? null) : null,
|
||||
fields: [],
|
||||
resolution:
|
||||
uniqueRequest === undefined || otherKinds ? "partial" : "complete",
|
||||
resolution: !soleWrite || otherKinds ? "partial" : "complete",
|
||||
});
|
||||
});
|
||||
return output;
|
||||
|
||||
@@ -29,7 +29,10 @@ it.each([
|
||||
(operation) => operation.kind === "response-consumer",
|
||||
);
|
||||
expect(consumers).toHaveLength(1);
|
||||
expect(consumers[0]).toMatchObject({ endpoint, resolution: "complete" });
|
||||
expect(consumers[0]).toMatchObject({
|
||||
endpoint,
|
||||
resolution: endpoint === null ? "partial" : "complete",
|
||||
});
|
||||
expect(consumers[0]?.linkedRequestIds).toEqual([request?.requestId]);
|
||||
},
|
||||
);
|
||||
@@ -43,7 +46,7 @@ it("does not prove an incoming response was initialized by a conditional request
|
||||
(operation) => operation.kind === "response-consumer",
|
||||
),
|
||||
).toEqual([
|
||||
expect.objectContaining({ endpoint: null, resolution: "complete" }),
|
||||
expect.objectContaining({ endpoint: null, resolution: "partial" }),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user