Skip to content

Commit 280e721

Browse files
committed
Test: Fix TapReporter test to cover and use corrent 'internal' stack 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.
1 parent 9d4afff commit 280e721

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/core/stacktrace.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const fileName = qunitFileName();
6565
* - For errors in Node.js, format any remaining qunit.js and node:internal
6666
* frames as internal (i.e. grey out).
6767
*
68-
* @param {string} Error#stack
68+
* @param {string} stack Error#stack
6969
* @param {Function} formatInternal Format a string in an "internal" color
7070
* @param {string|null} [eToString] Error#toString() to help remove
7171
* noise from Node.js/V8 stack traces.
@@ -83,6 +83,8 @@ export function annotateStacktrace (stack, formatInternal, eToString = null) {
8383
let initialInternal = true;
8484
for (let i = 0; i < frames.length; i++) {
8585
const frame = frames[i];
86+
// Example of internal stack trace (Node 16+)
87+
// "at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)"
8688
const isInternal = ((fileName && frame.indexOf(fileName) !== -1) || frame.indexOf('node:internal/') !== -1);
8789
if (!isInternal) {
8890
initialInternal = false;
@@ -99,6 +101,7 @@ export function annotateStacktrace (stack, formatInternal, eToString = null) {
99101
export function extractStacktrace (e, offset) {
100102
offset = offset === undefined ? 4 : offset;
101103

104+
// Support: IE9, e.stack is not supported, we will return undefined
102105
if (e && e.stack) {
103106
const stack = e.stack.split('\n');
104107
// In Firefox and Safari, e.stack starts immediately with the first frame.

test/main/TapReporter.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function mockStack (error) {
22
error.stack = ''
33
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
4-
+ ' at require (internal/helpers.js:22:18)\n'
4+
+ ' at require (node:internal/helpers.js:22:18)\n'
55
+ ' at /dev/null/src/example/foo.js:220:27';
66
return error;
77
}
@@ -35,6 +35,9 @@ QUnit.module('TapReporter', function (hooks) {
3535
},
3636
cyan: function (txt) {
3737
return '\x1B[36m' + txt + '\x1B[39m';
38+
},
39+
grey: function (txt) {
40+
return '\x1B[90m' + txt + '\x1B[39m';
3841
}
3942
};
4043

@@ -149,15 +152,15 @@ QUnit.module('TapReporter', function (hooks) {
149152
+ ' severity: failed\n'
150153
+ ' stack: |\n'
151154
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
152-
+ ' at require (internal/helpers.js:22:18)\n'
155+
+ ' ' + kleur.grey(' at require (node:internal/helpers.js:22:18)') + '\n'
153156
+ ' at /dev/null/src/example/foo.js:220:27\n'
154157
+ ' ...\n'
155158
+ ' ---\n'
156159
+ ' message: second error\n'
157160
+ ' severity: failed\n'
158161
+ ' stack: |\n'
159162
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
160-
+ ' at require (internal/helpers.js:22:18)\n'
163+
+ ' ' + kleur.grey(' at require (node:internal/helpers.js:22:18)') + '\n'
161164
+ ' at /dev/null/src/example/foo.js:220:27\n'
162165
+ ' ...\n'
163166
);
@@ -190,7 +193,7 @@ QUnit.module('TapReporter', function (hooks) {
190193
+ ' severity: failed\n'
191194
+ ' stack: |\n'
192195
+ ' at Object.<anonymous> (/dev/null/test/unit/data.js:6:5)\n'
193-
+ ' at require (internal/helpers.js:22:18)\n'
196+
+ ' ' + kleur.grey(' at require (node:internal/helpers.js:22:18)') + '\n'
194197
+ ' at /dev/null/src/example/foo.js:220:27\n'
195198
+ ' ...\n'
196199
+ 'Bail out! ReferenceError: Boo is not defined\n'

0 commit comments

Comments
 (0)