forked from emberjs/ember-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-isolation-validation-test.js
90 lines (69 loc) · 2.44 KB
/
test-isolation-validation-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import Ember from 'ember';
import { later, _backburner as backburner } from '@ember/runloop';
import { module, test } from 'qunit';
import { installTestNotIsolatedHook } from 'ember-qunit/test-isolation-validation';
import { getDebugInfo } from '@ember/test-helpers';
import patchAssert from './utils/patch-assert-helper';
backburner.DEBUG = true;
if (getDebugInfo()) {
module('test isolation validation', function (hooks) {
let isWaiterPending = false;
let waiter = () => {
return !isWaiterPending;
};
// In Ember < 2.8 `registerWaiter` expected to be bound to
// `Ember.Test` 😭
//
// Once we have dropped support for < 2.8 we should swap this to
// use:
//
// import { registerWaiter } from '@ember/test';
Ember.Test.registerWaiter(waiter);
QUnit.on('testEnd', function () {
Ember.Test.unregisterWaiter(this._waiter);
});
hooks.beforeEach(function () {
this.cancelId = 0;
backburner.DEBUG = true;
installTestNotIsolatedHook();
});
test('detectIfTestNotIsolated does not add failing assertion when test is isolated', function (assert) {
assert.expect(1);
assert.ok(true);
});
test('detectIfTestNotIsolated adds failing assertion when test has pending timers', function (assert) {
assert.expect(1);
patchAssert(assert);
this.cancelId = later(() => {}, 1000);
});
test('detectIfTestNotIsolated adds failing assertion when test has test waiters', function (assert) {
assert.expect(1);
patchAssert(assert);
isWaiterPending = true;
});
test('detectIfTestNotIsolated allows for a small window (e.g. an autorun to flush)', function (assert) {
assert.expect(0);
isWaiterPending = true;
setTimeout(() => (isWaiterPending = false), 0);
});
module('timeouts', function (hooks) {
hooks.afterEach(function (assert) {
assert.test._originalPushResult({
result:
assert.test.assertions[0].message.indexOf(
'Failed: Test took longer than 50ms'
) === 0,
});
});
test('detectIfTestNotIsolated outputs debug info on test timeout', function (assert) {
assert.expect(1);
assert.timeout(50);
assert.async();
let testPushFailure = assert.test.pushFailure;
patchAssert(assert);
assert.test.pushFailure = testPushFailure;
later(() => {}, 100);
});
});
});
}