Skip to content

Commit 2b912d9

Browse files
committed
add and fix publish tests
1 parent 4da9db1 commit 2b912d9

File tree

3 files changed

+73
-24
lines changed

3 files changed

+73
-24
lines changed

packages/build/src/npm-packages/publish.spec.ts

+66-18
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,82 @@ describe('npm-packages publishNpmPackages', function () {
88
let listNpmPackages: SinonStub;
99
let markBumpedFilesAsAssumeUnchanged: SinonStub;
1010
let spawnSync: SinonStub;
11+
const lernaBin = path.resolve(
12+
__dirname,
13+
'..',
14+
'..',
15+
'..',
16+
'..',
17+
'node_modules',
18+
'.bin',
19+
'lerna'
20+
);
1121

1222
beforeEach(function () {
1323
listNpmPackages = sinon.stub();
1424
markBumpedFilesAsAssumeUnchanged = sinon.stub();
1525
spawnSync = sinon.stub();
1626
});
1727

18-
it('calls lerna to publish packages for a real version', function () {
19-
const lernaBin = path.resolve(
20-
__dirname,
21-
'..',
22-
'..',
23-
'..',
24-
'..',
25-
'node_modules',
26-
'.bin',
27-
'lerna'
28-
);
28+
it('throws if mongosh is not existent when publishing all', function () {
2929
const packages = [{ name: 'packageA', version: '0.7.0' }];
3030
listNpmPackages.returns(packages);
3131

32+
expect(() =>
33+
publishNpmPackages(
34+
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
35+
listNpmPackages,
36+
markBumpedFilesAsAssumeUnchanged,
37+
spawnSync
38+
)
39+
).throws('mongosh package not found');
40+
});
41+
42+
it('takes mongosh version and pushes tags', function () {
43+
const packages = [
44+
{ name: 'packageA', version: '0.7.0' },
45+
{ name: 'mongosh', version: '1.2.0' },
46+
];
47+
listNpmPackages.returns(packages);
48+
49+
publishNpmPackages(
50+
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
51+
listNpmPackages,
52+
markBumpedFilesAsAssumeUnchanged,
53+
spawnSync
54+
);
55+
56+
expect(spawnSync).calledWith('git', ['tag', '-a', '1.2.0', '-m', '1.2.0']);
57+
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
58+
});
59+
60+
it('does not manually push tags with auxiliary packages', function () {
61+
const packages = [
62+
{ name: 'packageA', version: '0.7.0' },
63+
{ name: 'mongosh', version: '1.2.0' },
64+
];
65+
listNpmPackages.returns(packages);
66+
67+
publishNpmPackages(
68+
{ isDryRun: false, useAuxiliaryPackagesOnly: true },
69+
listNpmPackages,
70+
markBumpedFilesAsAssumeUnchanged,
71+
spawnSync
72+
);
73+
74+
expect(spawnSync).calledWith('git', ['tag', '-a', '1.2.0', '-m', '1.2.0']);
75+
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
76+
});
77+
78+
it('calls lerna to publish packages for a real version', function () {
79+
const packages = [
80+
{ name: 'packageA', version: '0.7.0' },
81+
{ name: 'mongosh', version: '1.2.0' },
82+
];
83+
listNpmPackages.returns(packages);
84+
3285
publishNpmPackages(
33-
false,
34-
false,
86+
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
3587
listNpmPackages,
3688
markBumpedFilesAsAssumeUnchanged,
3789
spawnSync
@@ -48,10 +100,7 @@ describe('npm-packages publishNpmPackages', function () {
48100
'from-package',
49101
'--no-private',
50102
'--no-changelog',
51-
'--no-push',
52103
'--exact',
53-
'--no-git-tag-version',
54-
'--force-publish',
55104
'--yes',
56105
'--no-verify-access',
57106
],
@@ -70,8 +119,7 @@ describe('npm-packages publishNpmPackages', function () {
70119

71120
try {
72121
publishNpmPackages(
73-
false,
74-
false,
122+
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
75123
listNpmPackages,
76124
markBumpedFilesAsAssumeUnchanged,
77125
spawnSync

packages/build/src/npm-packages/publish.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { spawnSync as spawnSyncFn } from '../helpers/spawn-sync';
1111
import type { SpawnSyncOptionsWithStringEncoding } from 'child_process';
1212

1313
export function publishNpmPackages(
14-
isDryRun = false,
15-
useAuxiliaryPackagesOnly = false,
14+
{ isDryRun = false, useAuxiliaryPackagesOnly = false },
1615
listNpmPackages: typeof listNpmPackagesFn = listNpmPackagesFn,
1716
markBumpedFilesAsAssumeUnchangedFn: typeof markBumpedFilesAsAssumeUnchanged = markBumpedFilesAsAssumeUnchanged,
1817
spawnSync: typeof spawnSyncFn = spawnSyncFn
@@ -35,7 +34,7 @@ export function publishNpmPackages(
3534
(packageConfig) => !MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name)
3635
);
3736
}
38-
// Lerna requires a clean repository for a publish from-package (--force-publish does not have any effect here)
37+
// Lerna requires a clean repository for a publish from-package
3938
// we use git update-index --assume-unchanged on files we know have been bumped
4039
markBumpedFilesAsAssumeUnchangedFn(packages, true);
4140
try {
@@ -47,7 +46,6 @@ export function publishNpmPackages(
4746
'--no-private',
4847
'--no-changelog',
4948
'--exact',
50-
'--force-publish',
5149
'--yes',
5250
'--no-verify-access',
5351
],
@@ -63,7 +61,7 @@ export function publishNpmPackages(
6361
)?.version;
6462

6563
if (!mongoshVersion) {
66-
throw new Error('Mongosh package not found');
64+
throw new Error('mongosh package not found');
6765
}
6866

6967
spawnSync(

packages/build/src/run-publish.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export async function runPublish(
8181
// ensures the segment api key to be present in the published packages
8282
await writeBuildInfo(config, 'packaged');
8383

84-
publishNpmPackages(config.isDryRun, config.useAuxiliaryPackagesOnly);
84+
publishNpmPackages({
85+
isDryRun: config.isDryRun,
86+
useAuxiliaryPackagesOnly: config.useAuxiliaryPackagesOnly,
87+
});
8588

8689
await publishToHomebrew(
8790
homebrewCoreGithubRepo,

0 commit comments

Comments
 (0)