Skip to content

Commit c4f1d77

Browse files
committed
add vfs snapshot capability for future tests
1 parent e756182 commit c4f1d77

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/harness/vfs.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ namespace vfs {
126126
return this._shadowRoot;
127127
}
128128

129+
/**
130+
* Snapshots the current file system, effectively shadowing itself. This is useful for
131+
* generating file system patches using `.diff()` from one snapshot to the next. Performs
132+
* no action if this file system is read-only.
133+
*/
134+
public snapshot() {
135+
if (this.isReadonly) return;
136+
const fs = new FileSystem(this.ignoreCase, { time: this._time });
137+
fs._lazy = this._lazy;
138+
fs._cwd = this._cwd;
139+
fs._time = this._time;
140+
fs._shadowRoot = this._shadowRoot;
141+
fs._dirStack = this._dirStack;
142+
fs.makeReadonly();
143+
this._lazy = {};
144+
this._shadowRoot = fs;
145+
}
146+
129147
/**
130148
* Gets a shadow copy of this file system. Changes to the shadow copy do not affect the
131149
* original, allowing multiple copies of the same core file system without multiple copies

0 commit comments

Comments
 (0)