@@ -14,7 +14,7 @@ jest.mock('libnpm', () => registry);
1414jest . mock ( '../src/cache' , ( ) => cache ) ;
1515
1616import * as install from '../src/install' ;
17- import { setEnv , restoreEnv } from './utils' ;
17+ import * as utils from './utils' ;
1818
1919describe ( 'resolve' , ( ) => {
2020 it ( 'fetches exact version of expo-cli' , async ( ) => {
@@ -25,66 +25,66 @@ describe('resolve', () => {
2525} ) ;
2626
2727describe ( 'install' , ( ) => {
28- it ( 'installs path from cache' , async ( ) => {
28+ it ( 'installs path from local cache' , async ( ) => {
2929 cache . fromLocalCache . mockResolvedValue ( '/cache/path' ) ;
3030 const expoPath = await install . install ( { version : '3.0.10' , packager : 'npm' } ) ;
3131 expect ( expoPath ) . toBe ( '/cache/path/node_modules/.bin' ) ;
3232 } ) ;
3333
34- it ( 'installs path from packager and cache it' , async ( ) => {
35- process . env [ 'RUNNER_TEMP' ] = '/temp/path' ;
34+ it ( 'installs path from packager and cache it locally ' , async ( ) => {
35+ utils . setEnv ( 'RUNNER_TEMP' , '/temp/path' ) ;
3636 cache . fromLocalCache . mockResolvedValue ( undefined ) ;
3737 cache . toLocalCache . mockResolvedValue ( '/cache/path' ) ;
3838 const expoPath = await install . install ( { version : '3.0.10' , packager : 'npm' } ) ;
3939 expect ( expoPath ) . toBe ( '/cache/path/node_modules/.bin' ) ;
4040 expect ( cache . toLocalCache ) . toBeCalledWith ( '/temp/path' , '3.0.10' ) ;
41+ utils . restoreEnv ( ) ;
4142 } ) ;
42- } ) ;
4343
44- describe ( 'fromPackager' , ( ) => {
45- afterEach ( ( ) => {
46- restoreEnv ( ) ;
44+ it ( 'installs path from remote cache' , async ( ) => {
45+ cache . fromLocalCache . mockResolvedValue ( undefined ) ;
46+ cache . fromRemoteCache . mockResolvedValue ( '/cache/path' ) ;
47+ registry . manifest . mockResolvedValue ( { version : '3.20.0' } ) ;
48+ const expoPath = await install . install ( { version : '3.20.1' , packager : 'npm' , cache : true } ) ;
49+ expect ( expoPath ) . toBe ( '/cache/path/node_modules/.bin' ) ;
50+ expect ( cache . fromRemoteCache ) . toBeCalledWith ( '3.20.0' , 'npm' , undefined ) ;
51+ } ) ;
52+
53+ it ( 'installs path from packager and cache it remotely' , async ( ) => {
54+ utils . setEnv ( 'RUNNER_TEMP' , '/temp/path' ) ;
55+ cache . fromLocalCache . mockResolvedValue ( undefined ) ;
56+ cache . fromRemoteCache . mockResolvedValue ( undefined ) ;
57+ cache . toLocalCache . mockResolvedValue ( '/cache/path' ) ;
58+ registry . manifest . mockResolvedValue ( { version : '3.20.1' } ) ;
59+ const expoPath = await install . install ( { version : '3.20.1' , packager : 'npm' , cache : true } ) ;
60+ expect ( expoPath ) . toBe ( '/cache/path/node_modules/.bin' ) ;
61+ expect ( cache . toRemoteCache ) . toBeCalledWith ( '/cache/path' , '3.20.1' , 'npm' , undefined ) ;
62+ utils . restoreEnv ( ) ;
4763 } ) ;
64+ } ) ;
4865
66+ describe ( 'fromPackager' , ( ) => {
4967 it ( 'resolves tool path' , async ( ) => {
5068 await install . fromPackager ( '3.0.10' , 'npm' ) ;
5169 expect ( io . which ) . toBeCalledWith ( 'npm' ) ;
5270 } ) ;
5371
5472 it ( 'creates temporary folder' , async ( ) => {
55- setEnv ( 'RUNNER_TEMP' , '/temp/path' ) ;
73+ utils . setEnv ( 'RUNNER_TEMP' , '/temp/path' ) ;
5674 await install . fromPackager ( 'latest' , 'yarn' ) ;
5775 expect ( io . mkdirP ) . toBeCalledWith ( '/temp/path' ) ;
76+ utils . restoreEnv ( ) ;
5877 } ) ;
5978
6079 it ( 'installs expo with tool' , async ( ) => {
61- setEnv ( 'RUNNER_TEMP' , '/temp/path' ) ;
80+ utils . setEnv ( 'RUNNER_TEMP' , '/temp/path' ) ;
6281 io . which . mockResolvedValue ( 'npm' ) ;
6382 const expoPath = await install . fromPackager ( 'beta' , 'npm' ) ;
6483 expect ( expoPath ) . toBe ( '/temp/path' ) ;
6584 expect ( cli . exec ) . toBeCalled ( ) ;
6685 expect ( cli . exec . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'npm' ) ;
6786 expect ( cli . exec . mock . calls [ 0 ] [ 1 ] ) . toStrictEqual ( [ 'add' , 'expo-cli@beta' ] ) ;
6887 expect ( cli . exec . mock . calls [ 0 ] [ 2 ] ) . toMatchObject ( { cwd : '/temp/path' } ) ;
88+ utils . restoreEnv ( ) ;
6989 } ) ;
7090} ) ;
71-
72- // todo: move this to cache tests
73-
74- // describe('fromCache', () => {
75- // it('uses cache for exact version', async () => {
76- // toolCache.find.mockResolvedValue('/cache/expo/path');
77- // const cachePath = await install.fromCache('3.0.10');
78- // expect(toolCache.find).toBeCalledWith('expo-cli', '3.0.10');
79- // expect(cachePath).toBe('/cache/expo/path');
80- // });
81- // });
82-
83- // describe('toCache', () => {
84- // it('uses cache for installed folder', async () => {
85- // toolCache.cacheDir.mockResolvedValue('/cache/expo/path');
86- // const cachePath = await install.toCache('3.0.10', '/expo/install/path');
87- // expect(toolCache.cacheDir).toBeCalledWith('/expo/install/path', 'expo-cli', '3.0.10');
88- // expect(cachePath).toBe('/cache/expo/path');
89- // });
90- // });
0 commit comments