|
1 | 1 | import { describe, expect, it, afterEach, jest } from '@jest/globals'; |
2 | 2 | import fs from 'fs'; |
3 | 3 | import path from 'path'; |
4 | | -import { addGitObserver, clearGitObservers } from 'workspace-tools'; |
| 4 | +import { addGitObserver, catalogsToYaml, clearGitObservers, type Catalogs } from 'workspace-tools'; |
5 | 5 | import { generateChangeFiles, getChangeFiles } from '../__fixtures__/changeFiles'; |
6 | 6 | import { defaultBranchName, defaultRemoteBranchName } from '../__fixtures__/gitDefaults'; |
7 | 7 | import { initMockLogs } from '../__fixtures__/mockLogs'; |
8 | 8 | import type { Repository } from '../__fixtures__/repository'; |
9 | | -import { type PackageJsonFixture, RepositoryFactory } from '../__fixtures__/repositoryFactory'; |
| 9 | +import { type PackageJsonFixture, type RepoFixture, RepositoryFactory } from '../__fixtures__/repositoryFactory'; |
10 | 10 | import { publish } from '../commands/publish'; |
11 | 11 | import type { ParsedOptions, RepoOptions } from '../types/BeachballOptions'; |
12 | 12 | import { _mockNpmPublish, initNpmMock } from '../__fixtures__/mockNpm'; |
@@ -62,6 +62,7 @@ describe('publish command (e2e)', () => { |
62 | 62 | deepFreezeProperties(context.bumpInfo); |
63 | 63 | deepFreezeProperties(context.originalPackageInfos); |
64 | 64 | await publish(parsedOptions.options, context); |
| 65 | + return context; |
65 | 66 | } |
66 | 67 |
|
67 | 68 | afterEach(() => { |
@@ -334,6 +335,113 @@ describe('publish command (e2e)', () => { |
334 | 335 | expect(newPackageInfos.foo.version).toBe('1.0.0'); |
335 | 336 | }); |
336 | 337 |
|
| 338 | + // Combine workspace/catalog/file cases since these tests are slow |
| 339 | + it('publishes packages with workspace: and catalog: deps and replaces versions', async () => { |
| 340 | + const monorepo: RepoFixture['folders'] = { |
| 341 | + packages: { |
| 342 | + 'pkg-1': { version: '1.0.0' }, |
| 343 | + 'pkg-2': { version: '1.0.0', dependencies: { 'pkg-1': 'workspace:~' } }, |
| 344 | + 'pkg-3': { version: '1.0.0', dependencies: { 'pkg-2': 'workspace:^1.0.0' } }, |
| 345 | + 'pkg-4': { |
| 346 | + version: '1.0.0', |
| 347 | + dependencies: { 'pkg-1': 'catalog:' }, |
| 348 | + devDependencies: { 'pkg-2': 'file:../pkg-2' }, |
| 349 | + }, |
| 350 | + }, |
| 351 | + }; |
| 352 | + const catalogs: Catalogs = { |
| 353 | + default: { 'pkg-1': 'workspace:~' }, |
| 354 | + }; |
| 355 | + repositoryFactory = new RepositoryFactory({ |
| 356 | + folders: monorepo, |
| 357 | + extraFiles: { '.yarnrc.yml': catalogsToYaml(catalogs) }, |
| 358 | + }); |
| 359 | + repo = repositoryFactory.cloneRepository(); |
| 360 | + |
| 361 | + const { options, parsedOptions } = getOptions({ bumpDeps: true, fetch: false }); |
| 362 | + generateChangeFiles([{ packageName: 'pkg-1', type: 'minor' }], options); |
| 363 | + repo.push(); |
| 364 | + |
| 365 | + const { originalPackageInfos } = await publishWrapper(parsedOptions); |
| 366 | + repo.checkout(defaultBranchName); |
| 367 | + repo.pull(); |
| 368 | + |
| 369 | + expect(repo.getCurrentTags()).toEqual(['pkg-1_v1.1.0', 'pkg-2_v1.0.1', 'pkg-3_v1.0.1', 'pkg-4_v1.0.1']); |
| 370 | + |
| 371 | + // All the dependent packages are bumped despite the workspace: dep specs. |
| 372 | + // The literal workspace: specs are preserved in git. |
| 373 | + const packageInfos = getPackageInfos(parsedOptions); |
| 374 | + expect(packageInfos['pkg-1'].version).toBe('1.1.0'); |
| 375 | + // workspace:~ range isn't changed |
| 376 | + expect(packageInfos['pkg-2']).toEqual({ ...originalPackageInfos['pkg-2'], version: '1.0.1' }); |
| 377 | + expect(packageInfos['pkg-2'].version).toBe('1.0.1'); |
| 378 | + // workspace: range with number is updated |
| 379 | + expect(packageInfos['pkg-3'].dependencies).toEqual({ 'pkg-2': 'workspace:^1.0.1' }); |
| 380 | + // catalog: range isn't changed |
| 381 | + expect(packageInfos['pkg-4']).toEqual({ ...originalPackageInfos['pkg-4'], version: '1.0.1' }); |
| 382 | + |
| 383 | + // The changelogs are adequately covered by the similar bump test. |
| 384 | + |
| 385 | + // Verify that the published packages have the actual resolved versions |
| 386 | + expect(npmMock.getPublishedPackage('pkg-1')).toMatchObject({ version: '1.1.0' }); |
| 387 | + expect(npmMock.getPublishedPackage('pkg-2')).toMatchObject({ |
| 388 | + version: '1.0.1', |
| 389 | + dependencies: { 'pkg-1': '~1.1.0' }, |
| 390 | + }); |
| 391 | + expect(npmMock.getPublishedPackage('pkg-3')).toMatchObject({ |
| 392 | + version: '1.0.1', |
| 393 | + dependencies: { 'pkg-2': '^1.0.1' }, |
| 394 | + }); |
| 395 | + expect(npmMock.getPublishedPackage('pkg-4')).toMatchObject({ |
| 396 | + version: '1.0.1', |
| 397 | + dependencies: { 'pkg-1': '~1.1.0' }, |
| 398 | + // file: deps aren't currently replaced (definitely fine for dev deps, questionable for prod) |
| 399 | + devDependencies: { 'pkg-2': 'file:../pkg-2' }, |
| 400 | + }); |
| 401 | + }); |
| 402 | + |
| 403 | + // it('bumps dependents with catalog: deps', async () => { |
| 404 | + // const monorepo: RepoFixture['folders'] = { |
| 405 | + // packages: { |
| 406 | + // 'pkg-1': { version: '1.0.0' }, |
| 407 | + // 'pkg-2': { version: '1.0.0', dependencies: { 'pkg-1': 'catalog:' } }, |
| 408 | + // 'pkg-3': { version: '1.0.0', dependencies: { 'pkg-2': 'catalog:' } }, |
| 409 | + // }, |
| 410 | + // }; |
| 411 | + // const catalogs: Catalogs = { |
| 412 | + // default: { 'pkg-1': 'workspace:~', 'pkg-2': 'workspace:^1.0.0' }, |
| 413 | + // }; |
| 414 | + // repositoryFactory = new RepositoryFactory({ |
| 415 | + // folders: monorepo, |
| 416 | + // // This isn't currently read by bump() but should be present for completeness |
| 417 | + // extraFiles: { '.yarnrc.yml': catalogsToYaml(catalogs) }, |
| 418 | + // }); |
| 419 | + // repo = repositoryFactory.cloneRepository(); |
| 420 | + |
| 421 | + // const { options, parsedOptions } = getOptions({ |
| 422 | + // bumpDeps: true, |
| 423 | + // }); |
| 424 | + // generateChangeFiles([{ packageName: 'pkg-1', type: 'minor' }], options); |
| 425 | + // repo.push(); |
| 426 | + |
| 427 | + // // The bumpInfo object is covered by the similar test in bumpInMemory.test.ts |
| 428 | + // const { originalPackageInfos } = await bumpWrapper(parsedOptions); |
| 429 | + |
| 430 | + // const packageInfos = getPackageInfos(parsedOptions); |
| 431 | + |
| 432 | + // // All the dependent packages are bumped despite the catalog: dep specs |
| 433 | + // expect(packageInfos['pkg-1'].version).toBe('1.1.0'); |
| 434 | + // // catalog: ranges aren't changed |
| 435 | + // expect(packageInfos['pkg-2']).toEqual({ ...originalPackageInfos['pkg-2'], version: '1.0.1' }); |
| 436 | + // expect(packageInfos['pkg-3']).toEqual({ ...originalPackageInfos['pkg-3'], version: '1.0.1' }); |
| 437 | + |
| 438 | + // expect(readChangelogJson(repo.pathTo('packages/pkg-1'))).not.toBeNull(); |
| 439 | + // // Current behavior: dependentChangedBy misses catalog: deps, so there are no changelog entries |
| 440 | + // // https://github.com/microsoft/beachball/issues/981 |
| 441 | + // expect(readChangelogJson(repo.pathTo('packages/pkg-2'))).toBeNull(); |
| 442 | + // expect(readChangelogJson(repo.pathTo('packages/pkg-3'))).toBeNull(); |
| 443 | + // }); |
| 444 | + |
337 | 445 | // These tests are slow, so combine pre and post hooks |
338 | 446 | it('respects prepublish/postpublish hooks', async () => { |
339 | 447 | repositoryFactory = new RepositoryFactory('monorepo'); |
@@ -499,6 +607,7 @@ describe('publish command (e2e)', () => { |
499 | 607 | }); |
500 | 608 |
|
501 | 609 | // Just test postpublish (prepublish should have the same logic) |
| 610 | + // TODO: possibly move to in-memory test |
502 | 611 | it('respects concurrency limit for publish hooks', async () => { |
503 | 612 | const packagesToPublish = ['pkg1', 'pkg2', 'pkg3', 'pkg4']; |
504 | 613 | type ExtraPackageJsonFixture = PackageJsonFixture & { customAfterPublish?: { notify: string } }; |
|
0 commit comments