@@ -8,7 +8,13 @@ import * as utils from '../src/cache-utils';
88import { restoreCache } from '../src/cache-restore' ;
99
1010describe ( 'cache-restore' , ( ) => {
11- process . env [ 'GITHUB_WORKSPACE' ] = path . join ( __dirname , 'data' ) ;
11+ const packageManagers = [ 'yarn' , 'npm' , 'pnpm' ] as const ;
12+ type PackageManager = ( typeof packageManagers ) [ number ] ;
13+
14+ const setWorkspaceFor = ( pm : PackageManager ) => {
15+ process . env [ 'GITHUB_WORKSPACE' ] = path . join ( __dirname , 'data' , pm ) ;
16+ } ;
17+ const originalGithubWorkspace = process . env [ 'GITHUB_WORKSPACE' ] ;
1218 if ( ! process . env . RUNNER_OS ) {
1319 process . env . RUNNER_OS = 'Linux' ;
1420 }
@@ -25,7 +31,7 @@ describe('cache-restore', () => {
2531 'abf7c9b306a3149dcfba4673e2362755503bcceaab46f0e4e6fee0ade493e20c' ;
2632 const pnpmFileHash =
2733 '26309058093e84713f38869c50cf1cee9b08155ede874ec1b44ce3fca8c68c70' ;
28- const cachesObject = {
34+ const cachesObject : Record < string , string > = {
2935 [ npmCachePath ] : npmFileHash ,
3036 [ pnpmCachePath ] : pnpmFileHash ,
3137 [ yarn1CachePath ] : yarnFileHash ,
@@ -128,9 +134,11 @@ describe('cache-restore', () => {
128134 [ 'yarn' , '1.2.3' , yarnFileHash ] ,
129135 [ 'npm' , '' , npmFileHash ] ,
130136 [ 'pnpm' , '' , pnpmFileHash ]
131- ] ) (
137+ ] as const ) (
132138 'restored dependencies for %s' ,
133139 async ( packageManager , toolVersion , fileHash ) => {
140+ // Set workspace to the appropriate fixture folder
141+ setWorkspaceFor ( packageManager ) ;
134142 getCommandOutputSpy . mockImplementation ( ( command : string ) => {
135143 if ( command . includes ( 'version' ) ) {
136144 return toolVersion ;
@@ -158,9 +166,11 @@ describe('cache-restore', () => {
158166 [ 'yarn' , '1.2.3' , yarnFileHash ] ,
159167 [ 'npm' , '' , npmFileHash ] ,
160168 [ 'pnpm' , '' , pnpmFileHash ]
161- ] ) (
169+ ] as const ) (
162170 'dependencies are changed %s' ,
163171 async ( packageManager , toolVersion , fileHash ) => {
172+ // Set workspace to the appropriate fixture folder
173+ setWorkspaceFor ( packageManager ) ;
164174 getCommandOutputSpy . mockImplementation ( ( command : string ) => {
165175 if ( command . includes ( 'version' ) ) {
166176 return toolVersion ;
@@ -181,6 +191,11 @@ describe('cache-restore', () => {
181191 } ) ;
182192
183193 afterEach ( ( ) => {
194+ if ( originalGithubWorkspace === undefined ) {
195+ delete process . env [ 'GITHUB_WORKSPACE' ] ;
196+ } else {
197+ process . env [ 'GITHUB_WORKSPACE' ] = originalGithubWorkspace ;
198+ }
184199 jest . resetAllMocks ( ) ;
185200 jest . clearAllMocks ( ) ;
186201 } ) ;
0 commit comments