forked from qunitjs/qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
183 lines (136 loc) · 4.24 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { window, setTimeout } from "./globals";
import equiv from "./equiv";
import dump from "./dump";
import module from "./module";
import Assert from "./assert";
import Test, { test, skip, only, todo, pushFailure } from "./test";
import exportQUnit from "./export";
import config from "./core/config";
import { defined, extend, objectType, is, now } from "./core/utilities";
import { registerLoggingCallbacks, runLoggingCallbacks } from "./core/logging";
import { sourceFromStacktrace } from "./core/stacktrace";
import ProcessingQueue from "./core/processing-queue";
import SuiteReport from "./reports/suite";
import { on, emit } from "./events";
import onError from "./core/onerror";
import onUnhandledRejection from "./core/on-unhandled-rejection";
const QUnit = {};
export const globalSuite = new SuiteReport();
// The initial "currentModule" represents the global (or top-level) module that
// is not explicitly defined by the user, therefore we add the "globalSuite" to
// it since each module has a suiteReport associated with it.
config.currentModule.suiteReport = globalSuite;
var globalStartCalled = false;
var runStarted = false;
// Figure out if we're running the tests from a server or not
QUnit.isLocal = !( defined.document && window.location.protocol !== "file:" );
// Expose the current QUnit version
QUnit.version = "@VERSION";
extend( QUnit, {
on,
module,
test: test,
todo: todo,
skip: skip,
only: only,
start: function( count ) {
var globalStartAlreadyCalled = globalStartCalled;
if ( !config.current ) {
globalStartCalled = true;
if ( runStarted ) {
throw new Error( "Called start() while test already started running" );
} else if ( globalStartAlreadyCalled || count > 1 ) {
throw new Error( "Called start() outside of a test context too many times" );
} else if ( config.autostart ) {
throw new Error( "Called start() outside of a test context when " +
"QUnit.config.autostart was true" );
} else if ( !config.pageLoaded ) {
// The page isn't completely loaded yet, so we set autostart and then
// load if we're in Node or wait for the browser's load event.
config.autostart = true;
// Starts from Node even if .load was not previously called. We still return
// early otherwise we'll wind up "beginning" twice.
if ( !defined.document ) {
QUnit.load();
}
return;
}
} else {
throw new Error( "QUnit.start cannot be called inside a test context." );
}
scheduleBegin();
},
config: config,
is: is,
objectType: objectType,
extend: extend,
load: function() {
config.pageLoaded = true;
// Initialize the configuration options
extend( config, {
stats: { all: 0, bad: 0 },
started: 0,
updateRate: 1000,
autostart: true,
filter: ""
}, true );
if ( !runStarted ) {
config.blocking = false;
if ( config.autostart ) {
scheduleBegin();
}
}
},
stack: function( offset ) {
offset = ( offset || 0 ) + 2;
return sourceFromStacktrace( offset );
},
onError,
onUnhandledRejection
} );
QUnit.pushFailure = pushFailure;
QUnit.assert = Assert.prototype;
QUnit.equiv = equiv;
QUnit.dump = dump;
registerLoggingCallbacks( QUnit );
function scheduleBegin() {
runStarted = true;
// Add a slight delay to allow definition of more modules and tests.
if ( defined.setTimeout ) {
setTimeout( function() {
begin();
} );
} else {
begin();
}
}
export function begin() {
var i, l,
modulesLog = [];
// If the test run hasn't officially begun yet
if ( !config.started ) {
// Record the time of the test run's beginning
config.started = now();
// Delete the loose unnamed module if unused.
if ( config.modules[ 0 ].name === "" && config.modules[ 0 ].tests.length === 0 ) {
config.modules.shift();
}
// Avoid unnecessary information by not logging modules' test environments
for ( i = 0, l = config.modules.length; i < l; i++ ) {
modulesLog.push( {
name: config.modules[ i ].name,
tests: config.modules[ i ].tests
} );
}
// The test run is officially beginning now
emit( "runStart", globalSuite.start( true ) );
runLoggingCallbacks( "begin", {
totalTests: Test.count,
modules: modulesLog
} );
}
config.blocking = false;
ProcessingQueue.advance();
}
exportQUnit( QUnit );
export default QUnit;