-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathformat.test.ts
More file actions
98 lines (89 loc) · 2.58 KB
/
format.test.ts
File metadata and controls
98 lines (89 loc) · 2.58 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
88
89
90
91
92
93
94
95
96
97
98
import type { ModuleDest, ModuleTreeNode } from '../../../shared/types/data'
import { describe, expect, it } from 'vitest'
import { bytesToHumanSize, getContentByteSize, toTree } from '../format'
describe('bytesToHumanSize', () => {
it('should return raw bytes (<1000)', () => {
expect(bytesToHumanSize(10)).toEqual([10, 'B'])
})
it('should return kb with proper digits', () => {
expect(bytesToHumanSize(1000)).toEqual(['1', 'kB'])
expect(bytesToHumanSize(1000 * 1.5)).toEqual(['1.5', 'kB'])
expect(bytesToHumanSize(1000 * 1.666, 1)).toEqual(['1.7', 'kB'])
})
it('should return mb with proper digits', () => {
expect(bytesToHumanSize(1000 * 1000)).toEqual(['1', 'MB'])
expect(bytesToHumanSize(1000 * 1000 * 1.5)).toEqual(['1.5', 'MB'])
expect(bytesToHumanSize(1000 * 1000 * 1.666, 1)).toEqual(['1.7', 'MB'])
})
// larger...
})
describe('getContentByteSize', () => {
it('should return 0 with empty string', () => {
expect(getContentByteSize('')).toBe(0)
})
it('should return bytes', () => {
expect(getContentByteSize('vite')).toBe(4)
})
})
describe('toTree', () => {
it('should work with empty modules', () => {
expect(toTree([], 'Root')).toEqual({
name: 'Root',
children: {},
items: [],
})
})
it('should work', () => {
const modules: ModuleDest[] = [
{
full: '/path/to/project/dist/src/components/Button.js',
path: 'src/components/Button.js',
},
{
full: '/path/to/project/dist/src/utils/helper.js',
path: 'src/utils/helper.js',
},
{
full: '/path/to/project/dist/index.js',
path: 'index.js',
},
]
expect(toTree(modules, 'Root')).toEqual({
name: 'Root',
children: {
src: {
name: 'src',
children: {
components: {
name: 'components',
children: {},
items: [
{
full: '/path/to/project/dist/src/components/Button.js',
path: 'src/components/Button.js',
},
],
},
utils: {
name: 'utils',
children: {},
items: [
{
full: '/path/to/project/dist/src/utils/helper.js',
path: 'src/utils/helper.js',
},
],
},
},
items: [],
},
},
items: [
{
full: '/path/to/project/dist/index.js',
path: 'index.js',
},
],
} satisfies ModuleTreeNode)
})
})