(actual, filename = process.argv[1])
| 155 | } |
| 156 | |
| 157 | async function assertSnapshot(actual, filename = process.argv[1]) { |
| 158 | const snapshot = getSnapshotPath(filename); |
| 159 | if (process.env.NODE_REGENERATE_SNAPSHOTS) { |
| 160 | await fs.writeFile(snapshot, actual); |
| 161 | } else { |
| 162 | let expected; |
| 163 | try { |
| 164 | expected = await fs.readFile(snapshot, 'utf8'); |
| 165 | } catch (e) { |
| 166 | if (e.code === 'ENOENT') { |
| 167 | console.log( |
| 168 | 'Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1', |
| 169 | ); |
| 170 | } |
| 171 | throw e; |
| 172 | } |
| 173 | assert.strictEqual(actual, replaceWindowsLineEndings(expected)); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Spawn a process and assert its output against a snapshot. |
no test coverage detected
searching dependent graphs…