Skip to content

Commit

Permalink
Tests: Update CLI test and test fixture to remove stacktrace ambiguity.
Browse files Browse the repository at this point in the history
Unfortunately, we cannot use real errors here because the stack trace
representation changes across Node versions (and therefore the
expectations fail).
  • Loading branch information
rwjblue committed Dec 18, 2017
1 parent 59f4080 commit 93007ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
18 changes: 13 additions & 5 deletions test/cli/fixtures/expected/tap-outputs.js
@@ -1,3 +1,7 @@
"use strict";

const path = require( "path" );

// Expected outputs from the TapReporter for the commands run in CLI tests
module.exports = {
"qunit":
Expand Down Expand Up @@ -97,21 +101,25 @@ not ok 1 Unhandled Rejections > test passes just fine, but has a rejected promis
---
message: "Error thrown in non-returned promise!"
severity: failed
actual: {}
actual: {
"message": "Error thrown in non-returned promise!",
"stack": "Error: Error thrown in non-returned promise!\\n at /some/path/wherever/unhandled-rejection.js:13:11"
}
expected: undefined
stack: Error: Error thrown in non-returned promise!
at /Users/rjackson/src/open-source/qunit/test/cli/fixtures/unhandled-rejection.js:13:11
at <anonymous>
at /some/path/wherever/unhandled-rejection.js:13:11
...
not ok 2 global failure
---
message: "outside of a test context"
severity: failed
actual: {
"message": "outside of a test context"
"message": "outside of a test context",
"stack": "Error: outside of a test context\\n at Object.<anonymous> (/some/path/wherever/unhandled-rejection.js:20:18)"
}
expected: undefined
stack: at runTest (/Users/rjackson/src/open-source/qunit/dist/qunit.js:1478:30)
stack: Error: outside of a test context
at Object.<anonymous> (/some/path/wherever/unhandled-rejection.js:20:18)
...
1..2
# pass 0
Expand Down
17 changes: 15 additions & 2 deletions test/cli/fixtures/unhandled-rejection.js
Expand Up @@ -10,12 +10,25 @@ QUnit.module( "Unhandled Rejections", function() {
setTimeout( resolve );
} )
.then( function() {
throw new Error( "Error thrown in non-returned promise!" );

// throwing a non-Error here because stack trace representation
// across Node versions is not stable (they continue to get better)
throw {
message: "Error thrown in non-returned promise!",
stack: `Error: Error thrown in non-returned promise!
at /some/path/wherever/unhandled-rejection.js:13:11`
};
} );

// prevent test from exiting before unhandled rejection fires
setTimeout( done, 10 );
} );

Promise.reject( { message: "outside of a test context" } );
// rejecting with a non-Error here because stack trace representation
// across Node versions is not stable (they continue to get better)
Promise.reject( {
message: "outside of a test context",
stack: `Error: outside of a test context
at Object.<anonymous> (/some/path/wherever/unhandled-rejection.js:20:18)`
} );
} );

0 comments on commit 93007ce

Please sign in to comment.