-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
update.spec.ts
144 lines (121 loc) · 4.18 KB
/
update.spec.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
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
// TODO #22198
import { XmlDocument } from 'xmldoc';
import { Fixtures } from '../../../../test/fixtures';
import { bumpPackageVersion, updateDependency } from './update';
const simpleContent = Fixtures.get(`simple.pom.xml`);
const minimumContent = Fixtures.get(`minimum.pom.xml`);
const minimumSnapshotContent = Fixtures.get(`minimum_snapshot.pom.xml`);
const prereleaseContent = Fixtures.get(`prerelease.pom.xml`);
describe('modules/manager/maven/update', () => {
describe('updateDependency', () => {
it('should return null for replacement', () => {
const res = updateDependency({
fileContent: '',
upgrade: { updateType: 'replacement' },
});
expect(res).toBeNull();
});
});
describe('bumpPackageVersion', () => {
it('bumps pom.xml version', () => {
const { bumpedContent } = bumpPackageVersion(
simpleContent,
'0.0.1',
'patch',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('0.0.2');
});
it('bumps pom.xml version keeping SNAPSHOT', () => {
const { bumpedContent } = bumpPackageVersion(
minimumSnapshotContent,
'0.0.1-SNAPSHOT',
'patch',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('0.0.2-SNAPSHOT');
});
it('bumps pom.xml minor version keeping SNAPSHOT', () => {
const { bumpedContent } = bumpPackageVersion(
minimumSnapshotContent,
'0.0.1-SNAPSHOT',
'minor',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('0.1.0-SNAPSHOT');
});
it('bumps pom.xml major version keeping SNAPSHOT', () => {
const { bumpedContent } = bumpPackageVersion(
minimumSnapshotContent,
'0.0.1-SNAPSHOT',
'major',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('1.0.0-SNAPSHOT');
});
it('bumps pom.xml version keeping qualifier with -SNAPSHOT', () => {
const { bumpedContent } = bumpPackageVersion(
minimumSnapshotContent.replace(
'0.0.1-SNAPSHOT',
'0.0.1-qualified-SNAPSHOT',
),
'0.0.1-qualified-SNAPSHOT',
'patch',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('0.0.2-qualified-SNAPSHOT');
});
it('does not bump version twice', () => {
const { bumpedContent } = bumpPackageVersion(
simpleContent,
'0.0.1',
'patch',
);
const { bumpedContent: bumpedContent2 } = bumpPackageVersion(
bumpedContent!,
'0.0.1',
'patch',
);
expect(bumpedContent).toEqual(bumpedContent2);
});
it('does not bump version if version is not a semantic version', () => {
const { bumpedContent } = bumpPackageVersion(
minimumContent,
'1',
'patch',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('1');
});
it('does not bump version if pom.xml has no version', () => {
const { bumpedContent } = bumpPackageVersion(minimumContent, '', 'patch');
expect(bumpedContent).toEqual(minimumContent);
});
it('returns content if bumping errors', () => {
const { bumpedContent } = bumpPackageVersion(
simpleContent,
'0.0.1',
true as any,
);
expect(bumpedContent).toEqual(simpleContent);
});
it('bumps pom.xml version to SNAPSHOT with prerelease', () => {
const { bumpedContent } = bumpPackageVersion(
simpleContent,
'0.0.1',
'prerelease',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('0.0.2-SNAPSHOT');
});
it('bumps pom.xml version with prerelease semver level', () => {
const { bumpedContent } = bumpPackageVersion(
prereleaseContent,
'1.0.0-1',
'prerelease',
);
const project = new XmlDocument(bumpedContent!);
expect(project.valueWithPath('version')).toBe('1.0.0-2');
});
});
});