-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgroup.spec.ts
More file actions
80 lines (70 loc) · 2.54 KB
/
group.spec.ts
File metadata and controls
80 lines (70 loc) · 2.54 KB
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
import { groupStart } from './group'
const CI = {
isCI: true,
GITHUB_ACTIONS: false,
GITLAB: false,
TRAVIS: false,
AZURE_PIPELINES: false,
BUILDKITE: false,
};
jest.mock('ci-info', () => CI)
const originalWrite = process.stdout.write.bind(process.stdout)
beforeEach(() => {
process.stdout.write = jest.fn()
})
afterEach(() => {
CI.GITHUB_ACTIONS = false
CI.GITLAB = false
CI.TRAVIS = false
CI.AZURE_PIPELINES = false
CI.BUILDKITE = false
process.stdout.write = originalWrite
})
test('groups for GitHub', () => {
CI.GITHUB_ACTIONS = true
const groupEnd = groupStart('foo')!
expect(process.stdout.write).toHaveBeenCalledWith('::group::foo\r\n');
expect(process.stdout.write).toHaveBeenCalledTimes(1)
groupEnd()
expect(process.stdout.write).toHaveBeenCalledWith('::endgroup::\r\n')
expect(process.stdout.write).toHaveBeenCalledTimes(2)
})
test('groups for GitLab', () => {
CI.GITLAB = true
const DATE_NOW_MOCK = new Date('2023-10-20T12:00:00Z').getTime();
const timestamp = Math.floor(DATE_NOW_MOCK / 1000)
jest.spyOn(Date, 'now').mockImplementation(() => DATE_NOW_MOCK);
const groupEnd = groupStart('foo')!
expect(process.stdout.write).toHaveBeenCalledWith(`\x1b[0Ksection_start:${timestamp}:1\r\x1b[0Kfoo\n`);
expect(process.stdout.write).toHaveBeenCalledTimes(1)
groupEnd()
expect(process.stdout.write).toHaveBeenCalledWith(`\x1b[0Ksection_end:${timestamp}:1\r\x1b[0K\n`)
expect(process.stdout.write).toHaveBeenCalledTimes(2)
})
test('groups for Travis', () => {
CI.TRAVIS = true
const groupEnd = groupStart('foo')!
expect(process.stdout.write).toHaveBeenCalledWith('travis_fold:start:foo\r\n');
expect(process.stdout.write).toHaveBeenCalledTimes(1)
groupEnd()
expect(process.stdout.write).toHaveBeenCalledWith('travis_fold:end:foo\r\n')
expect(process.stdout.write).toHaveBeenCalledTimes(2)
})
test('groups for Azure', () => {
CI.AZURE_PIPELINES = true
const groupEnd = groupStart('foo')!
expect(process.stdout.write).toHaveBeenCalledWith('##[group]foo\r\n');
expect(process.stdout.write).toHaveBeenCalledTimes(1)
groupEnd()
expect(process.stdout.write).toHaveBeenCalledWith('##[endgroup]\r\n')
expect(process.stdout.write).toHaveBeenCalledTimes(2)
})
test('groups for Buildkite', () => {
CI.BUILDKITE = true
const groupEnd = groupStart('foo')!
expect(process.stdout.write).toHaveBeenCalledWith('--- foo\r\n');
expect(process.stdout.write).toHaveBeenCalledTimes(1)
groupEnd()
expect(process.stdout.write).toHaveBeenCalledWith('\r\n')
expect(process.stdout.write).toHaveBeenCalledTimes(2)
})