1
1
'use strict' ;
2
2
const expect = require ( 'chai' ) . expect ;
3
3
const sinon = require ( 'sinon' ) ;
4
- const proxyquire = require ( 'proxyquire' ) ;
4
+ const proxyquire = require ( 'proxyquire' ) . noPreserveCache ( ) ;
5
5
const Promise = require ( 'bluebird' ) ;
6
6
const { setupTestFolder, cleanupTestFolders} = require ( '../../utils/test-folder' ) ;
7
7
const path = require ( 'path' ) ;
@@ -102,48 +102,14 @@ describe('Unit: Tasks > yarn-install', function () {
102
102
} ) ;
103
103
104
104
describe ( 'dist subtask' , function ( ) {
105
- it ( 'rejects if yarn util returns invalid json' , function ( ) {
106
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : 'not json' } ) ;
107
- const dist = proxyquire ( modulePath , {
108
- '../utils/yarn' : yarnStub
109
- } ) . subTasks . dist ;
110
-
111
- return dist ( { version : '1.5.0' } ) . then ( ( ) => {
112
- expect ( false , 'error should have been thrown' ) . to . be . true ;
113
- } ) . catch ( ( error ) => {
114
- expect ( error ) . to . be . an . instanceof ( errors . CliError ) ;
115
- expect ( error . message ) . to . match ( / d o w n l o a d i n f o r m a t i o n c o u l d n o t b e r e a d / ) ;
116
- expect ( yarnStub . calledOnce ) . to . be . true ;
117
- expect ( yarnStub . calledWithExactly ( [ 'info' , '[email protected] ' , '--json' ] ) ) . to . be . true ;
118
- } ) ;
119
- } ) ;
120
-
121
- it ( 'rejects if dist data could not be found' , function ( ) {
122
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : '{}' } ) ;
123
- const dist = proxyquire ( modulePath , {
124
- '../utils/yarn' : yarnStub
125
- } ) . subTasks . dist ;
126
-
127
- return dist ( { version : '1.5.0' } ) . then ( ( ) => {
128
- expect ( false , 'error should have been thrown' ) . to . be . true ;
129
- } ) . catch ( ( error ) => {
130
- expect ( error ) . to . be . an . instanceof ( errors . CliError ) ;
131
- expect ( error . message ) . to . match ( / d o w n l o a d i n f o r m a t i o n c o u l d n o t b e r e a d / ) ;
132
- expect ( yarnStub . calledOnce ) . to . be . true ;
133
- expect ( yarnStub . calledWithExactly ( [ 'info' , '[email protected] ' , '--json' ] ) ) . to . be . true ;
134
- } ) ;
135
- } ) ;
136
-
137
105
it ( 'rejects if Ghost version isn\'t compatible with the current Node version and GHOST_NODE_VERISON_CHECK is not set' , function ( ) {
138
106
const data = {
139
- data : {
140
- engines : { node : '^0.10.0' } ,
141
- dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
142
- }
107
+ engines : { node : '^0.10.0' } ,
108
+ dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
143
109
} ;
144
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : JSON . stringify ( data ) } ) ;
110
+ const infoStub = sinon . stub ( ) . resolves ( data ) ;
145
111
const dist = proxyquire ( modulePath , {
146
- '../utils/yarn ' : yarnStub
112
+ 'package-json ' : infoStub
147
113
} ) . subTasks . dist ;
148
114
const ctx = { version : '1.5.0' } ;
149
115
@@ -152,29 +118,27 @@ describe('Unit: Tasks > yarn-install', function () {
152
118
} ) . catch ( ( error ) => {
153
119
expect ( error ) . to . be . an . instanceof ( errors . SystemError ) ;
154
120
expect ( error . message ) . to . equal ( 'Ghost v1.5.0 is not compatible with the current Node version.' ) ;
155
- expect ( yarnStub . calledOnce ) . to . be . true ;
156
- expect ( yarnStub . calledWithExactly ( [ 'info ', 'ghost@ 1.5.0', '--json' ] ) ) . to . be . true ;
121
+ expect ( infoStub . calledOnce ) . to . be . true ;
122
+ expect ( infoStub . calledWithExactly ( 'ghost ', { version : ' 1.5.0'} ) ) . to . be . true ;
157
123
} ) ;
158
124
} ) ;
159
125
160
126
it ( 'resolves if Ghost version isn\'t compatible with the current Node version and GHOST_NODE_VERISON_CHECK is set' , function ( ) {
161
127
const data = {
162
- data : {
163
- engines : { node : '^0.10.0' } ,
164
- dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
165
- }
128
+ engines : { node : '^0.10.0' } ,
129
+ dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
166
130
} ;
167
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : JSON . stringify ( data ) } ) ;
131
+ const infoStub = sinon . stub ( ) . resolves ( data ) ;
168
132
const dist = proxyquire ( modulePath , {
169
- '../utils/yarn ' : yarnStub
133
+ 'package-json ' : infoStub
170
134
} ) . subTasks . dist ;
171
135
const ctx = { version : '1.5.0' } ;
172
136
process . env . GHOST_NODE_VERSION_CHECK = 'false' ;
173
137
174
138
return dist ( ctx ) . then ( ( ) => {
175
139
delete process . env . GHOST_NODE_VERSION_CHECK ;
176
- expect ( yarnStub . calledOnce ) . to . be . true ;
177
- expect ( yarnStub . calledWithExactly ( [ 'info ', 'ghost@ 1.5.0', '--json' ] ) ) . to . be . true ;
140
+ expect ( infoStub . calledOnce ) . to . be . true ;
141
+ expect ( infoStub . calledWithExactly ( 'ghost ', { version : ' 1.5.0'} ) ) . to . be . true ;
178
142
expect ( ctx ) . to . deep . equal ( {
179
143
version : '1.5.0' ,
180
144
shasum : 'asdf1234' ,
@@ -188,14 +152,12 @@ describe('Unit: Tasks > yarn-install', function () {
188
152
189
153
it ( 'rejects if Ghost version isn\'t compatible with the current CLI version' , function ( ) {
190
154
const data = {
191
- data : {
192
- engines : { node : process . versions . node , cli : '^0.0.1' } ,
193
- dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
194
- }
155
+ engines : { node : process . versions . node , cli : '^0.0.1' } ,
156
+ dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
195
157
} ;
196
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : JSON . stringify ( data ) } ) ;
158
+ const infoStub = sinon . stub ( ) . resolves ( data ) ;
197
159
const dist = proxyquire ( modulePath , {
198
- '../utils/yarn ' : yarnStub ,
160
+ 'package-json ' : infoStub ,
199
161
'../../package.json' : { version : '1.0.0' }
200
162
} ) . subTasks . dist ;
201
163
const ctx = { version : '1.5.0' } ;
@@ -205,28 +167,26 @@ describe('Unit: Tasks > yarn-install', function () {
205
167
} ) . catch ( ( error ) => {
206
168
expect ( error ) . to . be . an . instanceof ( errors . SystemError ) ;
207
169
expect ( error . message ) . to . equal ( 'Ghost v1.5.0 is not compatible with this version of the CLI.' ) ;
208
- expect ( yarnStub . calledOnce ) . to . be . true ;
209
- expect ( yarnStub . calledWithExactly ( [ 'info ', 'ghost@ 1.5.0', '--json' ] ) ) . to . be . true ;
170
+ expect ( infoStub . calledOnce ) . to . be . true ;
171
+ expect ( infoStub . calledWithExactly ( 'ghost ', { version : ' 1.5.0'} ) ) . to . be . true ;
210
172
} ) ;
211
173
} ) ;
212
174
213
175
it ( 'resolves if Ghost version isn\'t compatible with CLI version, but CLI is a prerelease version' , function ( ) {
214
176
const data = {
215
- data : {
216
- engines : { node : process . versions . node , cli : '^1.9.0' } ,
217
- dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
218
- }
177
+ engines : { node : process . versions . node , cli : '^1.9.0' } ,
178
+ dist : { shasum : 'asdf1234' , tarball : 'something.tgz' }
219
179
} ;
220
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : JSON . stringify ( data ) } ) ;
180
+ const infoStub = sinon . stub ( ) . resolves ( data ) ;
221
181
const dist = proxyquire ( modulePath , {
222
- '../utils/yarn ' : yarnStub ,
182
+ 'package-json ' : infoStub ,
223
183
'../../package.json' : { version : '1.10.0-beta.0' }
224
184
} ) . subTasks . dist ;
225
185
const ctx = { version : '1.5.0' } ;
226
186
227
187
return dist ( ctx ) . then ( ( ) => {
228
- expect ( yarnStub . calledOnce ) . to . be . true ;
229
- expect ( yarnStub . calledWithExactly ( [ 'info ', 'ghost@ 1.5.0', '--json' ] ) ) . to . be . true ;
188
+ expect ( infoStub . calledOnce ) . to . be . true ;
189
+ expect ( infoStub . calledWithExactly ( 'ghost ', { version : ' 1.5.0'} ) ) . to . be . true ;
230
190
expect ( ctx ) . to . deep . equal ( {
231
191
version : '1.5.0' ,
232
192
shasum : 'asdf1234' ,
@@ -236,16 +196,16 @@ describe('Unit: Tasks > yarn-install', function () {
236
196
} ) ;
237
197
238
198
it ( 'adds shasum and tarball values to context' , function ( ) {
239
- const data = { data : { dist : { shasum : 'asdf1234' , tarball : 'something.tgz' } } } ;
240
- const yarnStub = sinon . stub ( ) . resolves ( { stdout : JSON . stringify ( data ) } ) ;
199
+ const data = { dist : { shasum : 'asdf1234' , tarball : 'something.tgz' } } ;
200
+ const infoStub = sinon . stub ( ) . resolves ( data ) ;
241
201
const dist = proxyquire ( modulePath , {
242
- '../utils/yarn ' : yarnStub
202
+ 'package-json ' : infoStub
243
203
} ) . subTasks . dist ;
244
204
const ctx = { version : '1.5.0' } ;
245
205
246
206
return dist ( ctx ) . then ( ( ) => {
247
- expect ( yarnStub . calledOnce ) . to . be . true ;
248
- expect ( yarnStub . calledWithExactly ( [ 'info ', 'ghost@ 1.5.0', '--json' ] ) ) . to . be . true ;
207
+ expect ( infoStub . calledOnce ) . to . be . true ;
208
+ expect ( infoStub . calledWithExactly ( 'ghost ', { version : ' 1.5.0'} ) ) . to . be . true ;
249
209
expect ( ctx ) . to . deep . equal ( {
250
210
version : '1.5.0' ,
251
211
shasum : 'asdf1234' ,
0 commit comments