/
custom_reporter.spec.ts
90 lines (77 loc) · 5.74 KB
/
custom_reporter.spec.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { SceneFinished, SceneStarts, SceneTagged, TestRunnerDetected, TestSuiteFinished, TestSuiteStarts } from '@serenity-js/core/lib/events';
import { CapabilityTag, ExecutionFailedWithError, ExecutionSkipped, ExecutionSuccessful, FeatureTag, ImplementationPending, Name, ProblemIndication, ThemeTag } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';
import { jasmine } from '../src/jasmine';
describe('@serenity-js/jasmine', function () {
/**
* @see https://jasmine.github.io/tutorials/custom_reporter
*/
describe('to meet the requirements for custom reporters', () => {
/**
* @see https://jasmine.github.io/examples/jasmine_failure_types.js
*/
it('recognises "all the possible" failure modes', () =>
jasmine(
'examples/custom-reporter-requirements/jasmine_failure_types.js',
'--random=false',
)
.then(ifExitCodeIsOtherThan(3, logOutput))
.then(result => {
expect(result.exitCode).to.equal(3);
PickEvent.from(result.events)
.next(TestSuiteStarts, event => expect(event.details.name).to.equal(new Name(`a suite`)))
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name(`a spec`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Custom-reporter-requirements')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('a suite')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Jasmine')))
.next(SceneFinished, event => {
const outcome = event.outcome as ProblemIndication;
expect(outcome).to.be.instanceOf(ExecutionFailedWithError);
expect(outcome.error).to.be.instanceof(Error);
expect(outcome.error.message).to.equal('Failed: spec'); // there's no message when the spec body is missing
})
.next(TestSuiteFinished, event => {
expect(event.details.name).to.equal(new Name(`a suite`));
expect(event.outcome).to.be.instanceof(ExecutionFailedWithError);
expect((event.outcome as ExecutionFailedWithError).error.message).to.equal('Failed: suite beforeAll');
})
;
}));
/**
* @see https://jasmine.github.io/examples/jasmine_exclusions.js
*/
it('recognises the pending, excluded and skipped scenarios', () =>
jasmine(
'examples/custom-reporter-requirements/jasmine_exclusions.js',
'--random=false',
)
.then(ifExitCodeIsOtherThan(2, logOutput))
.then(result => {
expect(result.exitCode).to.equal(2);
PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name(`pending suite will be pending`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Custom-reporter-requirements')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`focused suite, excludes other suites and specs`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ImplementationPending))
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name(`pending spec`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Custom-reporter-requirements')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`focused suite, excludes other suites and specs`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ImplementationPending))
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name(`spec`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Custom-reporter-requirements')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`focused suite, excludes other suites and specs`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ExecutionSuccessful))
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name(`will be excluded`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Custom-reporter-requirements')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`excluded suite`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ExecutionSkipped))
;
}));
});
});