@@ -10,12 +10,16 @@ import path from 'path';
1010import { PROJECT_ROOT } from './constants' ;
1111
1212describe ( 'npm-packages bump' , function ( ) {
13- let fsReadFile : SinonStub ;
1413 let fsWriteFile : SinonStub ;
14+ const shellApiSrc = path . join (
15+ PROJECT_ROOT ,
16+ 'packages' ,
17+ 'shell-api' ,
18+ 'src' ,
19+ 'mongosh-version.ts'
20+ ) ;
1521
1622 beforeEach ( function ( ) {
17- fsReadFile = sinon . stub ( fs , 'readFile' ) ;
18-
1923 fsWriteFile = sinon . stub ( fs , 'writeFile' ) ;
2024 fsWriteFile . resolves ( ) ;
2125 } ) ;
@@ -25,6 +29,13 @@ describe('npm-packages bump', function () {
2529 } ) ;
2630
2731 describe ( 'bumpMongoshReleasePackages' , function ( ) {
32+ let fsReadFile : SinonStub ;
33+ let getPackagesInTopologicalOrder : sinon . SinonStub ;
34+ beforeEach ( function ( ) {
35+ fsReadFile = sinon . stub ( fs , 'readFile' ) ;
36+ getPackagesInTopologicalOrder = sinon . stub ( ) ;
37+ } ) ;
38+
2839 it ( 'warns and does not run if version is not set' , async function ( ) {
2940 const consoleWarnSpy = sinon . spy ( console , 'warn' ) ;
3041 await bumpMongoshReleasePackages ( '' ) ;
@@ -35,9 +46,122 @@ describe('npm-packages bump', function () {
3546 expect ( fsWriteFile ) . not . called ;
3647 consoleWarnSpy . restore ( ) ;
3748 } ) ;
49+
50+ it ( 'bumps only mongosh packages' , async function ( ) {
51+ const mongoshPath = path . join ( PROJECT_ROOT , 'packages' , 'mongosh' ) ;
52+ const autocompletePath = path . join (
53+ PROJECT_ROOT ,
54+ 'packages' ,
55+ 'autocomplete'
56+ ) ;
57+ getPackagesInTopologicalOrder . resolves ( [
58+ { name : 'mongosh' , location : mongoshPath } ,
59+ { name : '@mongosh/autocomplete' , location : autocompletePath } ,
60+ ] ) ;
61+
62+ const rootProjectJson = path . join ( PROJECT_ROOT , 'package.json' ) ;
63+ const mongoshProjectJson = path . join ( mongoshPath , 'package.json' ) ;
64+ const autocompleteProjectJson = path . join (
65+ autocompletePath ,
66+ 'package.json'
67+ ) ;
68+ const mockPackageJson = [
69+ [
70+ rootProjectJson ,
71+ {
72+ name : 'mongosh' ,
73+ devDependencies : {
74+ mongosh : '0.1.2' ,
75+ '@mongosh/cli-repl' : '0.1.2' ,
76+ '@mongosh/autocomplete' : '1.2.3' ,
77+ } ,
78+ } ,
79+ ] ,
80+ [
81+ mongoshProjectJson ,
82+ {
83+ name : 'mongosh' ,
84+ version : '0.1.2' ,
85+ devDependencies : {
86+ '@mongosh/cli-repl' : '9.9.9' ,
87+ '@mongosh/autocomplete' : '1.2.3' ,
88+ } ,
89+ } ,
90+ ] ,
91+ [
92+ autocompleteProjectJson ,
93+ {
94+ name : '@mongosh/autocomplete' ,
95+ version : '1.2.3' ,
96+ devDependencies : {
97+ '@mongosh/cli-repl' : '0.1.2' ,
98+ '@mongosh/config' : '3.3.3' ,
99+ } ,
100+ } ,
101+ ] ,
102+ ] ;
103+
104+ fsReadFile . throws ( 'Unknown file' ) ;
105+ for ( const [ file , json ] of mockPackageJson ) {
106+ fsReadFile . withArgs ( file , 'utf8' ) . resolves ( JSON . stringify ( json ) ) ;
107+ }
108+
109+ const updateShellApiMongoshVersion = sinon . stub ( ) ;
110+ await bumpMongoshReleasePackages (
111+ '9.9.9' ,
112+ getPackagesInTopologicalOrder ,
113+ updateShellApiMongoshVersion
114+ ) ;
115+ expect ( fsWriteFile ) . callCount ( 3 ) ;
116+
117+ expect (
118+ JSON . parse (
119+ fsWriteFile . withArgs ( rootProjectJson ) . firstCall . args [ 1 ] as string
120+ )
121+ ) . deep . equals ( {
122+ name : 'mongosh' ,
123+ devDependencies : {
124+ mongosh : '9.9.9' ,
125+ '@mongosh/cli-repl' : '9.9.9' ,
126+ '@mongosh/autocomplete' : '1.2.3' ,
127+ } ,
128+ } ) ;
129+
130+ expect (
131+ JSON . parse (
132+ fsWriteFile . withArgs ( mongoshProjectJson ) . firstCall . args [ 1 ] as string
133+ )
134+ ) . deep . equals ( {
135+ name : 'mongosh' ,
136+ version : '9.9.9' ,
137+ devDependencies : {
138+ '@mongosh/cli-repl' : '9.9.9' ,
139+ '@mongosh/autocomplete' : '1.2.3' ,
140+ } ,
141+ } ) ;
142+
143+ expect (
144+ JSON . parse (
145+ fsWriteFile . withArgs ( autocompleteProjectJson ) . firstCall
146+ . args [ 1 ] as string
147+ )
148+ ) . deep . equals ( {
149+ name : '@mongosh/autocomplete' ,
150+ version : '1.2.3' ,
151+ devDependencies : {
152+ '@mongosh/cli-repl' : '9.9.9' ,
153+ '@mongosh/config' : '3.3.3' ,
154+ } ,
155+ } ) ;
156+ } ) ;
38157 } ) ;
39158
40159 describe ( 'updateShellApiMongoshVersion' , function ( ) {
160+ let fsReadFile : SinonStub ;
161+ beforeEach ( function ( ) {
162+ fsReadFile = sinon . stub ( fs , 'readFile' ) ;
163+ } ) ;
164+
41165 it ( 'updates the file to the set version' , async function ( ) {
42166 fsReadFile . resolves ( `
43167 /** Current mongosh cli-repl version. */
@@ -47,13 +171,7 @@ describe('npm-packages bump', function () {
47171 await updateShellApiMongoshVersion ( newVersion ) ;
48172
49173 expect ( fsWriteFile ) . calledWith (
50- path . join (
51- PROJECT_ROOT ,
52- 'packages' ,
53- 'shell-api' ,
54- 'src' ,
55- 'mongosh-version.ts'
56- ) ,
174+ shellApiSrc ,
57175 `
58176 /** Current mongosh cli-repl version. */
59177 export const MONGOSH_VERSION = '${ newVersion } ';` ,
0 commit comments