Skip to content

Commit 506b50a

Browse files
BridgeARtargos
authored andcommitted
test: make repl tests more resilient
This refactors two tests to ignore line numbers in stack traces. That way changed line numbers do not have any impact on the test outcome anymore. PR-URL: #28608 Fixes: #28546 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Lance Ball <lball@redhat.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
1 parent af6608c commit 506b50a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

test/parallel/test-repl-pretty-custom-stack.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const repl = require('repl');
77

8+
const stackRegExp = /repl:[0-9]+:[0-9]+/g;
89

910
function run({ command, expected }) {
1011
let accum = '';
@@ -23,7 +24,10 @@ function run({ command, expected }) {
2324
});
2425

2526
r.write(`${command}\n`);
26-
assert.strictEqual(accum, expected);
27+
assert.strictEqual(
28+
accum.replace(stackRegExp, 'repl:*:*'),
29+
expected.replace(stackRegExp, 'repl:*:*')
30+
);
2731
r.close();
2832
}
2933

@@ -44,8 +48,8 @@ const tests = [
4448
{
4549
// test .load for a file that throws
4650
command: `.load ${fixtures.path('repl-pretty-stack.js')}`,
47-
expected: 'Thrown:\nError: Whoops!--->\nrepl:9:24--->\nd (repl:12:3)' +
48-
'--->\nc (repl:9:3)--->\nb (repl:6:3)--->\na (repl:3:3)\n'
51+
expected: 'Thrown:\nError: Whoops!--->\nrepl:*:*--->\nd (repl:*:*)' +
52+
'--->\nc (repl:*:*)--->\nb (repl:*:*)--->\na (repl:*:*)\n'
4953
},
5054
{
5155
command: 'let x y;',
@@ -63,7 +67,7 @@ const tests = [
6367
// test anonymous IIFE
6468
{
6569
command: '(function() { throw new Error(\'Whoops!\'); })()',
66-
expected: 'Thrown:\nError: Whoops!--->\nrepl:1:21\n'
70+
expected: 'Thrown:\nError: Whoops!--->\nrepl:*:*\n'
6771
}
6872
];
6973

test/parallel/test-repl-pretty-stack.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const repl = require('repl');
77

8+
const stackRegExp = /(at .*repl:)[0-9]+:[0-9]+/g;
89

910
function run({ command, expected, ...extraREPLOptions }) {
1011
let accum = '';
@@ -24,17 +25,20 @@ function run({ command, expected, ...extraREPLOptions }) {
2425
});
2526

2627
r.write(`${command}\n`);
27-
assert.strictEqual(accum, expected);
28+
assert.strictEqual(
29+
accum.replace(stackRegExp, '$1*:*'),
30+
expected.replace(stackRegExp, '$1*:*')
31+
);
2832
r.close();
2933
}
3034

3135
const tests = [
3236
{
3337
// Test .load for a file that throws.
3438
command: `.load ${fixtures.path('repl-pretty-stack.js')}`,
35-
expected: 'Thrown:\nError: Whoops!\n at repl:9:24\n' +
36-
' at d (repl:12:3)\n at c (repl:9:3)\n' +
37-
' at b (repl:6:3)\n at a (repl:3:3)\n'
39+
expected: 'Thrown:\nError: Whoops!\n at repl:*:*\n' +
40+
' at d (repl:*:*)\n at c (repl:*:*)\n' +
41+
' at b (repl:*:*)\n at a (repl:*:*)\n'
3842
},
3943
{
4044
command: 'let x y;',
@@ -48,12 +52,12 @@ const tests = [
4852
{
4953
command: '(() => { const err = Error(\'Whoops!\'); ' +
5054
'err.foo = \'bar\'; throw err; })()',
51-
expected: "Thrown:\nError: Whoops!\n at repl:1:22 {\n foo: 'bar'\n}\n",
55+
expected: "Thrown:\nError: Whoops!\n at repl:*:* {\n foo: 'bar'\n}\n",
5256
},
5357
{
5458
command: '(() => { const err = Error(\'Whoops!\'); ' +
5559
'err.foo = \'bar\'; throw err; })()',
56-
expected: 'Thrown:\nError: Whoops!\n at repl:1:22 {\n foo: ' +
60+
expected: 'Thrown:\nError: Whoops!\n at repl:*:* {\n foo: ' +
5761
"\u001b[32m'bar'\u001b[39m\n}\n",
5862
useColors: true
5963
},
@@ -64,7 +68,7 @@ const tests = [
6468
// Test anonymous IIFE.
6569
{
6670
command: '(function() { throw new Error(\'Whoops!\'); })()',
67-
expected: 'Thrown:\nError: Whoops!\n at repl:1:21\n'
71+
expected: 'Thrown:\nError: Whoops!\n at repl:*:*\n'
6872
}
6973
];
7074

0 commit comments

Comments
 (0)