Skip to content

Commit c2285a0

Browse files
committed
fix: remove unnecessary __dirname and stub methods in tests
1 parent 17c43a8 commit c2285a0

File tree

7 files changed

+83
-27
lines changed

7 files changed

+83
-27
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ describe('npm-packages bump', function () {
4949

5050
expect(fsWriteFile).calledWith(
5151
path.join(
52-
__dirname,
5352
PROJECT_ROOT,
5453
'packages',
5554
'shell-api',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export async function bumpMongoshReleasePackages(
6262
/** Updates the shell-api constant to match the mongosh version. */
6363
export async function updateShellApiMongoshVersion(version: string) {
6464
const shellApiVersionFilePath = path.join(
65-
__dirname,
6665
PROJECT_ROOT,
6766
'packages',
6867
'shell-api',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { bumpAuxiliaryPackages } from './bump';
1+
export { bumpAuxiliaryPackages, bumpMongoshReleasePackages } from './bump';
22
export { publishToNpm } from './publish';
33
export { pushTags } from './push-tags';

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

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ import type {
99
import type { createAndPublishDownloadCenterConfig as createAndPublishDownloadCenterConfigFn } from './download-center';
1010
import { GithubRepo } from '@mongodb-js/devtools-github-repo';
1111
import type { publishToHomebrew as publishToHomebrewType } from './homebrew';
12+
import {
13+
type publishToNpm as publishToNpmType,
14+
type pushTags as pushTagsType,
15+
} from './npm-packages';
1216
import type {
13-
publishToNpm as publishToNpmType,
14-
pushTags as pushTagsType,
17+
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
18+
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
1519
} from './npm-packages';
1620
import { publishMongosh } from './publish-mongosh';
1721
import { dummyConfig } from '../test/helpers';
22+
import { getArtifactUrl } from './evergreen';
1823

1924
chai.use(require('sinon-chai'));
2025

@@ -36,11 +41,14 @@ describe('publishMongosh', function () {
3641
let writeBuildInfo: typeof writeBuildInfoType;
3742
let publishToHomebrew: typeof publishToHomebrewType;
3843
let shouldDoPublicRelease: typeof shouldDoPublicReleaseFn;
44+
let bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn;
45+
let bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn;
3946
let githubRepo: GithubRepo;
4047
let mongoHomebrewCoreForkRepo: GithubRepo;
4148
let homebrewCoreRepo: GithubRepo;
4249
let barque: Barque;
4350
let pushTags: typeof pushTagsType;
51+
const getEvergreenArtifactUrl = getArtifactUrl;
4452

4553
beforeEach(function () {
4654
config = { ...dummyConfig };
@@ -51,6 +59,8 @@ describe('publishMongosh', function () {
5159
publishToHomebrew = sinon.spy();
5260
shouldDoPublicRelease = sinon.spy();
5361
pushTags = sinon.spy();
62+
bumpMongoshReleasePackages = sinon.spy();
63+
bumpAuxiliaryPackages = sinon.spy();
5464

5565
githubRepo = createStubRepo();
5666
mongoHomebrewCoreForkRepo = createStubRepo();
@@ -95,7 +105,10 @@ describe('publishMongosh', function () {
95105
pushTags,
96106
writeBuildInfo,
97107
publishToHomebrew,
98-
shouldDoPublicRelease
108+
shouldDoPublicRelease,
109+
getEvergreenArtifactUrl,
110+
bumpMongoshReleasePackages,
111+
bumpAuxiliaryPackages
99112
);
100113
} catch (e: any) {
101114
return expect(e.message).to.contain('Could not find prior draft tag');
@@ -121,7 +134,10 @@ describe('publishMongosh', function () {
121134
pushTags,
122135
writeBuildInfo,
123136
publishToHomebrew,
124-
shouldDoPublicRelease
137+
shouldDoPublicRelease,
138+
getEvergreenArtifactUrl,
139+
bumpMongoshReleasePackages,
140+
bumpAuxiliaryPackages
125141
);
126142
} catch (e: any) {
127143
return expect(e.message).to.contain('Version mismatch');
@@ -142,7 +158,10 @@ describe('publishMongosh', function () {
142158
pushTags,
143159
writeBuildInfo,
144160
publishToHomebrew,
145-
shouldDoPublicRelease
161+
shouldDoPublicRelease,
162+
getEvergreenArtifactUrl,
163+
bumpMongoshReleasePackages,
164+
bumpAuxiliaryPackages
146165
);
147166

148167
expect(barque.releaseToBarque).to.have.been.callCount(26);
@@ -173,7 +192,10 @@ describe('publishMongosh', function () {
173192
pushTags,
174193
writeBuildInfo,
175194
publishToHomebrew,
176-
shouldDoPublicRelease
195+
shouldDoPublicRelease,
196+
getEvergreenArtifactUrl,
197+
bumpMongoshReleasePackages,
198+
bumpAuxiliaryPackages
177199
);
178200

179201
expect(createAndPublishDownloadCenterConfig).to.have.been.calledWith(
@@ -196,7 +218,10 @@ describe('publishMongosh', function () {
196218
pushTags,
197219
writeBuildInfo,
198220
publishToHomebrew,
199-
shouldDoPublicRelease
221+
shouldDoPublicRelease,
222+
getEvergreenArtifactUrl,
223+
bumpMongoshReleasePackages,
224+
bumpAuxiliaryPackages
200225
);
201226

202227
expect(githubRepo.promoteRelease).to.have.been.calledWith(config);
@@ -214,7 +239,10 @@ describe('publishMongosh', function () {
214239
pushTags,
215240
writeBuildInfo,
216241
publishToHomebrew,
217-
shouldDoPublicRelease
242+
shouldDoPublicRelease,
243+
getEvergreenArtifactUrl,
244+
bumpMongoshReleasePackages,
245+
bumpAuxiliaryPackages
218246
);
219247

220248
expect(writeBuildInfo).to.have.been.calledOnceWith(config);
@@ -233,7 +261,10 @@ describe('publishMongosh', function () {
233261
pushTags,
234262
writeBuildInfo,
235263
publishToHomebrew,
236-
shouldDoPublicRelease
264+
shouldDoPublicRelease,
265+
getEvergreenArtifactUrl,
266+
bumpMongoshReleasePackages,
267+
bumpAuxiliaryPackages
237268
);
238269

239270
expect(publishToHomebrew).to.have.been.calledWith(
@@ -264,7 +295,10 @@ describe('publishMongosh', function () {
264295
pushTags,
265296
writeBuildInfo,
266297
publishToHomebrew,
267-
shouldDoPublicRelease
298+
shouldDoPublicRelease,
299+
getEvergreenArtifactUrl,
300+
bumpMongoshReleasePackages,
301+
bumpAuxiliaryPackages
268302
);
269303

270304
expect(createAndPublishDownloadCenterConfig).not.to.have.been.called;
@@ -282,7 +316,10 @@ describe('publishMongosh', function () {
282316
pushTags,
283317
writeBuildInfo,
284318
publishToHomebrew,
285-
shouldDoPublicRelease
319+
shouldDoPublicRelease,
320+
getEvergreenArtifactUrl,
321+
bumpMongoshReleasePackages,
322+
bumpAuxiliaryPackages
286323
);
287324

288325
expect(githubRepo.promoteRelease).not.to.have.been.called;
@@ -300,7 +337,10 @@ describe('publishMongosh', function () {
300337
pushTags,
301338
writeBuildInfo,
302339
publishToHomebrew,
303-
shouldDoPublicRelease
340+
shouldDoPublicRelease,
341+
getEvergreenArtifactUrl,
342+
bumpMongoshReleasePackages,
343+
bumpAuxiliaryPackages
304344
);
305345

306346
expect(publishToNpm).not.to.have.been.called;
@@ -318,7 +358,10 @@ describe('publishMongosh', function () {
318358
pushTags,
319359
writeBuildInfo,
320360
publishToHomebrew,
321-
shouldDoPublicRelease
361+
shouldDoPublicRelease,
362+
getEvergreenArtifactUrl,
363+
bumpMongoshReleasePackages,
364+
bumpAuxiliaryPackages
322365
);
323366

324367
expect(publishToHomebrew).not.to.have.been.called;
@@ -336,7 +379,10 @@ describe('publishMongosh', function () {
336379
pushTags,
337380
writeBuildInfo,
338381
publishToHomebrew,
339-
shouldDoPublicRelease
382+
shouldDoPublicRelease,
383+
getEvergreenArtifactUrl,
384+
bumpMongoshReleasePackages,
385+
bumpAuxiliaryPackages
340386
);
341387

342388
expect(barque.releaseToBarque).not.to.have.been.called;

packages/build/src/publish-mongosh.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { type publishToNpm as publishToNpmType } from './npm-packages';
1515
import type { PackageInformationProvider } from './packaging';
1616
import { getPackageFile } from './packaging';
1717
import {
18-
bumpAuxiliaryPackages,
19-
bumpMongoshReleasePackages,
20-
} from './npm-packages/bump';
18+
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
19+
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
20+
} from './npm-packages';
2121

2222
export async function publishMongosh(
2323
config: Config,
@@ -31,7 +31,9 @@ export async function publishMongosh(
3131
writeBuildInfo: typeof writeBuildInfoType,
3232
publishToHomebrew: typeof publishToHomebrewType,
3333
shouldDoPublicRelease: typeof shouldDoPublicReleaseFn = shouldDoPublicReleaseFn,
34-
getEvergreenArtifactUrl: typeof getArtifactUrlFn = getArtifactUrlFn
34+
getEvergreenArtifactUrl: typeof getArtifactUrlFn = getArtifactUrlFn,
35+
bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn = bumpMongoshReleasePackagesFn,
36+
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn
3537
): Promise<void> {
3638
if (!shouldDoPublicRelease(config)) {
3739
console.warn(

packages/build/src/run-draft.spec.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ describe('draft', function () {
3737
});
3838

3939
describe('runDraft', function () {
40+
const bumpMongoshReleasePackages = sinon.spy();
41+
const bumpMongoshAuxiliaryPackages = sinon.spy();
4042
let ensureGithubReleaseExistsAndUpdateChangelog: typeof ensureGithubReleaseExistsAndUpdateChangelogFn;
4143

4244
beforeEach(function () {
@@ -58,7 +60,9 @@ describe('draft', function () {
5860
githubRepo,
5961
uploadArtifactToDownloadCenter,
6062
downloadArtifactFromEvergreen,
61-
ensureGithubReleaseExistsAndUpdateChangelog
63+
ensureGithubReleaseExistsAndUpdateChangelog,
64+
bumpMongoshReleasePackages,
65+
bumpMongoshAuxiliaryPackages
6266
);
6367
});
6468

@@ -102,7 +106,9 @@ describe('draft', function () {
102106
githubRepo,
103107
uploadArtifactToDownloadCenter,
104108
downloadArtifactFromEvergreen,
105-
ensureGithubReleaseExistsAndUpdateChangelog
109+
ensureGithubReleaseExistsAndUpdateChangelog,
110+
bumpMongoshReleasePackages,
111+
bumpMongoshAuxiliaryPackages
106112
);
107113
expect(ensureGithubReleaseExistsAndUpdateChangelog).to.not.have.been
108114
.called;
@@ -125,7 +131,9 @@ describe('draft', function () {
125131
githubRepo,
126132
uploadArtifactToDownloadCenter,
127133
downloadArtifactFromEvergreen,
128-
ensureGithubReleaseExistsAndUpdateChangelog
134+
ensureGithubReleaseExistsAndUpdateChangelog,
135+
bumpMongoshReleasePackages,
136+
bumpMongoshAuxiliaryPackages
129137
);
130138
} catch (e: any) {
131139
expect(e.message).to.contain('Missing package information from config');

packages/build/src/run-draft.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import { generateChangelog as generateChangelogFn } from './git';
88
import type { GithubRepo } from '@mongodb-js/devtools-github-repo';
99
import { getPackageFile } from './packaging';
1010
import {
11-
bumpAuxiliaryPackages,
12-
bumpMongoshReleasePackages,
11+
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
12+
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
1313
} from './npm-packages/bump';
1414

1515
export async function runDraft(
1616
config: Config,
1717
githubRepo: GithubRepo,
1818
uploadToDownloadCenter: typeof uploadArtifactToDownloadCenterFn = uploadArtifactToDownloadCenterFn,
1919
downloadArtifactFromEvergreen: typeof downloadArtifactFromEvergreenFn = downloadArtifactFromEvergreenFn,
20-
ensureGithubReleaseExistsAndUpdateChangelog: typeof ensureGithubReleaseExistsAndUpdateChangelogFn = ensureGithubReleaseExistsAndUpdateChangelogFn
20+
ensureGithubReleaseExistsAndUpdateChangelog: typeof ensureGithubReleaseExistsAndUpdateChangelogFn = ensureGithubReleaseExistsAndUpdateChangelogFn,
21+
bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn = bumpMongoshReleasePackagesFn,
22+
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn
2123
): Promise<void> {
2224
const { triggeringGitTag } = config;
2325
const draftReleaseVersion = getReleaseVersionFromTag(triggeringGitTag);

0 commit comments

Comments
 (0)