-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
113 lines (94 loc) · 3.93 KB
/
test.js
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
'use strict';
const proxyquire = require('proxyquire');
const expect = require('chai').expect;
const sinon = require('sinon');
const util = require('util');
const reporter = proxyquire('./index', {util: util});
describe('reporter:teamcity', () => {
beforeEach(() => {
sinon.stub(process.stdout, 'write');
});
afterEach(() => {
if (process.stdout.write.restore) {
process.stdout.write.restore();
}
});
it('should not print anything when not passed any errors', () => {
const errors = [];
sinon.spy(console, 'log');
reporter.report(errors);
expect(console.log.called).to.equal(true);
expect(console.log.getCall(0).args[0]).to.equal('##teamcity[testSuiteStarted name=\'lesshint\']');
expect(console.log.getCall(1).args[0]).to.equal('##teamcity[testStarted name=\'lesshint\']');
expect(console.log.getCall(2).args[0]).to.equal('##teamcity[testFinished name=\'lesshint\']');
expect(console.log.getCall(3).args[0]).to.equal('##teamcity[testSuiteFinished name=\'lesshint\']');
console.log.restore();
});
it('print error for 1 file', () => {
const errors = [{
column: 5,
file: 'file.less',
fullPath: 'path/to/file.less',
line: 1,
linter: 'spaceBeforeBrace',
message: 'Opening curly brace should be preceded by one space.',
severity: 'error',
source: '.foo{ color: red; }'
}];
sinon.spy(console, 'log');
sinon.spy(util, 'format');
reporter.report(errors);
expect(console.log.called).to.equal(true);
expect(util.format.called).to.equal(true);
expect(console.log.getCall(1).args[0]).to.equal('##teamcity[testStarted name=\'path/to/file.less\']');
expect(console.log.getCall(2).args[0]).to.equal(
'##teamcity[testFailed name=\'path/to/file.less\' message=\'line 1, col 5,'
+ ' Error (spaceBeforeBrace) Opening curly brace should be preceded by one space.\']'
);
console.log.restore();
});
it('print errors for 2 files', () => {
const errors = [{
column: 5,
file: 'file.less',
fullPath: 'path/to/file.less',
line: 1,
linter: 'spaceBeforeBrace',
message: 'Opening curly brace should be preceded by one space.',
severity: 'error',
source: '.foo{ color: red; }'
}, {
column: 5,
file: 'file.less',
fullPath: 'path/to/file.less',
line: 1,
linter: 'spaceBeforeBrace',
message: 'Opening curly brace should be preceded by one space.',
severity: 'warning',
source: '.foo{ color: red; }'
}, {
column: 5,
file: 'file.less',
fullPath: 'path/to/another/file.less',
line: 1,
linter: 'spaceBeforeBrace',
message: 'Opening curly brace should be preceded by one space.',
severity: 'warning',
source: '.foo{ color: red; }'
}];
sinon.spy(console, 'log');
reporter.report(errors);
expect(console.log.called).to.equal(true);
expect(util.format.called).to.equal(true);
expect(console.log.getCall(1).args[0]).to.equal('##teamcity[testStarted name=\'path/to/file.less\']');
expect(console.log.getCall(2).args[0]).to.equal(
'##teamcity[testFailed name=\'path/to/file.less\' message=\'line 1, col 5,'
+ ' Error (spaceBeforeBrace) Opening curly brace should be preceded by one space.\']'
);
expect(console.log.getCall(6).args[0]).to.equal(
'##teamcity[testFailed name=\'path/to/another/file.less\' message=\'line 1, col 5,'
+ ' Warning (spaceBeforeBrace) Opening curly brace should be preceded by one space.\']'
);
console.log.restore();
});
});