This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
/
decorator-suite-runner.js
67 lines (52 loc) · 1.65 KB
/
decorator-suite-runner.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
'use strict';
const url = require('url');
const path = require('path');
const Runner = require('../runner');
const RunnerEvents = require('../../constants/runner-events');
module.exports = class DecoratorSuiteRunner extends Runner {
constructor(runner, browserAgent, config) {
super();
this._suiteRunner = runner;
this._browserConfig = config.forBrowser(browserAgent.browserId);
this.passthroughEvent(this._suiteRunner, [
RunnerEvents.BEGIN_SUITE,
RunnerEvents.END_SUITE
]);
[
RunnerEvents.BEGIN_STATE,
RunnerEvents.SKIP_STATE,
RunnerEvents.END_STATE,
RunnerEvents.TEST_RESULT,
RunnerEvents.CAPTURE,
RunnerEvents.UPDATE_RESULT,
RunnerEvents.WARNING,
RunnerEvents.ERROR
].forEach((event) => this._decorateEvent(event));
}
run(stateProcessor) {
return this._suiteRunner.run(stateProcessor);
}
cancel() {
this._suiteRunner.cancel();
}
_decorateEvent(event) {
this._suiteRunner.on(event, (data) => this.emitAndWait(event, this._addMetaUrl(data)));
}
_addMetaUrl(data) {
if (data.suite.metaInfo) {
return data;
}
const metaUrl = this._mkFullUrl(data.suite.url);
data.suite.metaInfo = {
get url() {
return metaUrl;
}
};
return data;
}
_mkFullUrl(suiteUrl) {
const rootUrl = this._browserConfig.rootUrl;
const urlObj = url.parse(rootUrl + '/' + suiteUrl);
return path.resolve(path.normalize(urlObj.path));
}
};