Skip to content

Commit

Permalink
feature(supertape) add support of mock-import
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Sep 14, 2021
1 parent c4abbd0 commit 2988217
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/supertape/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const REASON_USER = 3;
const REASON_EXCEPTION = 1;

module.exports.parseAt = (stack, {reason}) => {
const lines = stack.split('\n');
const lines = cutMockImport(stack).split('\n');

if (lines.length === 1)
return stack;
Expand All @@ -24,3 +24,7 @@ module.exports.formatOutput = (str) => {
.join('\n');
};

function cutMockImport(str) {
return str.replace(/\?mock-import-count=\d+/g, '');
}

16 changes: 16 additions & 0 deletions packages/supertape/lib/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ test('supertape: format: reason: exception', (t) => {
t.end();
});

test('supertape: format: mock-import: ', (t) => {
const stack = `
at file:///Users/coderaiser/estrace/lib/estrace.spec.js?mock-import-count=55:57:11
at async module.exports (/Users/coderaiser/estrace/node_modules/try-to-catch/lib/try-to-catch.js:7:23)
at async runOneTest (/Users/coderaiser/estrace/node_modules/supertape/lib/run-tests.js:143:21)
at async runTests (/Users/coderaiser/estrace/node_modules/supertape/lib/run-tests.js:92:9)
at async module.exports (/Users/coderaiser/estrace/node_modules/supertape/lib/run-tests.js:55:12)
at async EventEmitter.<anonymous> (/Users/coderaiser/estrace/node_modules/supertape/lib/supertape.js:69:26)
`;

const result = parseAt(stack, {reason: 'exception'});
const expected = 'at: file:///Users/coderaiser/estrace/lib/estrace.spec.js:57:11';

t.equal(result, expected);
t.end();
});

0 comments on commit 2988217

Please sign in to comment.