Skip to content

Commit

Permalink
Test: Fix TapReporter test to cover and use corrent 'internal' stack …
Browse files Browse the repository at this point in the history
…example

This was still an example of internal stacks as used by Node 12-14.
That's insignificant for the most part, except for the greying feature
recently added. By updating these fixtures, we'll improve test coverage.
  • Loading branch information
Krinkle committed Jan 18, 2025
1 parent 9d4afff commit 280e721
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/core/stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const fileName = qunitFileName();
* - For errors in Node.js, format any remaining qunit.js and node:internal
* frames as internal (i.e. grey out).
*
* @param {string} Error#stack
* @param {string} stack Error#stack
* @param {Function} formatInternal Format a string in an "internal" color
* @param {string|null} [eToString] Error#toString() to help remove
* noise from Node.js/V8 stack traces.
Expand All @@ -83,6 +83,8 @@ export function annotateStacktrace (stack, formatInternal, eToString = null) {
let initialInternal = true;
for (let i = 0; i < frames.length; i++) {
const frame = frames[i];
// Example of internal stack trace (Node 16+)
// "at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)"
const isInternal = ((fileName && frame.indexOf(fileName) !== -1) || frame.indexOf('node:internal/') !== -1);
if (!isInternal) {
initialInternal = false;
Expand All @@ -99,6 +101,7 @@ export function annotateStacktrace (stack, formatInternal, eToString = null) {
export function extractStacktrace (e, offset) {
offset = offset === undefined ? 4 : offset;

// Support: IE9, e.stack is not supported, we will return undefined
if (e && e.stack) {
const stack = e.stack.split('\n');
// In Firefox and Safari, e.stack starts immediately with the first frame.
Expand Down
11 changes: 7 additions & 4 deletions test/main/TapReporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function mockStack (error) {
error.stack = ''
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
+ ' at require (internal/helpers.js:22:18)\n'
+ ' at require (node:internal/helpers.js:22:18)\n'
+ ' at /dev/null/src/example/foo.js:220:27';
return error;
}
Expand Down Expand Up @@ -35,6 +35,9 @@ QUnit.module('TapReporter', function (hooks) {
},
cyan: function (txt) {
return '\x1B[36m' + txt + '\x1B[39m';
},
grey: function (txt) {
return '\x1B[90m' + txt + '\x1B[39m';
}
};

Expand Down Expand Up @@ -149,15 +152,15 @@ QUnit.module('TapReporter', function (hooks) {
+ ' severity: failed\n'
+ ' stack: |\n'
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
+ ' at require (internal/helpers.js:22:18)\n'
+ ' ' + kleur.grey(' at require (node:internal/helpers.js:22:18)') + '\n'
+ ' at /dev/null/src/example/foo.js:220:27\n'
+ ' ...\n'
+ ' ---\n'
+ ' message: second error\n'
+ ' severity: failed\n'
+ ' stack: |\n'
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
+ ' at require (internal/helpers.js:22:18)\n'
+ ' ' + kleur.grey(' at require (node:internal/helpers.js:22:18)') + '\n'
+ ' at /dev/null/src/example/foo.js:220:27\n'
+ ' ...\n'
);
Expand Down Expand Up @@ -190,7 +193,7 @@ QUnit.module('TapReporter', function (hooks) {
+ ' severity: failed\n'
+ ' stack: |\n'
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
+ ' at require (internal/helpers.js:22:18)\n'
+ ' ' + kleur.grey(' at require (node:internal/helpers.js:22:18)') + '\n'
+ ' at /dev/null/src/example/foo.js:220:27\n'
+ ' ...\n'
+ 'Bail out! ReferenceError: Boo is not defined\n'
Expand Down

0 comments on commit 280e721

Please sign in to comment.