11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Flags: --expose-internals 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciconst stream = require('stream'); 71cb0ef41Sopenharmony_ciconst REPL = require('internal/repl'); 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst fs = require('fs'); 101cb0ef41Sopenharmony_ciconst path = require('path'); 111cb0ef41Sopenharmony_ciconst { inspect } = require('util'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cicommon.skipIfDumbTerminal(); 141cb0ef41Sopenharmony_cicommon.allowGlobals('aaaa'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 171cb0ef41Sopenharmony_citmpdir.refresh(); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history'); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci// Create an input stream specialized for testing an array of actions 221cb0ef41Sopenharmony_ciclass ActionStream extends stream.Stream { 231cb0ef41Sopenharmony_ci run(data) { 241cb0ef41Sopenharmony_ci const _iter = data[Symbol.iterator](); 251cb0ef41Sopenharmony_ci const doAction = () => { 261cb0ef41Sopenharmony_ci const next = _iter.next(); 271cb0ef41Sopenharmony_ci if (next.done) { 281cb0ef41Sopenharmony_ci // Close the repl. Note that it must have a clean prompt to do so. 291cb0ef41Sopenharmony_ci this.emit('keypress', '', { ctrl: true, name: 'd' }); 301cb0ef41Sopenharmony_ci return; 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci const action = next.value; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci if (typeof action === 'object') { 351cb0ef41Sopenharmony_ci this.emit('keypress', '', action); 361cb0ef41Sopenharmony_ci } else { 371cb0ef41Sopenharmony_ci this.emit('data', `${action}`); 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci setImmediate(doAction); 401cb0ef41Sopenharmony_ci }; 411cb0ef41Sopenharmony_ci doAction(); 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci resume() {} 441cb0ef41Sopenharmony_ci pause() {} 451cb0ef41Sopenharmony_ci} 461cb0ef41Sopenharmony_ciActionStream.prototype.readable = true; 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci// Mock keys 491cb0ef41Sopenharmony_ciconst ENTER = { name: 'enter' }; 501cb0ef41Sopenharmony_ciconst UP = { name: 'up' }; 511cb0ef41Sopenharmony_ciconst DOWN = { name: 'down' }; 521cb0ef41Sopenharmony_ciconst BACKSPACE = { name: 'backspace' }; 531cb0ef41Sopenharmony_ciconst SEARCH_BACKWARDS = { name: 'r', ctrl: true }; 541cb0ef41Sopenharmony_ciconst SEARCH_FORWARDS = { name: 's', ctrl: true }; 551cb0ef41Sopenharmony_ciconst ESCAPE = { name: 'escape' }; 561cb0ef41Sopenharmony_ciconst CTRL_C = { name: 'c', ctrl: true }; 571cb0ef41Sopenharmony_ciconst DELETE_WORD_LEFT = { name: 'w', ctrl: true }; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciconst prompt = '> '; 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci// TODO(BridgeAR): Add tests for lines that exceed the maximum columns. 621cb0ef41Sopenharmony_ciconst tests = [ 631cb0ef41Sopenharmony_ci { // Creates few history to navigate for 641cb0ef41Sopenharmony_ci env: { NODE_REPL_HISTORY: defaultHistoryPath }, 651cb0ef41Sopenharmony_ci test: [ 661cb0ef41Sopenharmony_ci 'console.log("foo")', ENTER, 671cb0ef41Sopenharmony_ci 'ab = "aaaa"', ENTER, 681cb0ef41Sopenharmony_ci 'repl.repl.historyIndex', ENTER, 691cb0ef41Sopenharmony_ci 'console.log("foo")', ENTER, 701cb0ef41Sopenharmony_ci 'let ba = 9', ENTER, 711cb0ef41Sopenharmony_ci 'ab = "aaaa"', ENTER, 721cb0ef41Sopenharmony_ci '555 - 909', ENTER, 731cb0ef41Sopenharmony_ci '{key : {key2 :[] }}', ENTER, 741cb0ef41Sopenharmony_ci 'Array(100).fill(1)', ENTER, 751cb0ef41Sopenharmony_ci ], 761cb0ef41Sopenharmony_ci expected: [], 771cb0ef41Sopenharmony_ci clean: false 781cb0ef41Sopenharmony_ci }, 791cb0ef41Sopenharmony_ci { 801cb0ef41Sopenharmony_ci env: { NODE_REPL_HISTORY: defaultHistoryPath }, 811cb0ef41Sopenharmony_ci showEscapeCodes: true, 821cb0ef41Sopenharmony_ci checkTotal: true, 831cb0ef41Sopenharmony_ci useColors: true, 841cb0ef41Sopenharmony_ci test: [ 851cb0ef41Sopenharmony_ci '7', // 1 861cb0ef41Sopenharmony_ci SEARCH_FORWARDS, 871cb0ef41Sopenharmony_ci SEARCH_FORWARDS, // 3 881cb0ef41Sopenharmony_ci 'a', 891cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, // 5 901cb0ef41Sopenharmony_ci SEARCH_FORWARDS, 911cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, // 7 921cb0ef41Sopenharmony_ci 'a', 931cb0ef41Sopenharmony_ci BACKSPACE, // 9 941cb0ef41Sopenharmony_ci DELETE_WORD_LEFT, 951cb0ef41Sopenharmony_ci 'aa', // 11 961cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, 971cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, // 13 981cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, 991cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, // 15 1001cb0ef41Sopenharmony_ci SEARCH_FORWARDS, 1011cb0ef41Sopenharmony_ci ESCAPE, // 17 1021cb0ef41Sopenharmony_ci ENTER, 1031cb0ef41Sopenharmony_ci ], 1041cb0ef41Sopenharmony_ci // A = Cursor n up 1051cb0ef41Sopenharmony_ci // B = Cursor n down 1061cb0ef41Sopenharmony_ci // C = Cursor n forward 1071cb0ef41Sopenharmony_ci // D = Cursor n back 1081cb0ef41Sopenharmony_ci // G = Cursor to column n 1091cb0ef41Sopenharmony_ci // J = Erase in screen; 0 = right; 1 = left; 2 = total 1101cb0ef41Sopenharmony_ci // K = Erase in line; 0 = right; 1 = left; 2 = total 1111cb0ef41Sopenharmony_ci expected: [ 1121cb0ef41Sopenharmony_ci // 0. Start 1131cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 1141cb0ef41Sopenharmony_ci prompt, '\x1B[3G', 1151cb0ef41Sopenharmony_ci // 1. '7' 1161cb0ef41Sopenharmony_ci '7', 1171cb0ef41Sopenharmony_ci // 2. SEARCH FORWARDS 1181cb0ef41Sopenharmony_ci '\nfwd-i-search: _', '\x1B[1A', '\x1B[4G', 1191cb0ef41Sopenharmony_ci // 3. SEARCH FORWARDS 1201cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1211cb0ef41Sopenharmony_ci '7\nfwd-i-search: _', '\x1B[1A', '\x1B[4G', 1221cb0ef41Sopenharmony_ci // 4. 'a' 1231cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1241cb0ef41Sopenharmony_ci '7\nfailed-fwd-i-search: a_', '\x1B[1A', '\x1B[4G', 1251cb0ef41Sopenharmony_ci // 5. SEARCH BACKWARDS 1261cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1271cb0ef41Sopenharmony_ci 'Arr\x1B[4ma\x1B[24my(100).fill(1)\nbck-i-search: a_', 1281cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[6G', 1291cb0ef41Sopenharmony_ci // 6. SEARCH FORWARDS 1301cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1311cb0ef41Sopenharmony_ci '7\nfailed-fwd-i-search: a_', '\x1B[1A', '\x1B[4G', 1321cb0ef41Sopenharmony_ci // 7. SEARCH BACKWARDS 1331cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1341cb0ef41Sopenharmony_ci 'Arr\x1B[4ma\x1B[24my(100).fill(1)\nbck-i-search: a_', 1351cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[6G', 1361cb0ef41Sopenharmony_ci // 8. 'a' 1371cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1381cb0ef41Sopenharmony_ci 'ab = "aa\x1B[4maa\x1B[24m"\nbck-i-search: aa_', 1391cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[11G', 1401cb0ef41Sopenharmony_ci // 9. BACKSPACE 1411cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1421cb0ef41Sopenharmony_ci 'Arr\x1B[4ma\x1B[24my(100).fill(1)\nbck-i-search: a_', 1431cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[6G', 1441cb0ef41Sopenharmony_ci // 10. DELETE WORD LEFT (works as backspace) 1451cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1461cb0ef41Sopenharmony_ci '7\nbck-i-search: _', '\x1B[1A', '\x1B[4G', 1471cb0ef41Sopenharmony_ci // 11. 'a' 1481cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1491cb0ef41Sopenharmony_ci 'Arr\x1B[4ma\x1B[24my(100).fill(1)\nbck-i-search: a_', 1501cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[6G', 1511cb0ef41Sopenharmony_ci // 11. 'aa' - continued 1521cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1531cb0ef41Sopenharmony_ci 'ab = "aa\x1B[4maa\x1B[24m"\nbck-i-search: aa_', 1541cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[11G', 1551cb0ef41Sopenharmony_ci // 12. SEARCH BACKWARDS 1561cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1571cb0ef41Sopenharmony_ci 'ab = "a\x1B[4maa\x1B[24ma"\nbck-i-search: aa_', 1581cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[10G', 1591cb0ef41Sopenharmony_ci // 13. SEARCH BACKWARDS 1601cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1611cb0ef41Sopenharmony_ci 'ab = "\x1B[4maa\x1B[24maa"\nbck-i-search: aa_', 1621cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[9G', 1631cb0ef41Sopenharmony_ci // 14. SEARCH BACKWARDS 1641cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1651cb0ef41Sopenharmony_ci '7\nfailed-bck-i-search: aa_', '\x1B[1A', '\x1B[4G', 1661cb0ef41Sopenharmony_ci // 15. SEARCH BACKWARDS 1671cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1681cb0ef41Sopenharmony_ci '7\nfailed-bck-i-search: aa_', '\x1B[1A', '\x1B[4G', 1691cb0ef41Sopenharmony_ci // 16. SEARCH FORWARDS 1701cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1711cb0ef41Sopenharmony_ci 'ab = "\x1B[4maa\x1B[24maa"\nfwd-i-search: aa_', 1721cb0ef41Sopenharmony_ci '\x1B[1A', '\x1B[9G', 1731cb0ef41Sopenharmony_ci // 17. ESCAPE 1741cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 1751cb0ef41Sopenharmony_ci '7', 1761cb0ef41Sopenharmony_ci // 18. ENTER 1771cb0ef41Sopenharmony_ci '\r\n', 1781cb0ef41Sopenharmony_ci '\x1B[33m7\x1B[39m\n', 1791cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 1801cb0ef41Sopenharmony_ci prompt, 1811cb0ef41Sopenharmony_ci '\x1B[3G', 1821cb0ef41Sopenharmony_ci '\r\n', 1831cb0ef41Sopenharmony_ci ], 1841cb0ef41Sopenharmony_ci clean: false 1851cb0ef41Sopenharmony_ci }, 1861cb0ef41Sopenharmony_ci { 1871cb0ef41Sopenharmony_ci env: { NODE_REPL_HISTORY: defaultHistoryPath }, 1881cb0ef41Sopenharmony_ci showEscapeCodes: true, 1891cb0ef41Sopenharmony_ci skip: !process.features.inspector, 1901cb0ef41Sopenharmony_ci checkTotal: true, 1911cb0ef41Sopenharmony_ci useColors: false, 1921cb0ef41Sopenharmony_ci test: [ 1931cb0ef41Sopenharmony_ci 'fu', // 1 1941cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, 1951cb0ef41Sopenharmony_ci '}', // 3 1961cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, 1971cb0ef41Sopenharmony_ci CTRL_C, // 5 1981cb0ef41Sopenharmony_ci CTRL_C, 1991cb0ef41Sopenharmony_ci '1+1', // 7 2001cb0ef41Sopenharmony_ci ENTER, 2011cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, // 9 2021cb0ef41Sopenharmony_ci '+', 2031cb0ef41Sopenharmony_ci '\r', // 11 2041cb0ef41Sopenharmony_ci '2', 2051cb0ef41Sopenharmony_ci SEARCH_BACKWARDS, // 13 2061cb0ef41Sopenharmony_ci 're', 2071cb0ef41Sopenharmony_ci UP, // 15 2081cb0ef41Sopenharmony_ci DOWN, 2091cb0ef41Sopenharmony_ci SEARCH_FORWARDS, // 17 2101cb0ef41Sopenharmony_ci '\n', 2111cb0ef41Sopenharmony_ci ], 2121cb0ef41Sopenharmony_ci expected: [ 2131cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2141cb0ef41Sopenharmony_ci prompt, '\x1B[3G', 2151cb0ef41Sopenharmony_ci 'f', 'u', '\nbck-i-search: _', '\x1B[1A', '\x1B[5G', 2161cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2171cb0ef41Sopenharmony_ci '{key : {key2 :[] }}\nbck-i-search: }_', '\x1B[1A', '\x1B[21G', 2181cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2191cb0ef41Sopenharmony_ci '{key : {key2 :[] }}\nbck-i-search: }_', '\x1B[1A', '\x1B[20G', 2201cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2211cb0ef41Sopenharmony_ci 'fu', 2221cb0ef41Sopenharmony_ci '\r\n', 2231cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2241cb0ef41Sopenharmony_ci prompt, '\x1B[3G', 2251cb0ef41Sopenharmony_ci '1', '+', '1', '\n// 2', '\x1B[6G', '\x1B[1A', 2261cb0ef41Sopenharmony_ci '\x1B[1B', '\x1B[2K', '\x1B[1A', 2271cb0ef41Sopenharmony_ci '\r\n', 2281cb0ef41Sopenharmony_ci '2\n', 2291cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2301cb0ef41Sopenharmony_ci prompt, '\x1B[3G', 2311cb0ef41Sopenharmony_ci '\nbck-i-search: _', '\x1B[1A', 2321cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2331cb0ef41Sopenharmony_ci '1+1\nbck-i-search: +_', '\x1B[1A', '\x1B[4G', 2341cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2351cb0ef41Sopenharmony_ci '1+1', '\x1B[4G', 2361cb0ef41Sopenharmony_ci '\x1B[2C', 2371cb0ef41Sopenharmony_ci '\r\n', 2381cb0ef41Sopenharmony_ci '2\n', 2391cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2401cb0ef41Sopenharmony_ci prompt, '\x1B[3G', 2411cb0ef41Sopenharmony_ci '2', 2421cb0ef41Sopenharmony_ci '\nbck-i-search: _', '\x1B[1A', '\x1B[4G', 2431cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2441cb0ef41Sopenharmony_ci 'Array(100).fill(1)\nbck-i-search: r_', '\x1B[1A', '\x1B[5G', 2451cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2461cb0ef41Sopenharmony_ci 'repl.repl.historyIndex\nbck-i-search: re_', '\x1B[1A', '\x1B[8G', 2471cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2481cb0ef41Sopenharmony_ci 'repl.repl.historyIndex', '\x1B[8G', 2491cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2501cb0ef41Sopenharmony_ci `${prompt}ab = "aaaa"`, '\x1B[14G', 2511cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2521cb0ef41Sopenharmony_ci `${prompt}repl.repl.historyIndex`, '\x1B[25G', '\n// 8', 2531cb0ef41Sopenharmony_ci '\x1B[25G', '\x1B[1A', 2541cb0ef41Sopenharmony_ci '\x1B[1B', '\x1B[2K', '\x1B[1A', 2551cb0ef41Sopenharmony_ci '\nfwd-i-search: _', '\x1B[1A', '\x1B[25G', 2561cb0ef41Sopenharmony_ci '\x1B[3G', '\x1B[0J', 2571cb0ef41Sopenharmony_ci 'repl.repl.historyIndex', 2581cb0ef41Sopenharmony_ci '\r\n', 2591cb0ef41Sopenharmony_ci '-1\n', 2601cb0ef41Sopenharmony_ci '\x1B[1G', '\x1B[0J', 2611cb0ef41Sopenharmony_ci prompt, '\x1B[3G', 2621cb0ef41Sopenharmony_ci '\r\n', 2631cb0ef41Sopenharmony_ci ], 2641cb0ef41Sopenharmony_ci clean: false 2651cb0ef41Sopenharmony_ci }, 2661cb0ef41Sopenharmony_ci]; 2671cb0ef41Sopenharmony_ciconst numtests = tests.length; 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ciconst runTestWrap = common.mustCall(runTest, numtests); 2701cb0ef41Sopenharmony_ci 2711cb0ef41Sopenharmony_cifunction cleanupTmpFile() { 2721cb0ef41Sopenharmony_ci try { 2731cb0ef41Sopenharmony_ci // Write over the file, clearing any history 2741cb0ef41Sopenharmony_ci fs.writeFileSync(defaultHistoryPath, ''); 2751cb0ef41Sopenharmony_ci } catch (err) { 2761cb0ef41Sopenharmony_ci if (err.code === 'ENOENT') return true; 2771cb0ef41Sopenharmony_ci throw err; 2781cb0ef41Sopenharmony_ci } 2791cb0ef41Sopenharmony_ci return true; 2801cb0ef41Sopenharmony_ci} 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_cifunction runTest() { 2831cb0ef41Sopenharmony_ci const opts = tests.shift(); 2841cb0ef41Sopenharmony_ci if (!opts) return; // All done 2851cb0ef41Sopenharmony_ci 2861cb0ef41Sopenharmony_ci const { expected, skip } = opts; 2871cb0ef41Sopenharmony_ci 2881cb0ef41Sopenharmony_ci // Test unsupported on platform. 2891cb0ef41Sopenharmony_ci if (skip) { 2901cb0ef41Sopenharmony_ci setImmediate(runTestWrap, true); 2911cb0ef41Sopenharmony_ci return; 2921cb0ef41Sopenharmony_ci } 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_ci const lastChunks = []; 2951cb0ef41Sopenharmony_ci let i = 0; 2961cb0ef41Sopenharmony_ci 2971cb0ef41Sopenharmony_ci REPL.createInternalRepl(opts.env, { 2981cb0ef41Sopenharmony_ci input: new ActionStream(), 2991cb0ef41Sopenharmony_ci output: new stream.Writable({ 3001cb0ef41Sopenharmony_ci write(chunk, _, next) { 3011cb0ef41Sopenharmony_ci const output = chunk.toString(); 3021cb0ef41Sopenharmony_ci 3031cb0ef41Sopenharmony_ci if (!opts.showEscapeCodes && 3041cb0ef41Sopenharmony_ci (output[0] === '\x1B' || /^[\r\n]+$/.test(output))) { 3051cb0ef41Sopenharmony_ci return next(); 3061cb0ef41Sopenharmony_ci } 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci lastChunks.push(output); 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ci if (expected.length && !opts.checkTotal) { 3111cb0ef41Sopenharmony_ci try { 3121cb0ef41Sopenharmony_ci assert.strictEqual(output, expected[i]); 3131cb0ef41Sopenharmony_ci } catch (e) { 3141cb0ef41Sopenharmony_ci console.error(`Failed test # ${numtests - tests.length}`); 3151cb0ef41Sopenharmony_ci console.error('Last outputs: ' + inspect(lastChunks, { 3161cb0ef41Sopenharmony_ci breakLength: 5, colors: true 3171cb0ef41Sopenharmony_ci })); 3181cb0ef41Sopenharmony_ci throw e; 3191cb0ef41Sopenharmony_ci } 3201cb0ef41Sopenharmony_ci i++; 3211cb0ef41Sopenharmony_ci } 3221cb0ef41Sopenharmony_ci 3231cb0ef41Sopenharmony_ci next(); 3241cb0ef41Sopenharmony_ci } 3251cb0ef41Sopenharmony_ci }), 3261cb0ef41Sopenharmony_ci completer: opts.completer, 3271cb0ef41Sopenharmony_ci prompt, 3281cb0ef41Sopenharmony_ci useColors: opts.useColors || false, 3291cb0ef41Sopenharmony_ci terminal: true 3301cb0ef41Sopenharmony_ci }, function(err, repl) { 3311cb0ef41Sopenharmony_ci if (err) { 3321cb0ef41Sopenharmony_ci console.error(`Failed test # ${numtests - tests.length}`); 3331cb0ef41Sopenharmony_ci throw err; 3341cb0ef41Sopenharmony_ci } 3351cb0ef41Sopenharmony_ci 3361cb0ef41Sopenharmony_ci repl.once('close', () => { 3371cb0ef41Sopenharmony_ci if (opts.clean) 3381cb0ef41Sopenharmony_ci cleanupTmpFile(); 3391cb0ef41Sopenharmony_ci 3401cb0ef41Sopenharmony_ci if (opts.checkTotal) { 3411cb0ef41Sopenharmony_ci assert.deepStrictEqual(lastChunks, expected); 3421cb0ef41Sopenharmony_ci } else if (expected.length !== i) { 3431cb0ef41Sopenharmony_ci console.error(tests[numtests - tests.length - 1]); 3441cb0ef41Sopenharmony_ci throw new Error(`Failed test # ${numtests - tests.length}`); 3451cb0ef41Sopenharmony_ci } 3461cb0ef41Sopenharmony_ci 3471cb0ef41Sopenharmony_ci setImmediate(runTestWrap, true); 3481cb0ef41Sopenharmony_ci }); 3491cb0ef41Sopenharmony_ci 3501cb0ef41Sopenharmony_ci if (opts.columns) { 3511cb0ef41Sopenharmony_ci Object.defineProperty(repl, 'columns', { 3521cb0ef41Sopenharmony_ci value: opts.columns, 3531cb0ef41Sopenharmony_ci enumerable: true 3541cb0ef41Sopenharmony_ci }); 3551cb0ef41Sopenharmony_ci } 3561cb0ef41Sopenharmony_ci repl.inputStream.run(opts.test); 3571cb0ef41Sopenharmony_ci }); 3581cb0ef41Sopenharmony_ci} 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci// run the tests 3611cb0ef41Sopenharmony_cirunTest(); 362