-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
module-label.test.ts
50 lines (48 loc) · 1.52 KB
/
module-label.test.ts
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
import { expect, test } from 'vitest'
import { calcExternalLabels, createModuleLabelItem } from '../../../packages/ui/client/composables/module-graph'
const getExternalLabelsObj = (modules: string[]) => {
const labels = modules.map(module => createModuleLabelItem(module))
return Object.fromEntries(calcExternalLabels(labels))
}
test('calculate label of external module', () => {
const modules1: string[] = []
expect(getExternalLabelsObj(modules1)).toEqual({})
const modules2 = ['']
expect(getExternalLabelsObj(modules2)).toEqual({ '': '' })
const modules3 = [
'org/testA',
'org/testB',
]
expect(getExternalLabelsObj(modules3)).toEqual({
'org/testA': 'org/testA',
'org/testB': 'org/testB',
})
const modules4 = [...modules3, 'org/testC']
expect(getExternalLabelsObj(modules4)).toEqual({
'org/testA': 'org/testA',
'org/testB': 'org/testB',
'org/testC': 'org/testC',
})
const modules5 = [
'orgA',
'orgB',
]
expect(getExternalLabelsObj(modules5)).toEqual({
orgA: 'orgA',
orgB: 'orgB',
})
const modules6 = ['orgA', 'orgB', 'orgA/dist']
expect(getExternalLabelsObj(modules6)).toEqual({
'orgA': 'orgA',
'orgB': 'orgB',
'orgA/dist': 'orgA/dist',
})
const modules7 = [
'@testing-library/jest-dom/dist/index.js',
'@testing-library/react/dist/index.js',
]
expect(getExternalLabelsObj(modules7)).toEqual({
'@testing-library/jest-dom/dist/index.js': '@testing-library/jest-dom',
'@testing-library/react/dist/index.js': '@testing-library/react',
})
})