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
|
import { formatFilePath, formattedTime } from '~/ci/pipeline_details/stores/test_reports/utils';
describe('Test reports utils', () => {
describe('formatFilePath', () => {
it.each`
file | expected
${'./test.js'} | ${'test.js'}
${'/test.js'} | ${'test.js'}
${'.//////////////test.js'} | ${'test.js'}
${'test.js'} | ${'test.js'}
${'mock/path./test.js'} | ${'mock/path./test.js'}
${'./mock/path./test.js'} | ${'mock/path./test.js'}
`('should format $file to be $expected', ({ file, expected }) => {
expect(formatFilePath(file)).toBe(expected);
});
});
describe('formattedTime', () => {
describe('when time is smaller than a second', () => {
it('should return time in milliseconds fixed to 2 decimals', () => {
const result = formattedTime(0.4815162342);
expect(result).toBe('481.52ms');
});
});
describe('when time is equal to a second', () => {
it('should return time in seconds fixed to 2 decimals', () => {
const result = formattedTime(1);
expect(result).toBe('1.00s');
});
});
describe('when time is greater than a second', () => {
it('should return time in seconds fixed to 2 decimals', () => {
const result = formattedTime(4.815162342);
expect(result).toBe('4.82s');
});
});
describe('when time is greater than a minute', () => {
it('should return time in minutes', () => {
const result = formattedTime(99);
expect(result).toBe('1m 39s');
});
});
describe('when time is greater than a hour', () => {
it('should return time in hours', () => {
const result = formattedTime(3606);
expect(result).toBe('1h 6s');
});
});
describe('when time is exact a hour', () => {
it('should return time as one hour', () => {
const result = formattedTime(3600);
expect(result).toBe('1h');
});
});
describe('when time is greater than a hour with some minutes', () => {
it('should return time in hours', () => {
const result = formattedTime(3662);
expect(result).toBe('1h 1m 2s');
});
});
});
});
|