From 93007ceaff5e6c0cb4f49c89d07d28e1175a6779 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 18 Dec 2017 14:24:18 -0500 Subject: [PATCH] Tests: Update CLI test and test fixture to remove stacktrace ambiguity. Unfortunately, we cannot use real errors here because the stack trace representation changes across Node versions (and therefore the expectations fail). --- test/cli/fixtures/expected/tap-outputs.js | 18 +++++++++++++----- test/cli/fixtures/unhandled-rejection.js | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/test/cli/fixtures/expected/tap-outputs.js b/test/cli/fixtures/expected/tap-outputs.js index f0ad51c9b..031a442b9 100644 --- a/test/cli/fixtures/expected/tap-outputs.js +++ b/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": @@ -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 + 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. (/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. (/some/path/wherever/unhandled-rejection.js:20:18) ... 1..2 # pass 0 diff --git a/test/cli/fixtures/unhandled-rejection.js b/test/cli/fixtures/unhandled-rejection.js index 9f3eea81c..82d3b6eed 100644 --- a/test/cli/fixtures/unhandled-rejection.js +++ b/test/cli/fixtures/unhandled-rejection.js @@ -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. (/some/path/wherever/unhandled-rejection.js:20:18)` + } ); } );