Add support for custom reporter (#11938)

* Add support for custom reporter

* Update CustomReporter and add more test:
- jasmineDone() shoud return type "any" instead of "void".
- CustomReporter should has optional method.

* Fix error: Duplicate identifier 'Promise'.
This commit is contained in:
Foxeye-Rinx
2016-10-25 19:26:49 +09:00
committed by Masahiro Wakame
parent 3c223cbfb1
commit 9e778b38c2
2 changed files with 96 additions and 0 deletions
+56
View File
@@ -904,6 +904,62 @@ describe("Custom matcher: 'toBeGoofy'", function () {
});
});
// test based on http://jasmine.github.io/2.5/custom_reporter.html
var myReporter: jasmine.CustomReporter = {
jasmineStarted: function (suiteInfo: jasmine.SuiteInfo ) {
console.log("Running suite with " + suiteInfo.totalSpecsDefined);
},
suiteStarted: function (result: jasmine.CustomReporterResult) {
console.log("Suite started: " + result.description + " whose full description is: " + result.fullName);
},
specStarted: function (result: jasmine.CustomReporterResult) {
console.log("Spec started: " + result.description + " whose full description is: " + result.fullName);
},
specDone: function (result: jasmine.CustomReporterResult) {
console.log("Spec: " + result.description + " was " + result.status);
for (var i = 0; i < result.failedExpectations.length; i++) {
console.log("Failure: " + result.failedExpectations[i].message);
console.log("Actual: " + result.failedExpectations[i].actual);
console.log("Expected: " + result.failedExpectations[i].expected);
console.log(result.failedExpectations[i].stack);
}
console.log(result.passedExpectations.length);
},
suiteDone: function (result: jasmine.CustomReporterResult) {
console.log('Suite: ' + result.description + ' was ' + result.status);
for (var i = 0; i < result.failedExpectations.length; i++) {
console.log('AfterAll ' + result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
},
jasmineDone: function() {
console.log('Finished suite');
}
};
jasmine.getEnv().addReporter(myReporter);
// test for custom reporter which return ES6 Promise in jasmineDone():
var myShortReporter: jasmine.CustomReporter = {
jasmineDone: function() {
return new Promise<void>(function(resolve, reject) {
setTimeout(() => resolve(), 10000);
});
}
}
var jasmineDoneResolved: Promise<void> = myShortReporter.jasmineDone();
jasmineDoneResolved.then(() => {
console.log("[ShortReporter] : jasmineDone Resolved");
});
jasmine.getEnv().addReporter(myShortReporter);
describe("Randomize Tests", function() {
it("should allow randomization of the order of tests", function() {
expect(function() {
+40
View File
@@ -162,6 +162,7 @@ declare namespace jasmine {
versionString(): string;
nextSpecId(): number;
addReporter(reporter: Reporter): void;
addReporter(reporter: CustomReporter): void;
execute(): void;
describe(description: string, specDefinitions: () => void): Suite;
// ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these
@@ -354,6 +355,45 @@ declare namespace jasmine {
addReporter(reporter: Reporter): void;
}
interface SuiteInfo {
totalSpecsDefined: number;
}
interface CustomReportExpectation {
matcherName: string;
message: string;
passed: boolean;
stack: string;
}
interface FailedExpectation extends CustomReportExpectation {
actual: string;
expected: string;
}
interface PassedExpectation extends CustomReportExpectation {
}
interface CustomReporterResult {
description: string,
failedExpectations?: FailedExpectation[],
fullName: string,
id: string;
passedExpectations?: PassedExpectation[],
pendingReason?: string;
status?: string;
}
interface CustomReporter {
jasmineStarted?(suiteInfo: SuiteInfo): void;
suiteStarted?(result: CustomReporterResult): void;
specStarted?(result: CustomReporterResult): void;
specDone?(result: CustomReporterResult): void;
suiteDone?(result: CustomReporterResult): void;
jasmineDone?(): any;
}
interface Runner {
new (env: Env): any;