()
| 88 | } |
| 89 | |
| 90 | readFile() { |
| 91 | if (this.loaded) { |
| 92 | debug('skipping read of snapshot file'); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | try { |
| 97 | const source = readFileSync(this.snapshotFile, 'utf8'); |
| 98 | const context = { __proto__: null, exports: { __proto__: null } }; |
| 99 | |
| 100 | createContext(context); |
| 101 | runInContext(source, context); |
| 102 | |
| 103 | if (context.exports === null || typeof context.exports !== 'object') { |
| 104 | throw new ERR_INVALID_STATE( |
| 105 | `Malformed snapshot file '${this.snapshotFile}'.`, |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | for (const key in context.exports) { |
| 110 | this.snapshots[key] = templateEscape(context.exports[key]); |
| 111 | } |
| 112 | this.loaded = true; |
| 113 | } catch (err) { |
| 114 | throwReadError(err, this.snapshotFile); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | writeFile() { |
| 119 | try { |
no test coverage detected