





















@@ -73,6 +73,18 @@ describe("pw-tools-core", () => {
7373}
7474}
757576+function requireSaveAsPath(saveAs: ReturnType<typeof vi.fn>): string {
77+const [call] = saveAs.mock.calls;
78+if (!call) {
79+throw new Error("expected download saveAs call");
80+}
81+const [savedPath] = call;
82+if (typeof savedPath !== "string") {
83+throw new Error("expected download saveAs path");
84+}
85+return savedPath;
86+}
87+7688async function waitForImplicitDownloadOutput(params: {
7789downloadUrl: string;
7890suggestedFilename: string;
@@ -96,10 +108,7 @@ describe("pw-tools-core", () => {
96108});
9710998110const res = await p;
99-const outPath = (vi.mocked(saveAs).mock.calls as unknown as Array<[string]>)[0]?.[0];
100-if (typeof outPath !== "string") {
101-throw new Error("download save path was not captured");
102-}
111+const outPath = requireSaveAsPath(saveAs);
103112return { res, outPath };
104113}
105114@@ -145,18 +154,17 @@ describe("pw-tools-core", () => {
145154targetPath: string;
146155content: string;
147156}) {
148-const savedPath = params.saveAs.mock.calls[0]?.[0];
149-expect(typeof savedPath).toBe("string");
157+const savedPath = requireSaveAsPath(params.saveAs);
150158expect(savedPath).not.toBe(params.targetPath);
151-const savedParentName = path.basename(path.dirname(String(savedPath)));
159+const savedParentName = path.basename(path.dirname(savedPath));
152160expect(
153161savedParentName.includes("fs-safe-output") ||
154162savedParentName === path.basename(path.dirname(params.targetPath)),
155163).toBe(true);
156-expect(path.basename(String(savedPath))).toContain(path.basename(params.targetPath));
157-expect(path.basename(String(savedPath))).toMatch(/\.part$/);
164+expect(path.basename(savedPath)).toContain(path.basename(params.targetPath));
165+expect(path.basename(savedPath)).toMatch(/\.part$/);
158166expect(await fs.readFile(params.targetPath, "utf8")).toBe(params.content);
159-await expectPathMissing(String(savedPath));
167+await expectPathMissing(savedPath);
160168}
161169162170it("waits for the next download and atomically finalizes explicit output paths", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。