Skip to content

Commit 3e255df

Browse files
committed
test: remove cjs loader from stack traces
1 parent ec44403 commit 3e255df

File tree

57 files changed

+121
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+121
-277
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { spawnPromisified } from '../common/index.mjs';
2+
import assert from 'node:assert';
3+
import { execPath } from 'node:process';
4+
import { describe, it } from 'node:test';
5+
6+
7+
describe('--trace-uncaught', () => {
8+
it('prints a trace on process exit for uncaught errors', async () => {
9+
const { code, signal, stderr } = await spawnPromisified(execPath, [
10+
'--trace-uncaught',
11+
'--eval',
12+
`throw {
13+
get stack() {
14+
throw new Error('weird throw but ok');
15+
},
16+
get name() {
17+
throw new Error('weird throw but ok');
18+
},
19+
};`,
20+
]);
21+
22+
assert.match(stderr, /Thrown at:/);
23+
assert.match(stderr, / at \[eval\]:1:1/);
24+
assert.strictEqual(code, 1);
25+
assert.strictEqual(signal, null);
26+
});
27+
});

test/errors/throw-null-traced.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { spawnPromisified } from '../common/index.mjs';
2+
import assert from 'node:assert';
3+
import { execPath } from 'node:process';
4+
import { describe, it } from 'node:test';
5+
6+
7+
describe('--trace-uncaught', () => {
8+
it('prints a trace on process exit for uncaught errors', async () => {
9+
const { code, signal, stderr } = await spawnPromisified(execPath, [
10+
'--trace-uncaught',
11+
'--eval',
12+
'throw null;',
13+
]);
14+
15+
assert.match(stderr, /Thrown at:/);
16+
assert.match(stderr, / at \[eval\]:1:1/);
17+
assert.strictEqual(code, 1);
18+
assert.strictEqual(signal, null);
19+
});
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { spawnPromisified } from '../common/index.mjs';
2+
import assert from 'node:assert';
3+
import { execPath } from 'node:process';
4+
import { describe, it } from 'node:test';
5+
6+
7+
describe('--trace-uncaught', () => {
8+
it('prints a trace on process exit for uncaught errors', async () => {
9+
const { code, signal, stderr } = await spawnPromisified(execPath, [
10+
'--trace-uncaught',
11+
'--eval',
12+
'throw undefined;',
13+
]);
14+
15+
assert.match(stderr, /Thrown at:/);
16+
assert.match(stderr, / at \[eval\]:1:1/);
17+
assert.strictEqual(code, 1);
18+
assert.strictEqual(signal, null);
19+
});
20+
});

test/message/core_line_numbers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22
require('../common');
3+
Error.stackTraceLimit = 3;
4+
35
const punycode = require('punycode');
46

57
// This test verifies that line numbers in core modules are reported correctly.

test/message/core_line_numbers.out

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,5 @@ RangeError: Invalid input
66
at error (node:punycode:52:8)
77
at Object.decode (node:punycode:*:*)
88
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
9-
at Module._compile (node:internal/modules/cjs/loader:*:*)
10-
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
11-
at Module.load (node:internal/modules/cjs/loader:*:*)
12-
at Module._load (node:internal/modules/cjs/loader:*:*)
13-
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
14-
at node:internal/main/run_main_module:*:*
159

1610
Node.js *

test/message/error_aggregateTwoErrors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
'use strict';
33

44
require('../common');
5+
Error.stackTraceLimit = 1;
6+
57
const { aggregateTwoErrors } = require('internal/errors');
68

79
const originalError = new Error('original');

test/message/error_aggregateTwoErrors.out

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
11
*error_aggregateTwoErrors.js:*
22
throw aggregateTwoErrors(err, originalError);
33
^
4-
AggregateError: original
5-
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
6-
at Module._compile (node:internal/modules/cjs/loader:*:*)
7-
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
8-
at Module.load (node:internal/modules/cjs/loader:*:*)
9-
at Module._load (node:internal/modules/cjs/loader:*:*)
10-
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
11-
at node:internal/main/run_main_module:*:* {
4+
[AggregateError: original] {
125
code: 'ERR0',
136
[errors]: [
147
Error: original
15-
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
16-
at Module._compile (node:internal/modules/cjs/loader:*:*)
17-
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
18-
at Module.load (node:internal/modules/cjs/loader:*:*)
19-
at Module._load (node:internal/modules/cjs/loader:*:*)
20-
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
21-
at node:internal/main/run_main_module:*:* {
8+
at Object.<anonymous> (/Users/geoffrey/Sites/node/test/message/error_aggregateTwoErrors.js:*:*) {
229
code: 'ERR0'
2310
},
2411
Error: second error
25-
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*)
26-
at Module._compile (node:internal/modules/cjs/loader:*:*)
27-
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
28-
at Module.load (node:internal/modules/cjs/loader:*:*)
29-
at Module._load (node:internal/modules/cjs/loader:*:*)
30-
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
31-
at node:internal/main/run_main_module:*:* {
12+
at Object.<anonymous> (/Users/geoffrey/Sites/node/test/message/error_aggregateTwoErrors.js:*:*) {
3213
code: 'ERR1'
3314
}
3415
]

test/message/error_exit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323
require('../common');
24+
Error.stackTraceLimit = 1;
25+
2426
const assert = require('assert');
2527

2628
process.on('exit', function(code) {

test/message/error_exit.out

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
77

88
1 !== 2
99

10-
at Object.<anonymous> (*test*message*error_exit.js:*:*)
11-
at Module._compile (node:internal/modules/cjs/loader:*:*)
12-
at Module._extensions..js (node:internal/modules/cjs/loader:*:*)
13-
at Module.load (node:internal/modules/cjs/loader:*:*)
14-
at Module._load (node:internal/modules/cjs/loader:*:*)
15-
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:*:*)
16-
at node:internal/main/run_main_module:*:* {
10+
at Object.<anonymous> (*test*message*error_exit.js:*:*) {
1711
generatedMessage: true,
1812
code: 'ERR_ASSERTION',
1913
actual: 1,

test/message/error_with_nul.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
require('../common');
3+
Error.stackTraceLimit = 2;
34

45
function test() {
56
const a = 'abc\0def';

0 commit comments

Comments
 (0)