-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
99 lines (90 loc) · 3.1 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
/*! @license
* Karma GitHub Actions Reporter Tests
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const {parseFormattedError, GitHubActionsReporter} = require('./index.js');
describe('parseFormattedError', () => {
it('extracts file and line numbers', () => {
const text = 'Error: Expected 0 to be 1.\n' +
' at <Jasmine>\n' +
' at Bar (test/foo.js:11:15)\n' +
' at <Jasmine>\n';
expect(parseFormattedError(text)).toEqual({
message: 'Error: Expected 0 to be 1.',
file: 'test/foo.js',
line: '11',
column: '15',
});
});
// When using Babel and sourcemaps, the line number info is different.
it('extracts file and line numbers in sourcemapped format', () => {
const text = 'Error: Expected 0 to be 1.\n' +
' at <Jasmine>\n' +
' at Bar (test/foo.js:11:15 <- test/foo.js:867:5309)\n' +
' at <Jasmine>\n';
expect(parseFormattedError(text)).toEqual({
message: 'Error: Expected 0 to be 1.',
file: 'test/foo.js',
line: '11',
column: '15',
});
});
it('still returns the message when there are no useful line numbers', () => {
const text = 'Error: Expected 0 to be 1.\n' +
' at <Jasmine>\n';
expect(parseFormattedError(text)).toEqual({
message: 'Error: Expected 0 to be 1.',
});
});
});
describe('GitHubActionsReporter', () => {
const fakeDecorator = () => {};
const fakeFormatError = (error) => error;
const fakeBrowser = {name: 'Chrome (Linux)'};
it('reports spec errors via GitHub Actions workflow commands', () => {
const config = {
githubActionsReporter: {
outputCallback: jasmine.createSpy('outputCallback'),
},
};
const reporter = new GitHubActionsReporter(
fakeDecorator, fakeFormatError, config);
const result = {
fullName: 'Foo can Bar',
log: [
'Error: Expected 0 to be 1.\n' +
' at <Jasmine>\n' +
' at Bar (test/foo.js:11:15 <- test/foo.js:867:5309)\n' +
' at <Jasmine>\n',
],
};
reporter.specFailure(fakeBrowser, result);
expect(config.githubActionsReporter.outputCallback).toHaveBeenCalledWith(
'::error file=test/foo.js,line=11,col=15::' +
'Foo can Bar FAILED: Error: Expected 0 to be 1.');
});
it('reports spec errors with browser name', () => {
const config = {
githubActionsReporter: {
outputCallback: jasmine.createSpy('outputCallback'),
showBrowser: true,
},
};
const reporter = new GitHubActionsReporter(
fakeDecorator, fakeFormatError, config);
const result = {
fullName: 'Foo can Bar',
log: [
'Error: Expected 0 to be 1.\n' +
' at <Jasmine>\n' +
' at Bar (test/foo.js:11:15 <- test/foo.js:867:5309)\n' +
' at <Jasmine>\n',
],
};
reporter.specFailure(fakeBrowser, result);
expect(config.githubActionsReporter.outputCallback).toHaveBeenCalledWith(
'::error file=test/foo.js,line=11,col=15::' +
'Chrome (Linux) Foo can Bar FAILED: Error: Expected 0 to be 1.');
});
});