Skip to content

Commit

Permalink
Make throw/assertion stack traces useful
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Jul 20, 2017
1 parent ff4ad46 commit 7028f4b
Show file tree
Hide file tree
Showing 5 changed files with 1,760 additions and 1,192 deletions.
26 changes: 25 additions & 1 deletion lib/ember-qunit/adapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import Ember from 'ember';
import QUnit from 'qunit';

function unhandledRejectionAssertion(current, error) {
let message, source;

if (typeof error === 'object' && error !== null) {
message = error.message;
source = error.stack;

} else if (typeof error === "string") {
message = error;
source = "unknown source";
} else {
message = "unhandledRejection occured, but it had no message";
source = "unknown source";
}

current.pushResult({
result: false,
actual: false,
expected: true,
message: message,
source: source
});
}

export default Ember.Test.Adapter.extend({
init() {
this.doneCallbacks = [];
Expand All @@ -19,6 +43,6 @@ export default Ember.Test.Adapter.extend({
},

exception(error) {
QUnit.config.current.assert.ok(false, Ember.inspect(error));
unhandledRejectionAssertion(QUnit.config.current, error);
}
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"devDependencies": {
"bower": "^1.3.12",
"broccoli": "^0.16.9",
"broccoli-babel-transpiler": "^5.5.0",
"broccoli-funnel": "^1.1.0",
"broccoli-babel-transpiler": "^5.7.1",
"broccoli-funnel": "^1.2.0",
"broccoli-jshint": "^2.1.0",
"broccoli-merge-trees": "^2.0.0",
"broccoli-sourcemap-concat": "^1.1.6",
Expand All @@ -31,9 +31,9 @@
"ember-cli-release": "^1.0.0-beta.2",
"exists-sync": "^0.0.4",
"git-repo-version": "^0.4.1",
"loader.js": "^4.2.3",
"loader.js": "^4.5.1",
"phantomjs-prebuilt": "^2.1.12",
"resolve": "^1.1.7"
"resolve": "^1.3.3"
},
"repository": {
"type": "git",
Expand Down
7 changes: 0 additions & 7 deletions testem.json

This file was deleted.

98 changes: 93 additions & 5 deletions tests/adapter-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global setTimeout */

import { module, test } from 'qunit';
import { QUnitAdapter } from 'ember-qunit';
import QUnit, { module, test} from "qunit";
import { QUnitAdapter } from "ember-qunit";

module('QUnitAdapter');
module("QUnitAdapter");

test('asyncStart waits for asyncEnd to finish a test', function(assert) {
test("asyncStart waits for asyncEnd to finish a test", function(assert) {
const adapter = QUnitAdapter.create();

adapter.asyncStart();
Expand All @@ -15,7 +15,9 @@ test('asyncStart waits for asyncEnd to finish a test', function(assert) {
}, 50);
});

test('asyncStart waits for equal numbers of asyncEnd to finish a test', function(assert) {
test("asyncStart waits for equal numbers of asyncEnd to finish a test", function(
assert
) {
const adapter = QUnitAdapter.create();

adapter.asyncStart();
Expand All @@ -27,3 +29,89 @@ test('asyncStart waits for equal numbers of asyncEnd to finish a test', function
adapter.asyncEnd();
}, 50);
});

test("exception (nothing)", function(assert) {
const adapter = QUnitAdapter.create();

let count = 0;
let pushedResult;

let originalPushResult = QUnit.config.current.pushResult;
try {
QUnit.config.current.pushResult = function(result) {
count++;
pushedResult = result;
};
adapter.exception();
} finally {
QUnit.config.current.pushResult = originalPushResult;
}

assert.deepEqual(pushedResult, {
result: false,
actual: false,
expected: true,
message: "unhandledRejection occured, but it had no message",
source: "unknown source"
});

assert.equal(count, 1);
});

test("exception (error)", function(assert) {
const adapter = QUnitAdapter.create();
const error = new Error("hi");

let count = 0;
let pushedResult;

let originalPushResult = QUnit.config.current.pushResult;
try {
QUnit.config.current.pushResult = function(result) {
count++;
pushedResult = result;
};
adapter.exception(error);
} finally {
QUnit.config.current.pushResult = originalPushResult;
}

assert.deepEqual(pushedResult, {
result: false,
actual: false,
expected: true,
message: "hi",
source: error.stack
});

assert.equal(count, 1);
});

test("exception (string)", function(assert) {
const adapter = QUnitAdapter.create();
const error = "hi";

let count = 0;
let pushedResult;

let originalPushResult = QUnit.config.current.pushResult;
try {
QUnit.config.current.pushResult = function(result) {
count++;
pushedResult = result;
};
adapter.exception(error);
} finally {
QUnit.config.current.pushResult = originalPushResult;
}

assert.deepEqual(pushedResult, {
result: false,
actual: false,
expected: true,
message: "hi",
source: "unknown source"
});

assert.equal(count, 1);
});
Loading

0 comments on commit 7028f4b

Please sign in to comment.