(assertCleaned)
| 183 | const runTestWrap = common.mustCall(runTest, numtests); |
| 184 | |
| 185 | function runTest(assertCleaned) { |
| 186 | const opts = tests.shift(); |
| 187 | if (!opts) return; // All done |
| 188 | |
| 189 | if (assertCleaned) { |
| 190 | try { |
| 191 | assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), ''); |
| 192 | } catch (e) { |
| 193 | if (e.code !== 'ENOENT') { |
| 194 | console.error(`Failed test # ${numtests - tests.length}`); |
| 195 | throw e; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | const test = opts.test; |
| 201 | const expected = opts.expected; |
| 202 | const clean = opts.clean; |
| 203 | const before = opts.before; |
| 204 | const historySize = opts.env.NODE_REPL_HISTORY_SIZE; |
| 205 | const file = opts.env.NODE_REPL_HISTORY; |
| 206 | |
| 207 | if (before) before(); |
| 208 | |
| 209 | const repl = REPL.start({ |
| 210 | input: new ActionStream(), |
| 211 | output: new stream.Writable({ |
| 212 | write: common.mustCallAtLeast((chunk, _, next) => { |
| 213 | const output = chunk.toString(); |
| 214 | |
| 215 | // Ignore escapes and blank lines |
| 216 | if (output.charCodeAt(0) === 27 || /^[\r\n]+$/.test(output)) |
| 217 | return next(); |
| 218 | |
| 219 | try { |
| 220 | assert.strictEqual(output, expected.shift()); |
| 221 | } catch (err) { |
| 222 | console.error(`Failed test # ${numtests - tests.length}`); |
| 223 | throw err; |
| 224 | } |
| 225 | next(); |
| 226 | }), |
| 227 | }), |
| 228 | prompt: prompt, |
| 229 | useColors: false, |
| 230 | terminal: true, |
| 231 | historySize |
| 232 | }); |
| 233 | |
| 234 | repl.setupHistory(file, common.mustCall((err, repl) => { |
| 235 | if (err) { |
| 236 | console.error(`Failed test # ${numtests - tests.length}`); |
| 237 | throw err; |
| 238 | } |
| 239 | |
| 240 | repl.once('close', () => { |
| 241 | if (repl.historyManager.isFlushing) { |
| 242 | repl.once('flushHistory', onClose); |
no test coverage detected
searching dependent graphs…