-
Notifications
You must be signed in to change notification settings - Fork 785
/
core.js
143 lines (118 loc) 路 3.87 KB
/
core.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { window, document, setTimeout } from './globals';
import equiv from './equiv';
import dump from './dump';
import { runSuite, module } from './module';
import Assert from './assert';
import Test, { test, pushFailure } from './test';
import exportQUnit from './export';
import reporters from './reporters';
import config from './core/config';
import hooks from './core/hooks';
import { extend, objectType, is, performance } from './core/utilities';
import { registerLoggingCallbacks, runLoggingCallbacks } from './core/logging';
import { sourceFromStacktrace } from './core/stacktrace';
import ProcessingQueue from './core/processing-queue';
import { on, emit } from './events';
import onUncaughtException from './core/on-uncaught-exception';
import diff from './core/diff';
const QUnit = {};
// The "currentModule" object would ideally be defined using the createModule()
// function. Since it isn't, add the missing suiteReport property to it now that
// we have loaded all source code required to do so.
//
// TODO: Consider defining currentModule in core.js or module.js in its entirely
// rather than partly in config.js and partly here.
config.currentModule.suiteReport = runSuite;
config.pq = new ProcessingQueue(test);
// Figure out if we're running the tests from a server or not
QUnit.isLocal = (window && window.location && window.location.protocol === 'file:');
// Expose the current QUnit version
QUnit.version = '@VERSION';
extend(QUnit, {
config,
diff,
dump,
equiv,
reporters,
hooks,
is,
objectType,
on,
onUncaughtException,
pushFailure,
assert: Assert.prototype,
module,
test,
// alias other test flavors for easy access
todo: test.todo,
skip: test.skip,
only: test.only,
start: function () {
if (config.current) {
throw new Error('QUnit.start cannot be called inside a test.');
}
if (config._runStarted) {
if (document && config.autostart) {
throw new Error('QUnit.start() called too many times. Did you call QUnit.start() in browser context when autostart is also enabled? https://qunitjs.com/api/QUnit/start/');
}
throw new Error('QUnit.start() called too many times.');
}
config._runStarted = true;
// Add a slight delay to allow definition of more modules and tests.
if (document && document.readyState !== 'complete' && setTimeout) {
// In browser environments, if QUnit.start() is called very early,
// still wait for DOM ready to ensure reliable integration of reporters.
window.addEventListener('load', function () {
setTimeout(function () {
begin();
});
});
} else if (setTimeout) {
setTimeout(function () {
begin();
});
} else {
begin();
}
},
stack: function (offset) {
offset = (offset || 0) + 2;
return sourceFromStacktrace(offset);
}
});
registerLoggingCallbacks(QUnit);
function unblockAndAdvanceQueue () {
config.blocking = false;
config.pq.advance();
}
function begin () {
if (config.started) {
unblockAndAdvanceQueue();
return;
}
// The test run hasn't officially begun yet
// Record the time of the test run's beginning
config.started = performance.now();
// Delete the loose unnamed module if unused.
if (config.modules[0].name === '' && config.modules[0].tests.length === 0) {
config.modules.shift();
}
const modulesLog = [];
for (let i = 0; i < config.modules.length; i++) {
// Don't expose the unnamed global test module to plugins.
if (config.modules[i].name !== '') {
modulesLog.push({
name: config.modules[i].name,
moduleId: config.modules[i].moduleId
});
}
}
// The test run is officially beginning now
emit('runStart', runSuite.start(true));
runLoggingCallbacks('begin', {
totalTests: Test.count,
modules: modulesLog
}).then(unblockAndAdvanceQueue);
}
exportQUnit(QUnit);
export default QUnit;