mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 23:36:56 +00:00

Add capabilities to common test module to detect and skip tests on dumb terminals. In some of our build environments, like s390x, the terminal is a dumb terminal meaning it has very rudimentary capabilities. These in turn prevent some of the tests from completing with errors as below. not ok 1777 parallel/test-readline-tab-complete --- duration_ms: 0.365 severity: fail exitcode: 1 stack: |- assert.js:103 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: '\t' !== '' at /home/abuild/rpmbuild/BUILD/node-git.8698dd98bb/test/parallel/test-readline-tab-complete.js:63:14 at Array.forEach (<anonymous>) at /home/abuild/rpmbuild/BUILD/node-git.8698dd98bb/test/parallel/test-readline-tab-complete.js:18:17 at Array.forEach (<anonymous>) at Object.<anonymous> (/home/abuild/rpmbuild/BUILD/node-git.8698dd98bb/test/parallel/test-readline-tab-complete.js:17:3) at Module._compile (internal/modules/cjs/loader.js:1176:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10) at Module.load (internal/modules/cjs/loader.js:1040:32) at Function.Module._load (internal/modules/cjs/loader.js:929:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) { generatedMessage: true, code: 'ERR_ASSERTION', actual: '\t', expected: '', operator: 'strictEqual' } ... PR-URL: https://github.com/nodejs/node/pull/33165 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
const common = require('../common');
|
|
const readline = require('readline');
|
|
const assert = require('assert');
|
|
const EventEmitter = require('events').EventEmitter;
|
|
const { getStringWidth } = require('internal/util/inspect');
|
|
|
|
common.skipIfDumbTerminal();
|
|
|
|
// This test verifies that the tab completion supports unicode and the writes
|
|
// are limited to the minimum.
|
|
[
|
|
'あ',
|
|
'𐐷',
|
|
'🐕'
|
|
].forEach((char) => {
|
|
[true, false].forEach((lineBreak) => {
|
|
const completer = (line) => [
|
|
[
|
|
'First group',
|
|
'',
|
|
`${char}${'a'.repeat(10)}`, `${char}${'b'.repeat(10)}`, char.repeat(11),
|
|
],
|
|
line
|
|
];
|
|
|
|
let output = '';
|
|
const width = getStringWidth(char) - 1;
|
|
|
|
class FakeInput extends EventEmitter {
|
|
columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3
|
|
|
|
write = common.mustCall((data) => {
|
|
output += data;
|
|
}, 6)
|
|
|
|
resume() {}
|
|
pause() {}
|
|
end() {}
|
|
}
|
|
|
|
const fi = new FakeInput();
|
|
const rli = new readline.Interface({
|
|
input: fi,
|
|
output: fi,
|
|
terminal: true,
|
|
completer: completer
|
|
});
|
|
|
|
const last = '\r\nFirst group\r\n\r\n' +
|
|
`${char}${'a'.repeat(10)}${' '.repeat(2 + width * 10)}` +
|
|
`${char}${'b'.repeat(10)}` +
|
|
(lineBreak ? '\r\n' : ' '.repeat(2 + width * 10)) +
|
|
`${char.repeat(11)}\r\n` +
|
|
`\r\n\u001b[1G\u001b[0J> ${char}\u001b[${4 + width}G`;
|
|
|
|
const expectations = [char, '', last];
|
|
|
|
rli.on('line', common.mustNotCall());
|
|
for (const character of `${char}\t\t`) {
|
|
fi.emit('data', character);
|
|
assert.strictEqual(output, expectations.shift());
|
|
output = '';
|
|
}
|
|
rli.close();
|
|
});
|
|
});
|