-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.ts
More file actions
57 lines (50 loc) · 1.72 KB
/
Main.ts
File metadata and controls
57 lines (50 loc) · 1.72 KB
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
import { Failure, Global } from '@ephox/bedrock-common';
import * as Globals from '../core/Globals';
import * as TestLoader from '../core/TestLoader';
import { UrlParams } from '../core/UrlParams';
import { makeSessionId } from '../core/Utils';
import { Callbacks } from '../reporter/Callbacks';
import { Reporter } from '../reporter/Reporter';
import { Runner } from '../runner/Runner';
import { loop } from '../runner/Utils';
import { Ui } from '../ui/Ui';
declare const $: JQueryStatic;
// Setup the globals
Globals.setup();
const setupAndRun = (loadError?: Error) => {
const params = UrlParams.parse(window.location.search, makeSessionId);
const ui = Ui($('body'));
const callbacks = Callbacks();
const reporter = Reporter(params, callbacks, ui);
const runner = Runner(Globals.rootSuite(), params, callbacks, reporter, ui);
runner.init().then((data) => {
// Run the tests if an error didn't occur during loading
if (loadError !== undefined) {
return Promise.reject(loadError);
} else {
const autoMode = data.mode === 'auto';
if (autoMode) {
// Try to ensure the page has focus
window.focus();
}
return runner.run(data.chunk, data.retries, data.timeout, data.stopOnFailure, autoMode);
}
}).catch((e: Error) => {
console.error('Unexpected error occurred', e);
const err = Failure.prepFailure(e);
ui.error(err);
reporter.done(err);
});
};
const run = () => setupAndRun();
const runError = (e: Error) => setupAndRun(Failure.prepFailure(e));
const loadAndRun = (scripts: string[]) => {
// Load the scripts and then run
loop(scripts, TestLoader.load)
.then(run, runError);
};
Global.bedrock = {
loadAndRun,
run,
rootSuite: Globals.rootSuite()
};