-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathoutdated-result.unit.test.ts
More file actions
147 lines (134 loc) · 3.65 KB
/
outdated-result.unit.test.ts
File metadata and controls
147 lines (134 loc) · 3.65 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { describe, expect, it } from 'vitest';
import { toJsonLines } from '@code-pushup/utils';
import type {
OutdatedDependency,
OutdatedResult,
} from '../../runner/outdated/types.js';
import { REQUIRED_OUTDATED_FIELDS } from './constants.js';
import {
getOutdatedFieldIndexes,
validateOutdatedFields,
yarnClassicToOutdatedResult,
} from './outdated-result.js';
import type { YarnClassicFieldName } from './types.js';
describe('yarnClassicToOutdatedResult', () => {
const yarnInfo = { type: 'info', data: 'Colours' };
it('should transform Yarn v1 outdated to unified outdated result', () => {
const table = {
type: 'table',
data: {
head: [
'Package',
'Current',
'Latest',
'Package Type',
'URL',
] satisfies YarnClassicFieldName[],
body: [['nx', '16.8.1', '17.0.0', 'dependencies', 'https://nx.dev/']],
},
};
expect(
yarnClassicToOutdatedResult(toJsonLines([yarnInfo, table])),
).toEqual<OutdatedResult>([
{
name: 'nx',
current: '16.8.1',
latest: '17.0.0',
type: 'dependencies',
url: 'https://nx.dev/',
},
]);
});
it('should adapt to custom fields and order', () => {
const table = {
type: 'table',
data: {
head: [
'Latest',
'Package Type',
'Package',
'Workspaces', // irrelevant
'Current',
'Wanted', // irrelevant
],
body: [
['13.6.0', 'devDependencies', 'cypress', 'cli', '11.1.1', '13.0.0'],
],
},
};
expect(
yarnClassicToOutdatedResult(toJsonLines([yarnInfo, table])),
).toEqual<OutdatedResult>([
{
name: 'cypress',
current: '11.1.1',
latest: '13.6.0',
type: 'devDependencies',
},
]);
});
it('should transform no dependencies to empty array', () => {
const table = { type: 'table', data: { head: [], body: [] } };
expect(yarnClassicToOutdatedResult(toJsonLines([yarnInfo, table]))).toEqual(
[],
);
});
});
describe('validateOutdatedFields', () => {
it('should consider all required fields as valid', () => {
expect(validateOutdatedFields(REQUIRED_OUTDATED_FIELDS)).toBe(true);
});
it('should consider optional fields valid', () => {
expect(validateOutdatedFields([...REQUIRED_OUTDATED_FIELDS, 'URL'])).toBe(
true,
);
});
it('should throw for missing required fields', () => {
expect(() => validateOutdatedFields(['Package', 'Current'])).toThrow(
'does not contain all required fields',
);
});
});
describe('getOutdatedFieldIndexes', () => {
it('should return relevant fields with their index', () => {
expect(
getOutdatedFieldIndexes([...REQUIRED_OUTDATED_FIELDS, 'URL']),
).toStrictEqual<Record<keyof OutdatedDependency, number>>({
name: 0,
current: 1,
latest: 2,
type: 3,
url: 4,
});
});
it('should tag missing optional fields as -1', () => {
expect(
getOutdatedFieldIndexes(['Package', 'Current', 'Latest', 'Package Type']),
).toStrictEqual<Record<keyof OutdatedDependency, number>>({
name: 0,
current: 1,
latest: 2,
type: 3,
url: -1,
});
});
it('should skip additional fields', () => {
expect(
getOutdatedFieldIndexes([
'Latest',
'URL',
'Package Type',
'Package',
'Workspaces', // irrelevant
'Current',
'Wanted', // irrelevant
]),
).toStrictEqual<Record<keyof OutdatedDependency, number>>({
latest: 0,
url: 1,
type: 2,
name: 3,
current: 5,
});
});
});