From c4f1d7755dc93feeec51d87e2ab013ffc62936ff Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 13 Jun 2018 11:24:16 -0700 Subject: [PATCH] add vfs snapshot capability for future tests --- src/harness/vfs.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/harness/vfs.ts b/src/harness/vfs.ts index 750a990522e..ae99187f5fa 100644 --- a/src/harness/vfs.ts +++ b/src/harness/vfs.ts @@ -126,6 +126,24 @@ namespace vfs { return this._shadowRoot; } + /** + * Snapshots the current file system, effectively shadowing itself. This is useful for + * generating file system patches using `.diff()` from one snapshot to the next. Performs + * no action if this file system is read-only. + */ + public snapshot() { + if (this.isReadonly) return; + const fs = new FileSystem(this.ignoreCase, { time: this._time }); + fs._lazy = this._lazy; + fs._cwd = this._cwd; + fs._time = this._time; + fs._shadowRoot = this._shadowRoot; + fs._dirStack = this._dirStack; + fs.makeReadonly(); + this._lazy = {}; + this._shadowRoot = fs; + } + /** * Gets a shadow copy of this file system. Changes to the shadow copy do not affect the * original, allowing multiple copies of the same core file system without multiple copies