Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d596803
doc: add path rules and validation for export targets in package.json
0hmX Jun 9, 2025
893999e
src: replace V8 Fast API todo comment with note comment
dario-piotrowicz Jun 9, 2025
a4d7560
test: close FileHandle objects in tests explicitly
jasnell Jun 9, 2025
713fbad
test_runner: support object property mocking
idango10 Jun 9, 2025
4347ce3
src: add new CopyUtimes function to reduce code duplication
dario-piotrowicz Jun 9, 2025
dc10238
deps: update zlib to 1.3.1-470d3a2
nodejs-github-bot Jun 10, 2025
80eac14
deps: update simdjson to 3.13.0
nodejs-github-bot Jun 10, 2025
3aa2762
deps: update sqlite to 3.50.1
nodejs-github-bot Jun 10, 2025
181014a
test: cleanup status files
panva Jun 10, 2025
e9c6fa5
src: replace std::array with static arrays in contextify
mertcanaltin Jun 10, 2025
85f062c
test: deflake async-hooks/test-improper-order on AIX
bakigul1 Jun 3, 2025
7e34aa4
test: skip tests failing when run under root
LiviaMedeiros Jun 10, 2025
839964e
fs: allow correct handling of burst in fs-events with AsyncIterator
pipobscure Jun 10, 2025
450f481
deps: update amaro to 1.0.0
nodejs-github-bot Jun 11, 2025
76e3c8a
test: update WPT for es-exceptions to 2f96fa1996
nodejs-github-bot Jun 11, 2025
aa657f0
test: split indirect eval import tests
legendecas Jun 11, 2025
a3c7a63
module: allow cycles in require() in the CJS handling in ESM loader
joyeecheung Jun 11, 2025
9b28f40
module: remove experimental warning from type stripping
marco-ippolito Jun 11, 2025
fa089d6
test: update WPT for dom/abort to dc928169ee
nodejs-github-bot Jun 11, 2025
94e53d4
test: update WPT for urlpattern to 3ffda23e5a
nodejs-github-bot Jun 1, 2025
b1f60d2
http2: add diagnostics channel 'http2.server.stream.close'
RaisinTen Jun 11, 2025
b11da11
http2: fix DEP0194 message
climba03003 Jun 11, 2025
afbaf92
tools: improve release proposal linter
aduh95 Jun 11, 2025
6390f70
lib,src: support DOMException ser-des
legendecas Jun 11, 2025
b6760b3
esm: syncify default path of `ModuleLoader.load`
JakobJingleheimer Jun 11, 2025
ffff8ce
typings: add ZSTD_COMPRESS, ZSTD_DECOMPRESS to internalBinding
nektro Jun 12, 2025
45f7d16
module: refactor commonjs typescript loader
marco-ippolito Jun 12, 2025
ff8a369
module: fix typescript import.meta.main
marco-ippolito Jun 12, 2025
c1f9791
tools: edit commit-queue workflow file
aduh95 Jun 12, 2025
1cc77c7
doc: punctuation fix for Node-API versioning clarification
jiacai2050 Jun 12, 2025
268c8c1
tools: remove config.status under `make distclean`
Renegade334 Jun 12, 2025
b22e970
tools: switch to `@stylistic/eslint-plugin`
targos Jun 13, 2025
ec808b3
test: use `common.skipIfInspectorDisabled()` to skip tests
dario-piotrowicz Jun 13, 2025
dfb0144
src: enhance error messages for unknown options
pmarchini Jun 13, 2025
e6a1787
tools: bump brace-expansion from 1.1.11 to 1.1.12 in /tools/eslint
dependabot[bot] Jun 14, 2025
dc2f23e
tools: bump `brace-expansion` in `/tools/clang-format`
dependabot[bot] Jun 14, 2025
ef0230a
url: add fileURLToPathBuffer API
jasnell Jun 12, 2025
b7e488c
test: refactor repl tab complete tests
dario-piotrowicz Jun 15, 2025
c39d570
test: reduce the use of private symbols in test-events-once.js
kt3k Jun 15, 2025
17df800
typings: add Atomics primordials
Renegade334 Jun 4, 2025
704b1fa
test: add tests for REPL custom evals
dario-piotrowicz Jun 15, 2025
841609a
doc: add islandryu to collaborators
islandryu Jun 16, 2025
8aa0513
2025-06-17, Version 24.3.0 (Current)
nodejs-github-bot Jun 16, 2025
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
test: add tests for REPL custom evals
this commit reintroduces the REPL custom eval tests that have
been introduced in #57691
but reverted in #57793

the tests turned out problematic before because `getReplOutput`,
the function used to return the repl output wasn't taking into
account that input processing and output emitting are asynchronous
operation can resolve with a small delay

the new implementation here replaces `getReplOutput` with
`getReplRunOutput` that resolves repl inputs by running them
and using the repl prompt as an indicator to when the input
processing has completed

PR-URL: #57850
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
dario-piotrowicz authored and targos committed Jun 16, 2025
commit 704b1fa075b645e105976cd94ee5e9eb37528744
1 change: 0 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ function REPLServer(prompt,
options.useColors = shouldColorize(options.output);
}

// TODO(devsnek): Add a test case for custom eval functions.
const preview = options.terminal &&
(options.preview !== undefined ? !!options.preview : !eval_);

Expand Down
101 changes: 101 additions & 0 deletions test/parallel/test-repl-custom-eval-previews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

const common = require('../common');
const ArrayStream = require('../common/arraystream');
const assert = require('assert');
const { describe, it } = require('node:test');

common.skipIfInspectorDisabled();

const repl = require('repl');

const testingReplPrompt = '_REPL_TESTING_PROMPT_>';

// Processes some input in a REPL instance and returns a promise that
// resolves to the produced output (as a string).
function getReplRunOutput(input, replOptions) {
return new Promise((resolve) => {
const inputStream = new ArrayStream();
const outputStream = new ArrayStream();

const replServer = repl.start({
input: inputStream,
output: outputStream,
prompt: testingReplPrompt,
...replOptions,
});

let output = '';

outputStream.write = (chunk) => {
output += chunk;
// The prompt appears after the input has been processed
if (output.includes(testingReplPrompt)) {
replServer.close();
resolve(output);
}
};

inputStream.emit('data', input);

inputStream.run(['']);
});
}

describe('with previews', () => {
it("doesn't show previews by default", async () => {
const input = "'Hello custom' + ' eval World!'";
const output = await getReplRunOutput(
input,
{
terminal: true,
eval: (code, _ctx, _replRes, cb) => cb(null, eval(code)),
},
);
const lines = getSingleCommandLines(output);
assert.match(lines.command, /^'Hello custom' \+ ' eval World!'/);
assert.match(lines.prompt, new RegExp(`${testingReplPrompt}$`));
assert.strictEqual(lines.result, "'Hello custom eval World!'");
assert.strictEqual(lines.preview, undefined);
});

it('does show previews if `preview` is set to `true`', async () => {
const input = "'Hello custom' + ' eval World!'";
const output = await getReplRunOutput(
input,
{
terminal: true,
eval: (code, _ctx, _replRes, cb) => cb(null, eval(code)),
preview: true,
},
);
const lines = getSingleCommandLines(output);
assert.match(lines.command, /^'Hello custom' \+ ' eval World!'/);
assert.match(lines.prompt, new RegExp(`${testingReplPrompt}$`));
assert.strictEqual(lines.result, "'Hello custom eval World!'");
assert.match(lines.preview, /'Hello custom eval World!'/);
});
});

function getSingleCommandLines(output) {
const outputLines = output.split('\n');

// The first line contains the command being run
const command = outputLines.shift();

// The last line contains the prompt (asking for some new input)
const prompt = outputLines.pop();

// The line before the last one contains the result of the command
const result = outputLines.pop();

// The line before that contains the preview of the command
const preview = outputLines.shift();

return {
command,
prompt,
result,
preview,
};
}
121 changes: 121 additions & 0 deletions test/parallel/test-repl-custom-eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
'use strict';

require('../common');
const ArrayStream = require('../common/arraystream');
const assert = require('assert');
const { describe, it } = require('node:test');

const repl = require('repl');

// Processes some input in a REPL instance and returns a promise that
// resolves to the produced output (as a string).
function getReplRunOutput(input, replOptions) {
return new Promise((resolve) => {
const inputStream = new ArrayStream();
const outputStream = new ArrayStream();

const testingReplPrompt = '_REPL_TESTING_PROMPT_>';

const replServer = repl.start({
input: inputStream,
output: outputStream,
prompt: testingReplPrompt,
...replOptions,
});

let output = '';

outputStream.write = (chunk) => {
output += chunk;
// The prompt appears after the input has been processed
if (output.includes(testingReplPrompt)) {
replServer.close();
resolve(output);
}
};

inputStream.emit('data', input);

inputStream.run(['']);
});
}

describe('repl with custom eval', { concurrency: true }, () => {
it('uses the custom eval function as expected', async () => {
const output = await getReplRunOutput('Convert this to upper case', {
terminal: true,
eval: (code, _ctx, _replRes, cb) => cb(null, code.toUpperCase()),
});
assert.match(
output,
/Convert this to upper case\r\n'CONVERT THIS TO UPPER CASE\\n'/
);
});

it('surfaces errors as expected', async () => {
const output = await getReplRunOutput('Convert this to upper case', {
terminal: true,
eval: (_code, _ctx, _replRes, cb) => cb(new Error('Testing Error')),
});
assert.match(output, /Uncaught Error: Testing Error\n/);
});

it('provides a repl context to the eval callback', async () => {
const context = await new Promise((resolve) => {
const r = repl.start({
eval: (_cmd, context) => resolve(context),
});
r.context = { foo: 'bar' };
r.write('\n.exit\n');
});
assert.strictEqual(context.foo, 'bar');
});

it('provides the global context to the eval callback', async () => {
const context = await new Promise((resolve) => {
const r = repl.start({
useGlobal: true,
eval: (_cmd, context) => resolve(context),
});
global.foo = 'global_foo';
r.write('\n.exit\n');
});

assert.strictEqual(context.foo, 'global_foo');
delete global.foo;
});

it('inherits variables from the global context but does not use it afterwords if `useGlobal` is false', async () => {
global.bar = 'global_bar';
const context = await new Promise((resolve) => {
const r = repl.start({
useGlobal: false,
eval: (_cmd, context) => resolve(context),
});
global.baz = 'global_baz';
r.write('\n.exit\n');
});

assert.strictEqual(context.bar, 'global_bar');
assert.notStrictEqual(context.baz, 'global_baz');
delete global.bar;
delete global.baz;
});

/**
* Default preprocessor transforms
* function f() {} to
* var f = function f() {}
* This test ensures that original input is preserved.
* Reference: https://github.com/nodejs/node/issues/9743
*/
it('preserves the original input', async () => {
const cmd = await new Promise((resolve) => {
const r = repl.start({
eval: (cmd) => resolve(cmd),
});
r.write('function f() {}\n.exit\n');
});
assert.strictEqual(cmd, 'function f() {}\n');
});
});
33 changes: 0 additions & 33 deletions test/parallel/test-repl-eval.js

This file was deleted.

Loading