@@ -8,7 +8,13 @@ import * as utils from '../src/cache-utils'; |
8 | 8 | import {restoreCache} from '../src/cache-restore'; |
9 | 9 |
|
10 | 10 | describe('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']; |
12 | 18 | if (!process.env.RUNNER_OS) { |
13 | 19 | process.env.RUNNER_OS = 'Linux'; |
14 | 20 | } |
@@ -25,7 +31,7 @@ describe('cache-restore', () => { |
25 | 31 | 'abf7c9b306a3149dcfba4673e2362755503bcceaab46f0e4e6fee0ade493e20c'; |
26 | 32 | const pnpmFileHash = |
27 | 33 | '26309058093e84713f38869c50cf1cee9b08155ede874ec1b44ce3fca8c68c70'; |
28 | | - const cachesObject = { |
| 34 | + const cachesObject: Record<string, string> = { |
29 | 35 | [npmCachePath]: npmFileHash, |
30 | 36 | [pnpmCachePath]: pnpmFileHash, |
31 | 37 | [yarn1CachePath]: yarnFileHash, |
@@ -128,9 +134,11 @@ describe('cache-restore', () => { |
128 | 134 | ['yarn', '1.2.3', yarnFileHash], |
129 | 135 | ['npm', '', npmFileHash], |
130 | 136 | ['pnpm', '', pnpmFileHash] |
131 | | - ])( |
| 137 | + ] as const)( |
132 | 138 | 'restored dependencies for %s', |
133 | 139 | async (packageManager, toolVersion, fileHash) => { |
| 140 | + // Set workspace to the appropriate fixture folder |
| 141 | + setWorkspaceFor(packageManager); |
134 | 142 | getCommandOutputSpy.mockImplementation((command: string) => { |
135 | 143 | if (command.includes('version')) { |
136 | 144 | return toolVersion; |
@@ -158,9 +166,11 @@ describe('cache-restore', () => { |
158 | 166 | ['yarn', '1.2.3', yarnFileHash], |
159 | 167 | ['npm', '', npmFileHash], |
160 | 168 | ['pnpm', '', pnpmFileHash] |
161 | | - ])( |
| 169 | + ] as const)( |
162 | 170 | 'dependencies are changed %s', |
163 | 171 | async (packageManager, toolVersion, fileHash) => { |
| 172 | + // Set workspace to the appropriate fixture folder |
| 173 | + setWorkspaceFor(packageManager); |
164 | 174 | getCommandOutputSpy.mockImplementation((command: string) => { |
165 | 175 | if (command.includes('version')) { |
166 | 176 | return toolVersion; |
@@ -181,6 +191,11 @@ describe('cache-restore', () => { |
181 | 191 | }); |
182 | 192 |
|
183 | 193 | afterEach(() => { |
| 194 | + if (originalGithubWorkspace === undefined) { |
| 195 | + delete process.env['GITHUB_WORKSPACE']; |
| 196 | + } else { |
| 197 | + process.env['GITHUB_WORKSPACE'] = originalGithubWorkspace; |
| 198 | + } |
184 | 199 | jest.resetAllMocks(); |
185 | 200 | jest.clearAllMocks(); |
186 | 201 | }); |
|