-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathutils.spec.js
More file actions
87 lines (77 loc) · 2.67 KB
/
Copy pathutils.spec.js
File metadata and controls
87 lines (77 loc) · 2.67 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
81
82
83
84
85
86
87
import { toBool, getDeltaText, iconForDifference, diffTable, fileExists, stripHash } from '../src/utils.js';
test('toBool', () => {
expect(toBool('1')).toBe(true);
expect(toBool('true')).toBe(true);
expect(toBool('yes')).toBe(true);
expect(toBool('0')).toBe(false);
expect(toBool('false')).toBe(false);
expect(toBool('no')).toBe(false);
});
test('getDeltaText', () => {
expect(getDeltaText(5000, 20000)).toBe('+5 kB (+25%)');
expect(getDeltaText(-5000, 20000)).toBe('-5 kB (-25%)');
expect(getDeltaText(210, 0)).toBe('+210 B (new file)');
expect(getDeltaText(0, 0)).toBe('0 B');
expect(getDeltaText(4875, 20000)).toBe('+4.88 kB (+24.38%)');
expect(getDeltaText(-4875, 20000)).toBe('-4.88 kB (-24.38%)');
});
test('iconForDifference', () => {
expect(iconForDifference(0, 5000)).toBe('');
expect(iconForDifference(5500, 5000)).toBe('🆘');
expect(iconForDifference(-550, 5000)).toBe('👏');
});
test('diffTable', () => {
const files = [
{
filename: 'one.js',
size: 5000,
delta: 2500
},
{
filename: 'two.js',
size: 5000,
delta: -2500
},
{
filename: 'three.js',
size: 300,
delta: 0
},
{
filename: 'four.js',
size: 4500,
delta: 9
},
{
filename: 'five.js',
size: 6500,
delta: 0
},
];
const defaultOptions = {
showTotal: true,
collapseUnchanged: true,
omitUnchanged: false,
minimumChangeThreshold: 1,
sortBy: /** @type {const} */ ('Filename:asc')
};
expect(diffTable(files, { ...defaultOptions })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, showTotal: false })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, collapseUnchanged: false })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, omitUnchanged: true })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, minimumChangeThreshold: 10 })).toMatchSnapshot();
expect(diffTable(files.map(file => ({ ...file, delta: 0 })), { ...defaultOptions })).toMatchSnapshot();
expect(diffTable([files[2]], { ...defaultOptions })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, sortBy: 'Filename:desc' })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, sortBy: 'Size:asc' })).toMatchSnapshot();
expect(diffTable(files, { ...defaultOptions, sortBy: 'Change:desc' })).toMatchSnapshot();
});
test('fileExists', async () => {
expect(await fileExists('package.json')).toBe(true);
expect(await fileExists('file-that-does-not-exist')).toBe(false);
});
test('stripHash', () => {
expect(stripHash('\\b\\w{5}\\.')('foo.abcde.js')).toBe('foo.js');
expect(stripHash('\\.(\\w{5})\\.chunk\\.js$')('foo.abcde.chunk.js')).toBe('foo.*****.chunk.js');
expect(stripHash('')).toBe(undefined);
});