Skip to content

Commit 09b2cad

Browse files
committed
feat: add export and restore
1 parent 65729c3 commit 09b2cad

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/fixtures/file-system.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ export class FileSystem {
6767
async rm(path: string) {
6868
return this._instance.fs.rm(path);
6969
}
70+
71+
async export(path = "./", options = { excludes: [], includes: [] }) {
72+
return await this._instance.export(path, { ...options, format: "binary" });
73+
}
74+
75+
async restore(snapshot: Uint8Array) {
76+
return await this._instance.mount(snapshot);
77+
}
7078
}

test/file-system.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ test("user can remove files from webcontainer", async ({ webcontainer }) => {
4040
"third",
4141
]);
4242
});
43+
44+
test("user can export and restore snapshots", async ({ webcontainer }) => {
45+
await webcontainer.writeFile("/first", "1");
46+
await webcontainer.writeFile("/second", "2");
47+
48+
const snapshot = await webcontainer.export();
49+
50+
await webcontainer.rm("/second");
51+
await expect(webcontainer.readdir("/")).resolves.toStrictEqual(["first"]);
52+
53+
await webcontainer.restore(snapshot);
54+
await expect(webcontainer.readdir("/")).resolves.toStrictEqual([
55+
"first",
56+
"second",
57+
]);
58+
});

0 commit comments

Comments
 (0)