Skip to content

Commit ae1f3d4

Browse files
committed
Filter out namespaced internal modules
Fixes: tapjs#54 Refs: nodejs/node#35498
1 parent b3c146e commit ae1f3d4

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const natives = [].concat(
66
require('module').builtinModules,
77
'bootstrap_node',
88
'node',
9-
).map(n => new RegExp(`(?:\\(${n}\\.js:\\d+:\\d+\\)$|^\\s*at ${n}\\.js:\\d+:\\d+$)`));
9+
).map(n => new RegExp(`(?:\\((?:node:)?${n}(?:\\.js)?:\\d+:\\d+\\)$|^\\s*at (?:node:)?${n}(?:\\.js)?:\\d+:\\d+$)`));
1010

1111
natives.push(
12-
/\(internal\/[^:]+:\d+:\d+\)$/,
13-
/\s*at internal\/[^:]+:\d+:\d+$/,
12+
/\((?:node:)?internal\/[^:]+:\d+:\d+\)$/,
13+
/\s*at (?:node:)?internal\/[^:]+:\d+:\d+$/,
1414
/\/\.node-spawn-wrap-\w+-\w+\/node:\d+:\d+\)?$/
1515
);
1616

test/internals.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
',use strict';
2+
3+
const t = require('tap');
4+
const StackUtils = require('../');
5+
6+
const utils = require('./_utils');
7+
8+
const stackUtils = new StackUtils({ cwd: '/home/user' });
9+
10+
t.test('removes namespaced internal modules', t => {
11+
const stack = utils.join([
12+
'at Test.<anonymous> (test/test.js:99:5)',
13+
'at TapWrap.runInAsyncScope (node:async_hooks:193:9)',
14+
'at TapWrap.runInAsyncScope (node:async_hooks:193:9)',
15+
'at Object.<anonymous> (test/test.js:94:3)',
16+
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
17+
'at Module.replacementCompile (node_modules/append-transform/index.js:58:13)',
18+
'at Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
19+
'at Object.<anonymous> (node_modules/append-transform/index.js:62:4)',
20+
'at Module.load (node:internal/modules/cjs/loader:948:32)',
21+
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
22+
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
23+
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
24+
'at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
25+
'at Module.load (node:internal/modules/cjs/loader:948:32)',
26+
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
27+
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
28+
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
29+
'at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
30+
'at Module.load (node:internal/modules/cjs/loader:948:32)',
31+
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
32+
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
33+
'at node:internal/main/run_main_module:17:47'
34+
]);
35+
const expectedStack = utils.join([
36+
'Test.<anonymous> (test/test.js:99:5)',
37+
'Object.<anonymous> (test/test.js:94:3)',
38+
'Module.replacementCompile (node_modules/append-transform/index.js:58:13)',
39+
'Object.<anonymous> (node_modules/append-transform/index.js:62:4)',
40+
])
41+
t.plan(1);
42+
t.is(stackUtils.clean(stack), expectedStack);
43+
});

0 commit comments

Comments
 (0)