@@ -10,12 +10,16 @@ import path from 'path';
10
10
import { PROJECT_ROOT } from './constants' ;
11
11
12
12
describe ( 'npm-packages bump' , function ( ) {
13
- let fsReadFile : SinonStub ;
14
13
let fsWriteFile : SinonStub ;
14
+ const shellApiSrc = path . join (
15
+ PROJECT_ROOT ,
16
+ 'packages' ,
17
+ 'shell-api' ,
18
+ 'src' ,
19
+ 'mongosh-version.ts'
20
+ ) ;
15
21
16
22
beforeEach ( function ( ) {
17
- fsReadFile = sinon . stub ( fs , 'readFile' ) ;
18
-
19
23
fsWriteFile = sinon . stub ( fs , 'writeFile' ) ;
20
24
fsWriteFile . resolves ( ) ;
21
25
} ) ;
@@ -25,6 +29,13 @@ describe('npm-packages bump', function () {
25
29
} ) ;
26
30
27
31
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
+
28
39
it ( 'warns and does not run if version is not set' , async function ( ) {
29
40
const consoleWarnSpy = sinon . spy ( console , 'warn' ) ;
30
41
await bumpMongoshReleasePackages ( '' ) ;
@@ -35,9 +46,122 @@ describe('npm-packages bump', function () {
35
46
expect ( fsWriteFile ) . not . called ;
36
47
consoleWarnSpy . restore ( ) ;
37
48
} ) ;
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
+ } ) ;
38
157
} ) ;
39
158
40
159
describe ( 'updateShellApiMongoshVersion' , function ( ) {
160
+ let fsReadFile : SinonStub ;
161
+ beforeEach ( function ( ) {
162
+ fsReadFile = sinon . stub ( fs , 'readFile' ) ;
163
+ } ) ;
164
+
41
165
it ( 'updates the file to the set version' , async function ( ) {
42
166
fsReadFile . resolves ( `
43
167
/** Current mongosh cli-repl version. */
@@ -47,13 +171,7 @@ describe('npm-packages bump', function () {
47
171
await updateShellApiMongoshVersion ( newVersion ) ;
48
172
49
173
expect ( fsWriteFile ) . calledWith (
50
- path . join (
51
- PROJECT_ROOT ,
52
- 'packages' ,
53
- 'shell-api' ,
54
- 'src' ,
55
- 'mongosh-version.ts'
56
- ) ,
174
+ shellApiSrc ,
57
175
`
58
176
/** Current mongosh cli-repl version. */
59
177
export const MONGOSH_VERSION = '${ newVersion } ';` ,
0 commit comments