



























@@ -84,7 +84,17 @@ async function expectOutsideWriteRejected(params: {
8484}) {
8585const patch = buildAddFilePatch(params.patchTargetPath);
8686await expect(applyPatch(patch, { cwd: params.dir })).rejects.toThrow(/Path escapes sandbox root/);
87-await expect(fs.readFile(params.outsidePath, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
87+await expectMissingPath(fs.readFile(params.outsidePath, "utf8"));
88+}
89+90+async function expectMissingPath(operation: Promise<unknown>) {
91+let error: NodeJS.ErrnoException | undefined;
92+try {
93+await operation;
94+} catch (caught) {
95+error = caught as NodeJS.ErrnoException;
96+}
97+expect(error?.code).toBe("ENOENT");
8898}
899990100describe("applyPatch", () => {
@@ -232,7 +242,7 @@ describe("applyPatch", () => {
232242await expect(applyPatch(patch, { cwd: dir })).rejects.toThrow(
233243/Symlink escapes sandbox root/,
234244);
235-await expect(fs.readFile(outsideFile, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
245+await expectMissingPath(fs.readFile(outsideFile, "utf8"));
236246} finally {
237247await fs.rm(outsideDir, { recursive: true, force: true });
238248}
@@ -376,7 +386,7 @@ describe("applyPatch", () => {
376386377387const result = await applyPatch(patch, { cwd: dir });
378388expect(result.summary.deleted).toEqual(["link"]);
379-await expect(fs.lstat(linkDir)).rejects.toMatchObject({ code: "ENOENT" });
389+await expectMissingPath(fs.lstat(linkDir));
380390const outsideContents = await fs.readFile(outsideTarget, "utf8");
381391expect(outsideContents).toBe("keep\n");
382392} finally {
@@ -456,9 +466,7 @@ describe("applyPatch", () => {
456466);
457467},
458468});
459-await expect(fs.stat(path.join(outside, "nested"))).rejects.toMatchObject({
460-code: "ENOENT",
461-});
469+await expectMissingPath(fs.stat(path.join(outside, "nested")));
462470} finally {
463471await fs.rm(outside, { recursive: true, force: true });
464472}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。