-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathpublishE2E.test.ts
More file actions
707 lines (561 loc) · 22.9 KB
/
publishE2E.test.ts
File metadata and controls
707 lines (561 loc) · 22.9 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
import { describe, expect, it, afterEach, jest } from '@jest/globals';
import fs from 'fs';
import path from 'path';
import { addGitObserver, clearGitObservers } from 'workspace-tools';
import { generateChangeFiles } from '../__fixtures__/changeFiles';
import { defaultBranchName, defaultRemoteBranchName } from '../__fixtures__/gitDefaults';
import { initMockLogs } from '../__fixtures__/mockLogs';
import { npmShow } from '../__fixtures__/npmShow';
import type { Repository } from '../__fixtures__/repository';
import { type PackageJsonFixture, RepositoryFactory } from '../__fixtures__/repositoryFactory';
import { publish } from '../commands/publish';
import type { RepoOptions } from '../types/BeachballOptions';
import { _mockNpmPublish, initNpmMock } from '../__fixtures__/mockNpm';
import type { PackageJson } from '../types/PackageInfo';
import { getParsedOptions } from '../options/getOptions';
import { getPackageInfos } from '../monorepo/getPackageInfos';
import { validate } from '../validation/validate';
import { readJson } from '../object/readJson';
// Spawning actual npm to run commands against a fake registry is extremely slow, so mock it for
// this test (packagePublish covers the more complete npm registry scenario).
//
// If an issue is found in the future that could only be caught by this test using real npm,
// a new test file with a real registry should be created to cover that specific scenario.
jest.mock('../packageManager/npm');
describe('publish command (e2e)', () => {
const npmMock = initNpmMock();
let repositoryFactory: RepositoryFactory | undefined;
let repo: Repository | undefined;
// show error logs for these tests
const logs = initMockLogs({ alsoLog: ['error'] });
function getOptionsAndPackages(repoOptions?: Partial<RepoOptions>, extraArgv?: string[]) {
const parsedOptions = getParsedOptions({
cwd: repo!.rootPath,
argv: ['node', 'beachball', 'publish', '--yes', ...(extraArgv || [])],
testRepoOptions: {
branch: defaultRemoteBranchName,
registry: 'fake',
message: 'apply package updates',
tag: 'latest',
access: 'public',
...repoOptions,
},
});
const packageInfos = getPackageInfos(parsedOptions);
return { packageInfos, options: parsedOptions.options, parsedOptions };
}
afterEach(() => {
clearGitObservers();
repositoryFactory?.cleanUp();
repositoryFactory = undefined;
repo = undefined;
});
it('can perform a successful npm publish', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages();
generateChangeFiles(['foo'], options);
repo.push();
// For this test, run validate first to simulate what the CLI does
validate(options, { checkDependencies: true }, packageInfos);
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['foo_v1.1.0']);
// Also verify it's correct on disk
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.foo.version).toBe('1.1.0');
});
it('can perform a successful npm publish in detached HEAD', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, packageInfos } = getOptionsAndPackages({
push: false,
});
generateChangeFiles(['foo'], options);
repo.push();
repo.checkout('--detach');
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
});
it('can perform a successful npm publish from a race condition', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, packageInfos } = getOptionsAndPackages();
generateChangeFiles(['foo'], options);
repo.push();
// Adds a step that injects a race condition
let fetchCount = 0;
addGitObserver(args => {
if (args[0] === 'fetch') {
if (fetchCount === 0) {
const anotherRepo = repositoryFactory!.cloneRepository();
// inject a checkin
anotherRepo.updateJsonFile('package.json', { version: '1.0.2' });
anotherRepo.push();
}
fetchCount++;
}
});
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['foo_v1.1.0']);
// this indicates 2 tries
expect(fetchCount).toBe(2);
// TODO: this uses the modified version 1.0.2, which is wrong because the bumped version is newer.
// Needs further investigation...
// const newPackageInfos = getPackageInfos(parsedOptions);
// expect(newPackageInfos.foo.version).toBe('1.1.0');
});
it('can perform a successful npm publish from a race condition in the dependencies', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages();
generateChangeFiles(['foo'], options);
repo.push();
// Adds a step that injects a race condition
let fetchCount = 0;
addGitObserver(args => {
if (args[0] === 'fetch') {
if (fetchCount === 0) {
const anotherRepo = repositoryFactory!.cloneRepository();
// inject a checkin
const packageJsonFile = anotherRepo.pathTo('package.json');
const contents = readJson<PackageJson>(packageJsonFile);
delete contents.dependencies?.baz;
anotherRepo.commitChange('package.json', JSON.stringify(contents, null, 2));
anotherRepo.push();
}
fetchCount++;
}
});
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['foo_v1.1.0']);
// this indicates 2 tries
expect(fetchCount).toBe(2);
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.foo.version).toBe('1.1.0');
expect(newPackageInfos.foo.dependencies?.baz).toBeUndefined();
});
it('can perform a successful npm publish without bump', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages({ bump: false });
generateChangeFiles(['foo'], options);
repo.push();
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.0.0'],
'dist-tags': { latest: '1.0.0' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual([]);
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.foo.version).toBe('1.0.0');
});
it('publishes only changed packages in a monorepo', async () => {
repositoryFactory = new RepositoryFactory('monorepo');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages();
generateChangeFiles(['foo'], options);
repo.push();
// For this test, run validate first to simulate what the CLI does
validate(options, { checkDependencies: true }, packageInfos);
await publish(options, packageInfos);
await npmShow('bar', { shouldFail: true });
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['foo_v1.1.0']);
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.foo.version).toBe('1.1.0');
});
it('publishes dependent packages in a monorepo', async () => {
repositoryFactory = new RepositoryFactory('monorepo');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages();
// bump baz => dependent bump bar => dependent bump foo
generateChangeFiles(['baz'], options);
expect(repositoryFactory.fixture.folders.packages.foo.dependencies!.bar).toBeTruthy();
expect(repositoryFactory.fixture.folders.packages.bar.dependencies!.baz).toBeTruthy();
repo.push();
// For this test, run validate first to simulate what the CLI does
validate(options, { checkDependencies: true }, packageInfos);
await publish(options, packageInfos);
expect(await npmShow('baz')).toMatchObject({
name: 'baz',
versions: ['1.4.0'],
'dist-tags': { latest: '1.4.0' },
});
expect(await npmShow('bar')).toMatchObject({
name: 'bar',
versions: ['1.3.5'],
'dist-tags': { latest: '1.3.5' },
dependencies: { baz: '^1.4.0' },
});
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.0.1'],
'dist-tags': { latest: '1.0.1' },
dependencies: { bar: '^1.3.5' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['bar_v1.3.5', 'baz_v1.4.0', 'foo_v1.0.1']);
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.foo.version).toBe('1.0.1');
expect(newPackageInfos.foo.dependencies!.bar).toBe('^1.3.5');
expect(newPackageInfos.bar.version).toBe('1.3.5');
expect(newPackageInfos.bar.dependencies!.baz).toBe('^1.4.0');
expect(newPackageInfos.baz.version).toBe('1.4.0');
});
it('publishes new monorepo packages if requested', async () => {
// use a slightly smaller fixture to only publish one extra package
repositoryFactory = new RepositoryFactory({
folders: {
packages: { foo: { version: '1.0.0' }, bar: { version: '1.3.4' } },
},
});
repo = repositoryFactory.cloneRepository();
const { options, packageInfos } = getOptionsAndPackages({
new: true,
});
generateChangeFiles(['foo'], options);
repo.push();
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({ name: 'foo', versions: ['1.1.0'] });
expect(await npmShow('bar')).toMatchObject({ name: 'bar', versions: ['1.3.4'] });
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['bar_v1.3.4', 'foo_v1.1.0']);
});
it('should not perform npm publish on out-of-scope package', async () => {
repositoryFactory = new RepositoryFactory('monorepo');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages({ scope: ['!packages/foo'] });
generateChangeFiles(['foo'], options);
generateChangeFiles(['bar'], options);
repo.push();
await publish(options, packageInfos);
await npmShow('foo', { shouldFail: true });
expect(repo.getCurrentTags()).toEqual([]);
expect(await npmShow('bar')).toMatchObject({
name: 'bar',
versions: ['1.4.0'],
'dist-tags': { latest: '1.4.0' },
});
repo.checkout(defaultBranchName);
repo.pull();
expect(repo.getCurrentTags()).toEqual(['bar_v1.4.0']);
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.bar.version).toBe('1.4.0');
expect(newPackageInfos.foo.version).toBe('1.0.0');
});
it('should respect prepublish hooks', async () => {
repositoryFactory = new RepositoryFactory('monorepo');
repo = repositoryFactory.cloneRepository();
type ExtraPackageJson = PackageJson & { onPublish?: { main: string } };
const { options, packageInfos } = getOptionsAndPackages({
hooks: {
prepublish: (packagePath: string) => {
const packageJsonPath = path.join(packagePath, 'package.json');
const packageJson = readJson<ExtraPackageJson>(packageJsonPath);
if (packageJson.onPublish) {
Object.assign(packageJson, packageJson.onPublish);
delete packageJson.onPublish;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
}
},
},
});
generateChangeFiles(['foo'], options);
repo.push();
await publish(options, packageInfos);
// Query the information from package.json from the registry to see if it was successfully patched
const show = (await npmShow('foo'))!;
expect(show.name).toEqual('foo');
expect(show.main).toEqual('lib/index.js');
expect(show).not.toHaveProperty('onPublish');
repo.checkout(defaultBranchName);
repo.pull();
// All git results should still have previous information
expect(repo.getCurrentTags()).toEqual(['foo_v1.1.0']);
const fooPackageJson = readJson<ExtraPackageJson>(repo.pathTo('packages/foo/package.json'));
expect(fooPackageJson.main).toBe('src/index.ts');
expect(fooPackageJson.onPublish?.main).toBe('lib/index.js');
});
it('should respect postpublish hooks', async () => {
repositoryFactory = new RepositoryFactory('monorepo');
repo = repositoryFactory.cloneRepository();
let notified;
type ExtraPackageJson = PackageJson & { afterPublish?: { notify: string } };
const { options, packageInfos } = getOptionsAndPackages({
hooks: {
postpublish: packagePath => {
const packageJsonPath = path.join(packagePath, 'package.json');
const packageJson = readJson<ExtraPackageJson>(packageJsonPath);
if (packageJson.afterPublish) {
notified = packageJson.afterPublish.notify;
}
},
},
});
generateChangeFiles(['foo'], options);
repo.push();
await publish(options, packageInfos);
const fooPackageJson = readJson<ExtraPackageJson>(repo.pathTo('packages/foo/package.json'));
expect(fooPackageJson.main).toBe('src/index.ts');
expect(notified).toBe(fooPackageJson.afterPublish?.notify);
});
it('can perform a successful npm publish without fetch', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, parsedOptions, packageInfos } = getOptionsAndPackages({
fetch: false,
});
generateChangeFiles(['foo'], options);
repo.push();
let fetchCount = 0;
addGitObserver(args => {
if (args[0] === 'fetch') {
fetchCount++;
}
});
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
// no fetch when flag set to false
expect(fetchCount).toBe(0);
repo.checkout(defaultBranchName);
repo.pull();
const newPackageInfos = getPackageInfos(parsedOptions);
expect(newPackageInfos.foo.version).toBe('1.1.0');
});
it('should specify fetch depth when depth param is defined', async () => {
repositoryFactory = new RepositoryFactory('single');
repo = repositoryFactory.cloneRepository();
const { options, packageInfos } = getOptionsAndPackages({
depth: 10,
});
generateChangeFiles(['foo'], options);
repo.push();
let fetchCommand = '';
addGitObserver(args => {
if (args[0] === 'fetch') {
fetchCommand = args.join(' ');
}
});
await publish(options, packageInfos);
expect(await npmShow('foo')).toMatchObject({
name: 'foo',
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
expect(fetchCommand).toMatch('--depth=10');
});
it('calls precommit hook before committing changes', async () => {
repositoryFactory = new RepositoryFactory('monorepo');
repo = repositoryFactory.cloneRepository();
const { options, packageInfos } = getOptionsAndPackages({
hooks: {
precommit: async cwd => {
await new Promise(resolve => {
fs.writeFile(path.resolve(cwd, 'foo.txt'), 'foo', resolve);
});
},
},
});
generateChangeFiles(['foo'], options);
repo.push();
await publish(options, packageInfos);
repo.checkout(defaultBranchName);
repo.pull();
// All git results should still have previous information
expect(repo.getCurrentTags()).toEqual(['foo_v1.1.0']);
const fooText = fs.readFileSync(repo.pathTo('foo.txt'), 'utf8');
expect(fooText).toEqual('foo');
});
it('publishes multiple packages concurrently respecting the concurrency limit', async () => {
const packagesToPublish = ['pkg1', 'pkg2', 'pkg3', 'pkg4', 'pkg5', 'pkg6', 'pkg7', 'pkg8', 'pkg9'];
const packages: { [packageName: string]: PackageJsonFixture } = {};
for (const name of packagesToPublish) {
packages[name] = { version: '1.0.0' };
}
repositoryFactory = new RepositoryFactory({
folders: {
packages: packages,
},
});
repo = repositoryFactory.cloneRepository();
const concurrency = 2;
const { options, packageInfos } = getOptionsAndPackages({ concurrency });
generateChangeFiles(packagesToPublish, options);
repo.push();
const simulateWait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
let currentConcurrency = 0;
let maxConcurrency = 0;
npmMock.setCommandOverride('publish', async (registryData, args, opts) => {
currentConcurrency++;
await simulateWait(100);
const result = await _mockNpmPublish(registryData, args, opts);
maxConcurrency = Math.max(maxConcurrency, currentConcurrency);
currentConcurrency--;
return result;
});
await publish(options, packageInfos);
// Verify that at most `concurrency` number of packages were published concurrently
expect(maxConcurrency).toBe(concurrency);
// Verify all packages were published
for (const pkg of packagesToPublish) {
expect(await npmShow(pkg)).toMatchObject({
name: pkg,
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
}
repo.checkout(defaultBranchName);
repo.pull();
const expectedTags = packagesToPublish.map(pkg => `${pkg}_v1.1.0`);
// Verify all tags were updated
expect(repo.getCurrentTags().sort()).toEqual(expectedTags.sort());
});
it('handles errors correctly when one of the packages fails during concurrent publishing', async () => {
logs.setOverrideOptions({ alsoLog: [] });
const packageNames = ['pkg1', 'pkg2', 'pkg3', 'pkg4', 'pkg5', 'pkg6', 'pkg7', 'pkg8'];
const packages: { [packageName: string]: PackageJsonFixture } = {};
const packageToFail = 'pkg4';
for (const name of packageNames) {
packages[name] = { version: '1.0.0' };
}
packages['pkg8'].dependencies = { [packageToFail]: '1.0.0' };
packages['pkg7'].dependencies = { [packageToFail]: '1.0.0' };
repositoryFactory = new RepositoryFactory({
folders: {
packages: packages,
},
});
repo = repositoryFactory.cloneRepository();
const { options, packageInfos } = getOptionsAndPackages({ concurrency: 3 });
generateChangeFiles(packageNames, options);
repo.push();
npmMock.setCommandOverride('publish', async (registryData, args, opts) => {
if (opts.cwd?.endsWith(packageToFail)) {
return {
failed: true,
stderr: 'Failed to publish package',
stdout: '',
success: false,
all: 'Failed to publish package',
};
}
return _mockNpmPublish(registryData, args, opts);
});
await expect(publish(options, packageInfos)).rejects.toThrow(
'Error publishing! Refer to the previous logs for recovery instructions.'
);
for (const name of packageNames) {
if (['pkg7', 'pkg8', packageToFail].includes(name)) {
// Verify that the packages that failed to publish are not published
// pkg7 and pkg8 are not published because they depend on pkg4 and pkg4 failed to publish
await npmShow(name, { shouldFail: true });
} else {
// Verify that the packages that did not fail to publish are published
expect(await npmShow(name)).toMatchObject({
name: name,
versions: ['1.1.0'],
'dist-tags': { latest: '1.1.0' },
});
}
}
});
it('should respect postpublish hook respecting the concurrency limit when publishing multiple packages concurrently', async () => {
const packagesToPublish = ['pkg1', 'pkg2', 'pkg3', 'pkg4', 'pkg5', 'pkg6', 'pkg7', 'pkg8', 'pkg9'];
type ExtraPackageJsonFixture = PackageJsonFixture & { afterPublish?: { notify: string } };
const packages: { [packageName: string]: ExtraPackageJsonFixture } = {};
for (const name of packagesToPublish) {
packages[name] = {
version: '1.0.0',
afterPublish: {
notify: `message-${name}`,
},
};
}
repositoryFactory = new RepositoryFactory({
folders: {
packages: packages,
},
});
repo = repositoryFactory.cloneRepository();
const simulateWait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
const afterPublishStrings: { packageName: string; notify: string }[] = [];
const concurrency = 2;
let currentConcurrency = 0;
let maxConcurrency = 0;
const { options, packageInfos } = getOptionsAndPackages({
hooks: {
postpublish: async packagePath => {
currentConcurrency++;
await simulateWait(100);
const packageName = path.basename(packagePath);
const packageJsonPath = path.join(packagePath, 'package.json');
const packageJson = readJson<ExtraPackageJsonFixture>(packageJsonPath);
if (packageJson.afterPublish) {
afterPublishStrings.push({
packageName,
notify: packageJson.afterPublish.notify,
});
}
maxConcurrency = Math.max(maxConcurrency, currentConcurrency);
currentConcurrency--;
},
},
concurrency: concurrency,
});
generateChangeFiles(packagesToPublish, options);
repo.push();
await publish(options, packageInfos);
// Verify that at most `concurrency` number of postpublish hooks were running concurrently
expect(maxConcurrency).toBe(concurrency);
for (const pkg of packagesToPublish) {
const packageJson = readJson<ExtraPackageJsonFixture>(repo.pathTo(`packages/${pkg}/package.json`));
if (packageJson.afterPublish) {
// Verify that all postpublish hooks were called
expect(afterPublishStrings).toContainEqual({
packageName: pkg,
notify: packageJson.afterPublish.notify,
});
}
}
});
});