Skip to content

Commit 9ccbea3

Browse files
committed
fix: correct stubbing of existsTag
1 parent f7ae228 commit 9ccbea3

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,28 @@ describe('PackagePublisher', function () {
3838
MONGOSH_RELEASE_PACKAGES.includes(p.name)
3939
);
4040

41-
function setupTestPublisher(config: PackagePublisherConfig) {
41+
function setupTestPublisher(
42+
config: PackagePublisherConfig,
43+
{
44+
existsTagStub = sinon.stub(),
45+
}: {
46+
existsTagStub?: SinonStub | null;
47+
} = {}
48+
) {
4249
spawnSync = sinon.stub();
50+
spawnSync.returns(undefined);
4351

4452
testPublisher = new PackagePublisher(config, { spawnSync });
4553

46-
spawnSync.returns(undefined);
47-
4854
listNpmPackages = sinon.stub(testPublisher, 'listNpmPackages');
4955
listNpmPackages.returns(allReleasablePackages);
5056

51-
existsTag = sinon.stub(testPublisher, 'existsTag');
52-
existsTag.returns(false);
57+
if (existsTagStub) {
58+
console.log('setting up...');
59+
sinon.replace(testPublisher, 'existsTag', existsTagStub);
60+
existsTag = existsTagStub;
61+
existsTagStub.returns(false);
62+
}
5363
}
5464

5565
describe('publish()', function () {
@@ -245,11 +255,17 @@ describe('PackagePublisher', function () {
245255
});
246256

247257
describe('existsTag()', function () {
258+
beforeEach(function () {
259+
setupTestPublisher({}, { existsTagStub: null });
260+
});
261+
248262
it('returns true with existing tags', function () {
263+
spawnSync.returns({ status: 0 });
249264
expect(testPublisher.existsTag('v1.0.0')).equals(true);
250265
});
251266

252267
it('return false with tags that do not exist', function () {
268+
spawnSync.returns({ status: 1 });
253269
expect(testPublisher.existsTag('this-tag-will-never-exist-12345')).equals(
254270
false
255271
);

0 commit comments

Comments
 (0)