|
| 1 | +import { expect } from 'chai'; |
| 2 | +import type { SinonStub } from 'sinon'; |
| 3 | +import sinon from 'sinon'; |
| 4 | +import { |
| 5 | + bumpMongoshReleasePackages, |
| 6 | + updateShellApiMongoshVersion, |
| 7 | +} from './bump'; |
| 8 | +import { promises as fs } from 'fs'; |
| 9 | +import path from 'path'; |
| 10 | +import { PROJECT_ROOT } from './constants'; |
| 11 | +import * as monorepoTools from '@mongodb-js/monorepo-tools'; |
| 12 | + |
| 13 | +describe('npm-packages bump', function () { |
| 14 | + let fsReadFile: SinonStub; |
| 15 | + let fsWriteFile: SinonStub; |
| 16 | + |
| 17 | + beforeEach(function () { |
| 18 | + fsReadFile = sinon.stub(fs, 'readFile'); |
| 19 | + |
| 20 | + fsWriteFile = sinon.stub(fs, 'writeFile'); |
| 21 | + fsWriteFile.resolves(); |
| 22 | + }); |
| 23 | + |
| 24 | + afterEach(function () { |
| 25 | + sinon.restore(); |
| 26 | + }); |
| 27 | + |
| 28 | + describe('bumpMongoshReleasePackages', function () { |
| 29 | + it('throws if MONGOSH_RELEASE_VERSION is not set', async function () { |
| 30 | + process.env.MONGOSH_RELEASE_VERSION = ''; |
| 31 | + |
| 32 | + try { |
| 33 | + await bumpMongoshReleasePackages(); |
| 34 | + expect.fail('did not error'); |
| 35 | + } catch (error) { |
| 36 | + expect(error).instanceOf(Error); |
| 37 | + expect((error as Error).message).equals( |
| 38 | + 'MONGOSH_RELEASE_VERSION version not specified during mongosh bump' |
| 39 | + ); |
| 40 | + } |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('updateShellApiMongoshVersion', function () { |
| 45 | + it('updates the file to the set version', async function () { |
| 46 | + fsReadFile.resolves(` |
| 47 | + /** Current mongosh cli-repl version. */ |
| 48 | + export const MONGOSH_VERSION = '2.3.8';`); |
| 49 | + |
| 50 | + const newVersion = '3.0.0'; |
| 51 | + await updateShellApiMongoshVersion(newVersion); |
| 52 | + |
| 53 | + expect(fsWriteFile).calledWith( |
| 54 | + path.join( |
| 55 | + __dirname, |
| 56 | + PROJECT_ROOT, |
| 57 | + 'packages', |
| 58 | + 'shell-api', |
| 59 | + 'src', |
| 60 | + 'mongosh-version.ts' |
| 61 | + ), |
| 62 | + ` |
| 63 | + /** Current mongosh cli-repl version. */ |
| 64 | + export const MONGOSH_VERSION = '${newVersion}';`, |
| 65 | + 'utf-8' |
| 66 | + ); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments