mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

refactor the test/parallel/test-repl-tab-complete.js file by: - making the tests in the file self-contained (instead of all of them sharing the same REPL instance and constantly calling `.clear` on it) - using the test runner with appropriate descriptions to make clearer what is being tested - extracting some tests in their own js test files (to increase isolation of the tests and help with issues such as flakiness) PR-URL: https://github.com/nodejs/node/pull/58636 Reviewed-By: Giovanni Bucci <github@puskin.it> Reviewed-By: James M Snell <jasnell@gmail.com>
73 lines
1.7 KiB
JavaScript
73 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const ArrayStream = require('../common/arraystream');
|
|
const { hijackStderr, restoreStderr } = require('../common/hijackstdio');
|
|
const assert = require('assert');
|
|
|
|
const repl = require('repl');
|
|
|
|
const input = new ArrayStream();
|
|
const replServer = repl.start({
|
|
prompt: '',
|
|
input,
|
|
output: process.stdout,
|
|
allowBlockingCompletions: true,
|
|
});
|
|
|
|
// Some errors are passed to the domain, but do not callback
|
|
replServer._domain.on('error', assert.ifError);
|
|
|
|
for (const type of [
|
|
Array,
|
|
Buffer,
|
|
|
|
Uint8Array,
|
|
Uint16Array,
|
|
Uint32Array,
|
|
|
|
Uint8ClampedArray,
|
|
Int8Array,
|
|
Int16Array,
|
|
Int32Array,
|
|
Float32Array,
|
|
Float64Array,
|
|
]) {
|
|
input.run(['.clear']);
|
|
|
|
if (type === Array) {
|
|
input.run([
|
|
'var ele = [];',
|
|
'for (let i = 0; i < 1e6 + 1; i++) ele[i] = 0;',
|
|
'ele.biu = 1;',
|
|
]);
|
|
} else if (type === Buffer) {
|
|
input.run(['var ele = Buffer.alloc(1e6 + 1); ele.biu = 1;']);
|
|
} else {
|
|
input.run([`var ele = new ${type.name}(1e6 + 1); ele.biu = 1;`]);
|
|
}
|
|
|
|
hijackStderr(common.mustNotCall());
|
|
replServer.complete(
|
|
'ele.',
|
|
common.mustCall((err, data) => {
|
|
restoreStderr();
|
|
assert.ifError(err);
|
|
|
|
const ele =
|
|
type === Array ? [] : type === Buffer ? Buffer.alloc(0) : new type(0);
|
|
|
|
assert.strictEqual(data[0].includes('ele.biu'), true);
|
|
|
|
data[0].forEach((key) => {
|
|
if (!key || key === 'ele.biu') return;
|
|
assert.notStrictEqual(ele[key.slice(4)], undefined);
|
|
});
|
|
})
|
|
);
|
|
}
|
|
|
|
// check Buffer.prototype.length not crashing.
|
|
// Refs: https://github.com/nodejs/node/pull/11961
|
|
input.run(['.clear']);
|
|
replServer.complete('Buffer.prototype.', common.mustCall());
|