-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathpublishGit.test.ts
More file actions
171 lines (148 loc) · 4.81 KB
/
publishGit.test.ts
File metadata and controls
171 lines (148 loc) · 4.81 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { RepositoryFactory } from '../fixtures/repository';
import { bumpAndPush } from '../publish/bumpAndPush';
import { publish } from '../commands/publish';
import path from 'path';
import fs from 'fs-extra';
import { writeChangeFiles } from '../changefile/writeChangeFiles';
import { git, gitFailFast } from 'workspace-tools';
import { gatherBumpInfo } from '../bump/gatherBumpInfo';
import { BeachballOptions } from '../types/BeachballOptions';
import { ChangeFileInfo } from '../types/ChangeInfo';
import { getPackageInfos } from '../monorepo/getPackageInfos';
describe('publish command (git)', () => {
let repositoryFactory: RepositoryFactory;
beforeAll(() => {
jest.setTimeout(30000);
});
beforeEach(() => {
repositoryFactory = new RepositoryFactory();
repositoryFactory.create();
});
afterEach(() => {
repositoryFactory.cleanUp();
});
it('can perform a successful git push', async () => {
const repo = repositoryFactory.cloneRepository();
writeChangeFiles({
changes: [
{
type: 'minor',
comment: 'test',
email: 'test@test.com',
packageName: 'foo',
dependentChangeType: 'patch',
},
],
cwd: repo.rootPath,
});
git(['push', 'origin', 'master'], { cwd: repo.rootPath });
await publish({
all: false,
authType: 'authtoken',
branch: 'origin/master',
command: 'publish',
message: 'apply package updates',
path: repo.rootPath,
publish: false,
bumpDeps: false,
push: true,
registry: 'http://localhost:99999/',
gitTags: true,
tag: 'latest',
token: '',
new: false,
yes: true,
access: 'public',
package: 'foo',
changehint: 'Run "beachball change" to create a change file',
type: null,
useConventionalCommits: false,
fetch: true,
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
generateChangelog: true,
dependentChangeType: null,
});
const newRepo = repositoryFactory.cloneRepository();
const packageJson = fs.readJSONSync(path.join(newRepo.rootPath, 'package.json'));
expect(packageJson.version).toBe('1.1.0');
});
it('can handle a merge when there are change files present', async () => {
// 1. clone a new repo1, write a change file in repo1
const repo1 = repositoryFactory.cloneRepository();
writeChangeFiles({
changes: [
{
type: 'minor',
comment: 'test',
email: 'test@test.com',
packageName: 'foo',
dependentChangeType: 'patch',
},
],
cwd: repo1.rootPath,
});
git(['push', 'origin', 'master'], { cwd: repo1.rootPath });
// 2. simulate the start of a publish from repo1
const publishBranch = 'publish_test';
gitFailFast(['checkout', '-b', publishBranch], { cwd: repo1.rootPath });
console.log('Bumping version for npm publish');
const options: BeachballOptions = {
all: false,
authType: 'authtoken',
branch: 'origin/master',
command: 'publish',
message: 'apply package updates',
path: repo1.rootPath,
publish: false,
bumpDeps: false,
push: true,
registry: 'http://localhost:99999/',
gitTags: true,
tag: 'latest',
token: '',
yes: true,
new: false,
access: 'public',
package: 'foo',
changehint: 'Run "beachball change" to create a change file',
type: null,
useConventionalCommits: false,
fetch: true,
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
generateChangelog: true,
dependentChangeType: null,
};
const bumpInfo = gatherBumpInfo(options, getPackageInfos(repo1.rootPath));
// 3. Meanwhile, in repo2, also create a new change file
const repo2 = repositoryFactory.cloneRepository();
writeChangeFiles({
changes: [
{
type: 'minor',
comment: 'test',
email: 'test@test.com',
packageName: 'foo2',
dependentChangeType: 'patch',
},
],
cwd: repo2.rootPath,
});
git(['push', 'origin', 'master'], { cwd: repo2.rootPath });
// 4. Pretend to continue on with repo1's publish
await bumpAndPush(bumpInfo, publishBranch, options);
// 5. In a brand new cloned repo, make assertions
const newRepo = repositoryFactory.cloneRepository();
const newChangePath = path.join(newRepo.rootPath, 'change');
expect(fs.existsSync(newChangePath)).toBeTruthy();
const changeFiles = fs.readdirSync(newChangePath);
expect(changeFiles.length).toBe(1);
const changeFileContent: ChangeFileInfo = fs.readJSONSync(path.join(newChangePath, changeFiles[0]));
expect(changeFileContent.packageName).toBe('foo2');
});
});