This repository has been archived by the owner on Dec 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-explorer-custom-reporter.ts
76 lines (61 loc) · 2.24 KB
/
test-explorer-custom-reporter.ts
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
import * as karma from "karma";
import { TestResult } from "../../model/test-status.enum";
import { RunStatus } from "../../model/run-status.enum";
import { SpecCompleteResponse } from "../../model/spec-complete-response";
import * as io from "socket.io-client";
function TestExplorerCustomReporter(this: any, baseReporterDecorator: any, config: any, logger: any, emitter: any, formatError: any) {
this.config = config;
this.emitter = emitter;
this.socket = io("http://localhost:1111/");
const emitEvent = (eventName: any, eventResults: any = null) => {
this.socket.emit(eventName,{name: eventName, results: eventResults});
};
baseReporterDecorator(this);
this.adapters = [];
this.onSpecComplete = (browser: any, spec: any) => {
let status: TestResult = TestResult.Failed;
if (spec.skipped) {
status = TestResult.Skipped;
} else if (spec.success) {
status = TestResult.Success;
}
const result = new SpecCompleteResponse(spec.log, spec.suite, spec.description, status, spec.time);
emitEvent("spec_complete", result);
};
this.onRunComplete = (browserCollection: any, result: any) => {
emitEvent("run_complete", collectRunState(result));
};
this.onBrowserError = (browser: any, error: any) => {
emitEvent("browser_error", error);
};
this.onBrowserStart = (browser: any, info: any) => {
emitEvent("browser_start");
};
this.emitter.on("browsers_change", (capturedBrowsers: any) => {
if (!capturedBrowsers.forEach) {
// filter out events from Browser object
return;
}
let proceed = true;
capturedBrowsers.forEach((newBrowser: any) => {
if (!newBrowser.id || !newBrowser.name || newBrowser.id === newBrowser.name) {
proceed = false;
}
});
if (proceed) {
emitEvent("browser_connected");
}
});
}
function collectRunState(runResult: karma.TestResults): RunStatus {
if (runResult.disconnected) {
return RunStatus.Timeout;
} else if (runResult.error) {
return RunStatus.Error;
} else {
return RunStatus.Complete;
}
}
TestExplorerCustomReporter.$inject = ["baseReporterDecorator", "config", "logger", "emitter", "formatError"];
export const instance = TestExplorerCustomReporter;
export const name = "AngularReporter";