@@ -4,6 +4,8 @@ import * as path from 'path';
4
4
import * as core from '@actions/core' ;
5
5
import * as io from '@actions/io' ;
6
6
import * as auth from '../src/authutil' ;
7
+ import * as cacheUtils from '../src/cache-utils' ;
8
+ import { getCacheDirectoryPath } from '../src/cache-utils' ;
7
9
8
10
let rcFile : string ;
9
11
@@ -209,4 +211,66 @@ describe('authutil tests', () => {
209
211
`@otherscope:registry=MMM${ os . EOL } //registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${ os . EOL } @myscope:registry=https://registry.npmjs.org/${ os . EOL } always-auth=true`
210
212
) ;
211
213
} ) ;
214
+
215
+ it ( 'getPackageManagerWorkingDir should return null for not yarn' , async ( ) => {
216
+ process . env [ 'INPUT_CACHE' ] = 'some' ;
217
+ delete process . env [ 'INPUT_CACHE-DEPENDENCY-PATH' ] ;
218
+ const dir = cacheUtils . getPackageManagerWorkingDir ( ) ;
219
+ expect ( dir ) . toBeNull ( ) ;
220
+ } ) ;
221
+
222
+ it ( 'getPackageManagerWorkingDir should return null for not yarn with cache-dependency-path' , async ( ) => {
223
+ process . env [ 'INPUT_CACHE' ] = 'some' ;
224
+ process . env [ 'INPUT_CACHE-DEPENDENCY-PATH' ] = '/foo/bar' ;
225
+ const dir = cacheUtils . getPackageManagerWorkingDir ( ) ;
226
+ expect ( dir ) . toBeNull ( ) ;
227
+ } ) ;
228
+
229
+ it ( 'getPackageManagerWorkingDir should return null for yarn but without cache-dependency-path' , async ( ) => {
230
+ process . env [ 'INPUT_CACHE' ] = 'yarn' ;
231
+ delete process . env [ 'INPUT_CACHE-DEPENDENCY-PATH' ] ;
232
+ const dir = cacheUtils . getPackageManagerWorkingDir ( ) ;
233
+ expect ( dir ) . toBeNull ( ) ;
234
+ } ) ;
235
+
236
+ it ( 'getPackageManagerWorkingDir should return path for yarn with cache-dependency-path' , async ( ) => {
237
+ process . env [ 'INPUT_CACHE' ] = 'yarn' ;
238
+ const cachePath = '/foo/bar' ;
239
+ process . env [ 'INPUT_CACHE-DEPENDENCY-PATH' ] = cachePath ;
240
+ const dir = cacheUtils . getPackageManagerWorkingDir ( ) ;
241
+ expect ( dir ) . toEqual ( path . dirname ( cachePath ) ) ;
242
+ } ) ;
243
+
244
+ it ( 'getCommandOutput(getPackageManagerVersion) should be called from with getPackageManagerWorkingDir result' , async ( ) => {
245
+ process . env [ 'INPUT_CACHE' ] = 'yarn' ;
246
+ const cachePath = '/foo/bar' ;
247
+ process . env [ 'INPUT_CACHE-DEPENDENCY-PATH' ] = cachePath ;
248
+ const getCommandOutputSpy = jest
249
+ . spyOn ( cacheUtils , 'getCommandOutput' )
250
+ . mockReturnValue ( Promise . resolve ( 'baz' ) ) ;
251
+
252
+ const version = await cacheUtils . getPackageManagerVersion ( 'foo' , 'bar' ) ;
253
+ expect ( getCommandOutputSpy ) . toHaveBeenCalledWith (
254
+ `foo bar` ,
255
+ path . dirname ( cachePath )
256
+ ) ;
257
+ } ) ;
258
+
259
+ it ( 'getCommandOutput(getCacheDirectoryPath) should be called from with getPackageManagerWorkingDir result' , async ( ) => {
260
+ process . env [ 'INPUT_CACHE' ] = 'yarn' ;
261
+ const cachePath = '/foo/bar' ;
262
+ process . env [ 'INPUT_CACHE-DEPENDENCY-PATH' ] = cachePath ;
263
+ const getCommandOutputSpy = jest
264
+ . spyOn ( cacheUtils , 'getCommandOutput' )
265
+ . mockReturnValue ( Promise . resolve ( 'baz' ) ) ;
266
+
267
+ const version = await cacheUtils . getCacheDirectoryPath (
268
+ { lockFilePatterns : [ ] , getCacheFolderCommand : 'quz' } ,
269
+ ''
270
+ ) ;
271
+ expect ( getCommandOutputSpy ) . toHaveBeenCalledWith (
272
+ `quz` ,
273
+ path . dirname ( cachePath )
274
+ ) ;
275
+ } ) ;
212
276
} ) ;
0 commit comments