Skip to content

Commit

Permalink
Test: Strip internal functions from stacktraces in fixtures
Browse files Browse the repository at this point in the history
I'm currently evaluating esbuild, and this produces slightly different
function names (e.g. `module2` instead of `module$1`).

Normalize these away, similar to what we do with Node.js internal
call frames already.
  • Loading branch information
Krinkle committed Mar 27, 2022
1 parent a31e63e commit dec1509
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
19 changes: 6 additions & 13 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ Last test to run (hanging) has an async hold. Ensure all assert.async() callback
stack: |
Error: outside of a test context
at /qunit/test/cli/fixtures/unhandled-rejection.js:17:18
at processModule (/qunit/qunit/qunit.js)
at Object.module$1 [as module] (/qunit/qunit/qunit.js)
at qunit.js
at /qunit/test/cli/fixtures/unhandled-rejection.js:3:7
at internal
...
Expand Down Expand Up @@ -149,10 +148,7 @@ not ok 1 global failure
expected: undefined
stack: |
Error: No tests were run.
at done (/qunit/qunit/qunit.js)
at advanceTestQueue (/qunit/qunit/qunit.js)
at Object.advance (/qunit/qunit/qunit.js)
at unblockAndAdvanceQueue (/qunit/qunit/qunit.js)
at qunit.js
at internal
...
1..1
Expand Down Expand Up @@ -254,10 +250,7 @@ not ok 1 global failure
expected: undefined
stack: |
Error: No tests matched the filter "no matches".
at done (/qunit/qunit/qunit.js)
at advanceTestQueue (/qunit/qunit/qunit.js)
at Object.advance (/qunit/qunit/qunit.js)
at unblockAndAdvanceQueue (/qunit/qunit/qunit.js)
at qunit.js
at internal
...
1..1
Expand Down Expand Up @@ -487,7 +480,7 @@ not ok 1 global failure
stack: |
Error: No dice
at /qunit/test/cli/fixtures/bad-callbacks/begin-throw.js:2:8
at /qunit/qunit/qunit.js
at qunit.js
at internal
...
Bail out! Error: No dice`,
Expand All @@ -507,7 +500,7 @@ Bail out! Error: No dice
stack: |
Error: No dice
at /qunit/test/cli/fixtures/bad-callbacks/done-throw.js:2:8
at /qunit/qunit/qunit.js
at qunit.js
at internal
...`,

Expand Down Expand Up @@ -585,7 +578,7 @@ Bail out! Error: Unexpected release of async pause after tests finished.
stack: |
Error: Unexpected release of async pause after tests finished.
> Test: extra done scheduled outside any test [async #1]
at Timeout.release [as _onTimeout] (/qunit/qunit/qunit.js)
at qunit.js
at internal
...`,

Expand Down
17 changes: 9 additions & 8 deletions test/cli/helpers/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ function normalize( actual ) {
// Replace backslashes (\) in stack traces on Windows to POSIX
.replace( reSep, "/" )

// Convert "at processModule (/qunit/qunit/qunit.js:1:2)" to "at processModule (/qunit/qunit/qunit.js)"
.replace( /(\/qunit\/qunit\/qunit\.js):\d+:\d+\)/g, "$1)" )
// Convert "at processModule (/qunit/qunit/qunit.js:1:2)" to "at qunit.js"
// Convert "at /qunit/qunit/qunit.js:1:2" to "at qunit.js"
.replace( /^(\s+at ).*\/qunit\/qunit\/qunit\.js.*$/gm, "$1qunit.js" )

// Convert "at /qunit/qunit/qunit.js:1:2" to "at /qunit/qunit/qunit.js"
.replace( /( {2}at \/qunit\/qunit\/qunit\.js):\d+:\d+/g, "$1" )
// Convert any "/qunit/qunit/qunit.js:1:2" to "/qunit/qunit/qunit.js"
.replace( /(\/qunit\/qunit\/qunit\.js):\d+:\d+/g, "$1" )

// Strip inferred names for anonymous test closures (as Node 10 did),
// to match the output of Node 12+.
Expand All @@ -48,11 +49,11 @@ function normalize( actual ) {
// Convert "at load (/qunit/node_modules/append-transform/index.js:6" to "at internal"
.replace( / {2}at .+\/.*node_modules\/append-transform\/.*\)/g, " at internal" )

// merge successive lines after initial frame
.replace( /(\n\s+at internal)+/g, "$1" )
// Consolidate subsequent qunit.js frames
.replace( /^(\s+at qunit\.js$)(\n\s+at qunit\.js$)+/gm, "$1" )

// merge successive line with initial frame
.replace( /(at internal)\n\s+at internal/g, "$1" );
// Consolidate subsequent internal frames
.replace( /^(\s+at internal$)(\n\s+at internal$)+/gm, "$1" );
}

/**
Expand Down

0 comments on commit dec1509

Please sign in to comment.