~endlessm/jasmine-gjs/trunk

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* global jasmineImporter */

const ConsoleReporter = jasmineImporter.consoleReporter;

describe('Default console reporter', function () {
    let out, reporter, timerSpies;

    beforeEach(function () {
        out = (function () {
            let output = '';
            return {
                print(str) {
                    output += str;
                },
                getOutput() {
                    return output;
                },
                clear() {
                    output = '';
                },
            };
        })();

        timerSpies = {};
        const timerSpy = id => {
            timerSpies[id] = jasmine.createSpyObj('timer', ['start', 'elapsed']);
            return timerSpies[id];
        };

        reporter = new ConsoleReporter.DefaultReporter({
            print: out.print,
            show_colors: false,
            timerFactory: timerSpy,
        });
    });

    it('reports that the suite has started to the console', function () {
        reporter.jasmineStarted();
        expect(out.getOutput()).toEqual('Started\n');
    });

    it('reports a passing spec as a dot', function () {
        reporter.specDone({status: 'passed'});
        expect(out.getOutput()).toEqual('.');
    });

    it('does not report a disabled spec', function () {
        reporter.specDone({status: 'disabled'});
        expect(out.getOutput()).toEqual('');
    });

    it('reports a failing spec as an "F"', function () {
        reporter.specDone({status: 'failed'});
        expect(out.getOutput()).toEqual('F');
    });

    it('reports a pending spec as a "*"', function () {
        reporter.specDone({status: 'pending'});
        expect(out.getOutput()).toEqual('*');
    });

    it('alerts user if there are no specs', function () {
        reporter.jasmineStarted();
        out.clear();
        reporter.jasmineDone();
        expect(out.getOutput()).toMatch(/No specs found/);
    });

    it('reports a summary when done (singular spec)', function () {
        reporter.jasmineStarted();
        reporter.specStarted({});
        reporter.specDone({status: 'passed'});

        timerSpies['main'].elapsed.and.returnValue(1000);

        out.clear();
        reporter.jasmineDone();

        expect(out.getOutput()).toMatch(/1 spec, 0 failed/);
        expect(out.getOutput()).not.toMatch(/0 pending/);
        expect(out.getOutput()).toMatch('Finished in 1 s\n');
    });

    it('reports a summary when done (pluralized specs)', function () {
        reporter.jasmineStarted();
        reporter.specStarted({});
        reporter.specDone({status: 'passed'});
        reporter.specStarted({});
        reporter.specDone({status: 'pending'});
        reporter.specStarted({});
        reporter.specDone({
            status: 'failed',
            description: 'with a failing spec',
            fullName: 'A suite with a failing spec',
            failedExpectations: [{
                passed: false,
                message: 'Expected true to be false.',
                expected: false,
                actual: true,
                stack: 'fakeStack\nfakeStack',
            }],
        });

        out.clear();

        timerSpies['main'].elapsed.and.returnValue(100);

        reporter.jasmineDone();

        expect(out.getOutput()).toMatch(/3 specs, 1 failed, 1 pending/);
        expect(out.getOutput()).toMatch('Finished in 0.1 s\n');
    });

    it('reports a summary when done that includes the failed spec number before the full name of a failing spec', function () {
        reporter.jasmineStarted();
        reporter.specDone({status: 'passed'});
        reporter.specDone({
            status: 'failed',
            description: 'with a failing spec',
            fullName: 'A suite with a failing spec',
            failedExpectations: [{
                passed: false,
                message: 'Expected true to be false.',
                expected: false,
                actual: true,
                stack: 'fakeStack\nfakeStack',
            }],
        });

        out.clear();

        reporter.jasmineDone();

        expect(out.getOutput()).toMatch(/1\) A suite with a failing spec/);
    });

    describe('with color', function () {
        beforeEach(function () {
            reporter = new ConsoleReporter.DefaultReporter({
                print: out.print,
                showColors: true,
            });
        });

        it('reports that the suite has started to the console', function () {
            reporter.jasmineStarted();
            expect(out.getOutput()).toEqual('Started\n');
        });

        it('reports a passing spec as a dot', function () {
            reporter.specDone({status: 'passed'});
            expect(out.getOutput()).toEqual('\x1B[32m.\x1B[0m');
        });

        it('does not report a disabled spec', function () {
            reporter.specDone({status: 'disabled'});
            expect(out.getOutput()).toEqual('');
        });

        it('reports a failing spec as an "F"', function () {
            reporter.specDone({status: 'failed'});
            expect(out.getOutput()).toEqual('\x1B[31mF\x1B[0m');
        });
    });

    it('displays all afterAll exceptions', function () {
        reporter.suiteDone({failedExpectations: [{message: 'After All Exception'}]});
        reporter.suiteDone({failedExpectations: [{message: 'Some Other Exception'}]});
        reporter.jasmineDone();

        expect(out.getOutput()).toMatch(/After All Exception/);
        expect(out.getOutput()).toMatch(/Some Other Exception/);
    });
});