Skip to content

Instantly share code, notes, and snippets.

@DevWurm

DevWurm/TraceReporter.ts

Last active Nov 16, 2017
Embed
What would you like to do?
[...]
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;
})));
});
{
"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"
}
}
}
export function trace(tags: string | string[], spec: any) {
spec.result.metadata = {tags: tags instanceof Array ? tags : [tags]};
}
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
You can’t perform that action at this time.