Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repl: fixing the test cases
  • Loading branch information
antsmartian committed Nov 27, 2019
commit 57105230df6c76f565977950ce6f97c25569c80c
2 changes: 1 addition & 1 deletion lib/internal/readline/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function appendPreview(result, cursorTo, clearScreenDown) {
this.previewResult = `\u001b[90m // ${result}\u001b[39m`;
const line = `${this._prompt}${this.line} //${result}`;
const columns = this.output.columns;
const hasColors = this.output.hasColors();
const hasColors = this.output.hasColors ? this.output.hasColors() : false;
const s = hasColors ?
`${this._prompt}${this.line}${this.previewResult}` : line;

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-persistent-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const tests = [
env: {},
test: [UP, '\'42\'', ENTER],
expected: [prompt, '\'', '4', '2', '\'',
'> \'42\'\u001b[90m // \'42\'\u001b[39m', '\'42\'\n',
'> \'42\' //\'42\'', '\'42\'\n',
prompt, prompt],
clean: false
},
Expand Down
46 changes: 24 additions & 22 deletions test/parallel/test-repl-preview-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const tests = [
'aObj.a', CLEAR],
expected: [
wrapWithColorCode('aObj',
'{ a: { b: { c: [ {}, \'test\' ] } } }'),
'{ a: { b: { c: [Array] } } }'),
wrapWithColorCode('aObj.a',
'{ b: { c: [ {}, \'test\' ] } }')]
}
Expand All @@ -98,30 +98,32 @@ function runTest() {
const env = opts.env;
const test = opts.test;
const expected = opts.expected;
const ouput = new stream.Writable({
write(chunk, _, next) {
const output = chunk.toString();

// Ignore everything except eval result
if (!output.includes('//')) {
return next();
}

const toBeAsserted = expected[0];
try {
assert.strictEqual(output, toBeAsserted);
expected.shift();
} catch (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}

next();
},
});
ouput.hasColors = () => true;

REPL.createInternalRepl(env, {
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
const output = chunk.toString();

// Ignore everything except eval result
if (!output.includes('//')) {
return next();
}

const toBeAsserted = expected[0];
try {
assert.strictEqual(output, toBeAsserted);
expected.shift();
} catch (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}

next();
}
}),
output: ouput,
prompt: prompt,
useColors: false,
terminal: true
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-programmatic-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const tests = [
env: {},
test: [UP, '\'42\'', ENTER],
expected: [prompt, '\'', '4', '2', '\'',
`${prompt}'42'\u001b[90m // '42'\u001b[39m`,
`${prompt}'42' //'42'`,
'\'42\'\n', prompt, prompt],
clean: false
},
Expand Down