1 |
|
2 |
|
3 | export { default as QUnitAdapter, nonTestDoneCallback } from './adapter';
|
4 | export { loadTests } from './test-loader';
|
5 |
|
6 | import './qunit-configuration';
|
7 |
|
8 | if (typeof Testem !== 'undefined') {
|
9 | Testem.hookIntoTestFramework();
|
10 | }
|
11 |
|
12 | import { _backburner } from '@ember/runloop';
|
13 | import { resetOnerror, getTestMetadata } from '@ember/test-helpers';
|
14 | import { loadTests } from './test-loader';
|
15 | import Ember from 'ember';
|
16 | import * as QUnit from 'qunit';
|
17 | import QUnitAdapter from './adapter';
|
18 | import {
|
19 | setupContext,
|
20 | teardownContext,
|
21 | setupRenderingContext,
|
22 | setupApplicationContext,
|
23 | validateErrorHandler,
|
24 | } from '@ember/test-helpers';
|
25 | import { installTestNotIsolatedHook } from './test-isolation-validation';
|
26 |
|
27 | let waitForSettled = true;
|
28 |
|
29 | export function setupTest(hooks, _options) {
|
30 | let options = { waitForSettled, ..._options };
|
31 |
|
32 | hooks.beforeEach(function (assert) {
|
33 | let testMetadata = getTestMetadata(this);
|
34 | testMetadata.framework = 'qunit';
|
35 |
|
36 | return setupContext(this, options).then(() => {
|
37 | let originalPauseTest = this.pauseTest;
|
38 | this.pauseTest = function QUnit_pauseTest() {
|
39 | assert.timeout(-1);
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | clearTimeout(QUnit.config.timeout);
|
46 | return originalPauseTest.call(this);
|
47 | };
|
48 | });
|
49 | });
|
50 |
|
51 | hooks.afterEach(function () {
|
52 | return teardownContext(this, options);
|
53 | });
|
54 | }
|
55 |
|
56 | export function setupRenderingTest(hooks, _options) {
|
57 | let options = { waitForSettled, ..._options };
|
58 |
|
59 | setupTest(hooks, options);
|
60 |
|
61 | hooks.beforeEach(function () {
|
62 | return setupRenderingContext(this);
|
63 | });
|
64 | }
|
65 |
|
66 | export function setupApplicationTest(hooks, _options) {
|
67 | let options = { waitForSettled, ..._options };
|
68 |
|
69 | setupTest(hooks, options);
|
70 |
|
71 | hooks.beforeEach(function () {
|
72 | return setupApplicationContext(this);
|
73 | });
|
74 | }
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export function setupTestContainer() {
|
86 | let testContainer = document.getElementById('ember-testing-container');
|
87 | if (!testContainer) {
|
88 | return;
|
89 | }
|
90 |
|
91 | let params = QUnit.urlParams;
|
92 |
|
93 | if (params.devmode || params.fullscreencontainer) {
|
94 | testContainer.classList.add('ember-testing-container-full-screen');
|
95 | }
|
96 |
|
97 | if (params.nocontainer) {
|
98 | testContainer.classList.add('ember-testing-container-hidden');
|
99 | }
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | export function startTests() {
|
107 | QUnit.start();
|
108 | }
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | export function setupTestAdapter() {
|
116 | Ember.Test.adapter = QUnitAdapter.create();
|
117 | }
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | export function setupEmberTesting() {
|
126 | QUnit.testStart(() => {
|
127 | Ember.testing = true;
|
128 | });
|
129 |
|
130 | QUnit.testDone(() => {
|
131 | Ember.testing = false;
|
132 | });
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | export function setupEmberOnerrorValidation() {
|
140 | QUnit.module('ember-qunit: Ember.onerror validation', function () {
|
141 | QUnit.test('Ember.onerror is functioning properly', function (assert) {
|
142 | assert.expect(1);
|
143 | let result = validateErrorHandler();
|
144 | assert.ok(
|
145 | result.isValid,
|
146 | `Ember.onerror handler with invalid testing behavior detected. An Ember.onerror handler _must_ rethrow exceptions when \`Ember.testing\` is \`true\` or the test suite is unreliable. See https://git.io/vbine for more details.`
|
147 | );
|
148 | });
|
149 | });
|
150 | }
|
151 |
|
152 | export function setupResetOnerror() {
|
153 | QUnit.testDone(resetOnerror);
|
154 | }
|
155 |
|
156 | export function setupTestIsolationValidation(delay) {
|
157 | waitForSettled = false;
|
158 | _backburner.DEBUG = true;
|
159 | QUnit.on('testStart', () => installTestNotIsolatedHook(delay));
|
160 | }
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | export function start(options = {}) {
|
185 | if (options.loadTests !== false) {
|
186 | loadTests();
|
187 | }
|
188 |
|
189 | if (options.setupTestContainer !== false) {
|
190 | setupTestContainer();
|
191 | }
|
192 |
|
193 | if (options.setupTestAdapter !== false) {
|
194 | setupTestAdapter();
|
195 | }
|
196 |
|
197 | if (options.setupEmberTesting !== false) {
|
198 | setupEmberTesting();
|
199 | }
|
200 |
|
201 | if (options.setupEmberOnerrorValidation !== false) {
|
202 | setupEmberOnerrorValidation();
|
203 | }
|
204 |
|
205 | if (
|
206 | typeof options.setupTestIsolationValidation !== 'undefined' &&
|
207 | options.setupTestIsolationValidation !== false
|
208 | ) {
|
209 | setupTestIsolationValidation(options.testIsolationValidationDelay);
|
210 | }
|
211 |
|
212 | if (options.startTests !== false) {
|
213 | startTests();
|
214 | }
|
215 |
|
216 | setupResetOnerror();
|
217 | }
|