Skip to content

Commit

Permalink
Filter out namespaced internal modules
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlau committed Oct 20, 2020
1 parent b3c146e commit d62e42c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -6,11 +6,11 @@ const natives = [].concat(
require('module').builtinModules,
'bootstrap_node',
'node',
).map(n => new RegExp(`(?:\\(${n}\\.js:\\d+:\\d+\\)$|^\\s*at ${n}\\.js:\\d+:\\d+$)`));
).map(n => new RegExp(`(?:\\((?:node:)?${n}(?:\\.js)?:\\d+:\\d+\\)$|^\\s*at (?:node:)?${n}(?:\\.js)?:\\d+:\\d+$)`));

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

Expand Down
42 changes: 42 additions & 0 deletions test/internals.js
@@ -0,0 +1,42 @@
'use strict';

const t = require('tap');
const StackUtils = require('../');

const utils = require('./_utils');

const stackUtils = new StackUtils({ cwd: '/home/user' });

t.test('removes namespaced internal modules', t => {
const stack = utils.join([
'at Test.<anonymous> (test/test.js:99:5)',
'at TapWrap.runInAsyncScope (node:async_hooks:193:9)',
'at Object.<anonymous> (test/test.js:94:3)',
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
'at Module.replacementCompile (node_modules/append-transform/index.js:58:13)',
'at Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
'at Object.<anonymous> (node_modules/append-transform/index.js:62:4)',
'at Module.load (node:internal/modules/cjs/loader:948:32)',
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
'at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
'at Module.load (node:internal/modules/cjs/loader:948:32)',
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
'at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
'at Module.load (node:internal/modules/cjs/loader:948:32)',
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
'at node:internal/main/run_main_module:17:47'
]);
const expectedStack = utils.join([
'Test.<anonymous> (test/test.js:99:5)',
'Object.<anonymous> (test/test.js:94:3)',
'Module.replacementCompile (node_modules/append-transform/index.js:58:13)',
'Object.<anonymous> (node_modules/append-transform/index.js:62:4)',
])
t.plan(1);
t.is(stackUtils.clean(stack), expectedStack);
});

0 comments on commit d62e42c

Please sign in to comment.