Skip to content

Commit

Permalink
Fix reading source file multiple times (#2569)
Browse files Browse the repository at this point in the history
* Deduplicate filenames passed to addPrePostContext.

* Fix build.
  • Loading branch information
pushplay committed May 11, 2020
1 parent 4bc58c1 commit 0dd8962
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/node/src/parsers.ts
Expand Up @@ -163,7 +163,7 @@ export function parseStack(stack: stacktrace.StackFrame[], options?: NodeOptions
if (parsedFrame.filename) {
parsedFrame.module = getModule(parsedFrame.filename);

if (!isInternal && linesOfContext > 0) {
if (!isInternal && linesOfContext > 0 && filesToRead.indexOf(parsedFrame.filename) === -1) {
filesToRead.push(parsedFrame.filename);
}
}
Expand Down
36 changes: 36 additions & 0 deletions packages/node/test/parsers.test.ts
Expand Up @@ -71,6 +71,42 @@ describe('parsers.ts', () => {
});
});

test('parseStack with duplicate files', async () => {
expect.assertions(1);
const framesWithDuplicateFiles: stacktrace.StackFrame[] = [
{
columnNumber: 1,
fileName: '/var/task/index.js',
functionName: 'module.exports../src/index.ts.fxn1',
lineNumber: 1,
methodName: 'fxn1',
native: false,
typeName: 'module.exports../src/index.ts',
},
{
columnNumber: 2,
fileName: '/var/task/index.js',
functionName: 'module.exports../src/index.ts.fxn2',
lineNumber: 2,
methodName: 'fxn2',
native: false,
typeName: 'module.exports../src/index.ts',
},
{
columnNumber: 3,
fileName: '/var/task/index.js',
functionName: 'module.exports../src/index.ts.fxn3',
lineNumber: 3,
methodName: 'fxn3',
native: false,
typeName: 'module.exports../src/index.ts',
},
];
return Parsers.parseStack(framesWithDuplicateFiles).then(_ => {
expect(spy).toHaveBeenCalledTimes(1);
});
});

test('parseStack with no context', async () => {
expect.assertions(1);
return Parsers.parseStack(frames, { frameContextLines: 0 }).then(_ => {
Expand Down

0 comments on commit 0dd8962

Please sign in to comment.