MCPcopy Index your code
hub / github.com/nodejs/node / runTest

Function runTest

test/parallel/test-repl-programmatic-history-setup-history.js:194–279  ·  view source on GitHub ↗
(assertCleaned)

Source from the content-addressed store, hash-verified

192const runTestWrap = common.mustCall(runTest, numtests);
193
194function runTest(assertCleaned) {
195 const opts = tests.shift();
196 if (!opts) return; // All done
197
198 if (assertCleaned) {
199 try {
200 assert.strictEqual(fs.readFileSync(defaultHistoryPath, 'utf8'), '');
201 } catch (e) {
202 if (e.code !== 'ENOENT') {
203 console.error(`Failed test # ${numtests - tests.length}`);
204 throw e;
205 }
206 }
207 }
208
209 const test = opts.test;
210 const expected = opts.expected;
211 const clean = opts.clean;
212 const before = opts.before;
213 const size = opts.env.NODE_REPL_HISTORY_SIZE;
214 const filePath = opts.env.NODE_REPL_HISTORY;
215
216 if (before) before();
217
218 const repl = REPL.start({
219 input: new ActionStream(),
220 output: new stream.Writable({
221 write: common.mustCallAtLeast((chunk, _, next) => {
222 const output = chunk.toString();
223
224 // Ignore escapes and blank lines
225 if (output.charCodeAt(0) === 27 || /^[\r\n]+$/.test(output))
226 return next();
227
228 try {
229 assert.strictEqual(output, expected.shift());
230 } catch (err) {
231 console.error(`Failed test # ${numtests - tests.length}`);
232 throw err;
233 }
234 next();
235 }),
236 }),
237 prompt: prompt,
238 useColors: false,
239 terminal: true,
240 });
241
242 repl.setupHistory({
243 size,
244 filePath,
245 onHistoryFileLoaded,
246 removeHistoryDuplicates: false
247 });
248
249 function onHistoryFileLoaded(err, repl) {
250 if (err) {
251 console.error(`Failed test # ${numtests - tests.length}`);

Calls 9

setupHistoryMethod · 0.80
beforeFunction · 0.70
nextFunction · 0.70
shiftMethod · 0.45
readFileSyncMethod · 0.45
errorMethod · 0.45
startMethod · 0.45
toStringMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected