1 | import Ember from 'ember';
|
2 | import * as QUnit from 'qunit';
|
3 | import hasEmberVersion from '@ember/test-helpers/has-ember-version';
|
4 |
|
5 | function unhandledRejectionAssertion(current, error) {
|
6 | let message, source;
|
7 |
|
8 | if (typeof error === 'object' && error !== null) {
|
9 | message = error.message;
|
10 | source = error.stack;
|
11 | } else if (typeof error === 'string') {
|
12 | message = error;
|
13 | source = 'unknown source';
|
14 | } else {
|
15 | message = 'unhandledRejection occured, but it had no message';
|
16 | source = 'unknown source';
|
17 | }
|
18 |
|
19 | current.assert.pushResult({
|
20 | result: false,
|
21 | actual: false,
|
22 | expected: true,
|
23 | message: message,
|
24 | source: source,
|
25 | });
|
26 | }
|
27 |
|
28 | export function nonTestDoneCallback() {}
|
29 |
|
30 | let Adapter = Ember.Test.Adapter.extend({
|
31 | init() {
|
32 | this.doneCallbacks = [];
|
33 | this.qunit = this.qunit || QUnit;
|
34 | },
|
35 |
|
36 | asyncStart() {
|
37 | let currentTest = this.qunit.config.current;
|
38 | let done =
|
39 | currentTest && currentTest.assert
|
40 | ? currentTest.assert.async()
|
41 | : nonTestDoneCallback;
|
42 | this.doneCallbacks.push({ test: currentTest, done });
|
43 | },
|
44 |
|
45 | asyncEnd() {
|
46 | let currentTest = this.qunit.config.current;
|
47 |
|
48 | if (this.doneCallbacks.length === 0) {
|
49 | throw new Error(
|
50 | 'Adapter asyncEnd called when no async was expected. Please create an issue in ember-qunit.'
|
51 | );
|
52 | }
|
53 |
|
54 | let { test, done } = this.doneCallbacks.pop();
|
55 |
|
56 |
|
57 |
|
58 | if (test === currentTest) {
|
59 | done();
|
60 | }
|
61 | },
|
62 |
|
63 |
|
64 |
|
65 | exception: null,
|
66 | });
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | if (!hasEmberVersion(2, 17)) {
|
73 | Adapter = Adapter.extend({
|
74 | exception(error) {
|
75 | unhandledRejectionAssertion(QUnit.config.current, error);
|
76 | },
|
77 | });
|
78 | }
|
79 |
|
80 | export default Adapter;
|