Last active
November 16, 2017 22:12
-
-
Save DevWurm/5e1fc72afae63cf53adb5567da548191 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
import {TraceReporter} from '../../TraceReporter/TraceReporter'; | |
import {trace} from '../../TraceReporter/trace'; | |
jasmine.getEnv().addReporter(new TraceReporter()); | |
describe('AppComponent', () => { | |
[...] | |
trace('PROJECT-123', it('should create the app', async(() => { | |
fail(); | |
}))); | |
trace(['PROJECT-123', 'PROJECT-122'], it(`should have as title 'app'`, async(() => { | |
return; | |
}))); | |
trace('PROJECT-122', it('should render title in a h1 tag', async(() => { | |
return; | |
}))); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"PROJECT-123": { | |
"compliant": false, | |
"testCases": { | |
"should create the app": "failed", | |
"should have as title 'app'": "passed" | |
} | |
}, | |
"PROJECT-122": { | |
"compliant": true, | |
"testCases": { | |
"should have as title 'app'": "passed", | |
"should render title in a h1 tag": "passed" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function trace(tags: string | string[], spec: any) { | |
spec.result.metadata = {tags: tags instanceof Array ? tags : [tags]}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CustomReporter = jasmine.CustomReporter; | |
import CustomReporterResult = jasmine.CustomReporterResult; | |
export class TraceReporter implements CustomReporter { | |
private traceResult = new Map<string, SpecResult[]>(); | |
specDone(result: CustomReporterResult) { | |
const tags = (result['metadata'] || {tags: []}).tags; | |
tags.forEach(tag => { | |
if (this.traceResult.has(tag)) { | |
this.traceResult.set(tag, this.traceResult.get(tag).concat({ | |
description: result.description, | |
passed: result.status === 'passed' | |
})); | |
} else { | |
this.traceResult.set(tag, [{description: result.description, passed: result.status === 'passed'}]); | |
} | |
}); | |
} | |
jasmineDone() { | |
const result = Array.from(this.traceResult.entries()).reduce((report, [tag, specResults]) => | |
Object.assign(report, { | |
[tag]: { | |
compliant: specResults.reduce((isCompliant, {passed}) => isCompliant && passed, true), | |
testCases: specResults.reduce((results, {description, passed}) => | |
Object.assign(results, {[description]: passed ? 'passed' : 'failed'}), | |
{}) | |
} | |
}), | |
{}); | |
console.log(JSON.stringify(result, null, 4)); | |
} | |
} | |
interface SpecResult { | |
description: string; | |
passed: boolean; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment