Skip to content

Commit 81d063c

Browse files
Trottgibfahn
authored andcommitted
test: refactor test-repl-definecommand
The test was writing to both REPL input and output but only checking output. Sending output to both streams seems like it was an error. PR-URL: #17795 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 69944e3 commit 81d063c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/parallel/test-repl-definecommand.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ r.defineCommand('say1', {
2323
help: 'help for say1',
2424
action: function(thing) {
2525
output = '';
26-
this.write(`hello ${thing}`);
26+
this.output.write(`hello ${thing}\n`);
2727
this.displayPrompt();
2828
}
2929
});
3030

3131
r.defineCommand('say2', function() {
3232
output = '';
33-
this.write('hello from say2');
33+
this.output.write('hello from say2\n');
3434
this.displayPrompt();
3535
});
3636

@@ -39,6 +39,12 @@ assert(/\n\.say1 help for say1\n/.test(output),
3939
'help for say1 not present');
4040
assert(/\n\.say2\n/.test(output), 'help for say2 not present');
4141
inputStream.write('.say1 node developer\n');
42-
assert(/> hello node developer/.test(output), 'say1 outputted incorrectly');
42+
assert.ok(output.startsWith('hello node developer\n'),
43+
`say1 output starts incorrectly: "${output}"`);
44+
assert.ok(output.includes('> '),
45+
`say1 output does not include prompt: "${output}"`);
4346
inputStream.write('.say2 node developer\n');
44-
assert(/> hello from say2/.test(output), 'say2 outputted incorrectly');
47+
assert.ok(output.startsWith('hello from say2\n'),
48+
`say2 output starts incorrectly: "${output}"`);
49+
assert.ok(output.includes('> '),
50+
`say2 output does not include prompt: "${output}"`);

0 commit comments

Comments
 (0)