mirror of
https://github.com/actions/setup-node.git
synced 2026-03-04 06:51:04 +08:00
Compare commits
1 Commits
7e0a43fdfd
...
0b6e5029e4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b6e5029e4 |
@ -8,13 +8,9 @@ import * as utils from '../src/cache-utils';
|
|||||||
import {restoreCache} from '../src/cache-restore';
|
import {restoreCache} from '../src/cache-restore';
|
||||||
|
|
||||||
describe('cache-restore', () => {
|
describe('cache-restore', () => {
|
||||||
const packageManagers = ['yarn', 'npm', 'pnpm'] as const;
|
const setWorkspaceFor = (pm: 'npm' | 'yarn' | 'pnpm') => {
|
||||||
type PackageManager = (typeof packageManagers)[number];
|
|
||||||
|
|
||||||
const setWorkspaceFor = (pm: PackageManager) => {
|
|
||||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data', pm);
|
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data', pm);
|
||||||
};
|
};
|
||||||
const originalGithubWorkspace = process.env['GITHUB_WORKSPACE'];
|
|
||||||
if (!process.env.RUNNER_OS) {
|
if (!process.env.RUNNER_OS) {
|
||||||
process.env.RUNNER_OS = 'Linux';
|
process.env.RUNNER_OS = 'Linux';
|
||||||
}
|
}
|
||||||
@ -134,11 +130,11 @@ describe('cache-restore', () => {
|
|||||||
['yarn', '1.2.3', yarnFileHash],
|
['yarn', '1.2.3', yarnFileHash],
|
||||||
['npm', '', npmFileHash],
|
['npm', '', npmFileHash],
|
||||||
['pnpm', '', pnpmFileHash]
|
['pnpm', '', pnpmFileHash]
|
||||||
] as const)(
|
])(
|
||||||
'restored dependencies for %s',
|
'restored dependencies for %s',
|
||||||
async (packageManager, toolVersion, fileHash) => {
|
async (packageManager, toolVersion, fileHash) => {
|
||||||
// Set workspace to the appropriate fixture folder
|
// Set workspace to the appropriate fixture folder
|
||||||
setWorkspaceFor(packageManager);
|
setWorkspaceFor(packageManager as 'npm' | 'yarn' | 'pnpm');
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
if (command.includes('version')) {
|
if (command.includes('version')) {
|
||||||
return toolVersion;
|
return toolVersion;
|
||||||
@ -166,11 +162,11 @@ describe('cache-restore', () => {
|
|||||||
['yarn', '1.2.3', yarnFileHash],
|
['yarn', '1.2.3', yarnFileHash],
|
||||||
['npm', '', npmFileHash],
|
['npm', '', npmFileHash],
|
||||||
['pnpm', '', pnpmFileHash]
|
['pnpm', '', pnpmFileHash]
|
||||||
] as const)(
|
])(
|
||||||
'dependencies are changed %s',
|
'dependencies are changed %s',
|
||||||
async (packageManager, toolVersion, fileHash) => {
|
async (packageManager, toolVersion, fileHash) => {
|
||||||
// Set workspace to the appropriate fixture folder
|
// Set workspace to the appropriate fixture folder
|
||||||
setWorkspaceFor(packageManager);
|
setWorkspaceFor(packageManager as 'npm' | 'yarn' | 'pnpm');
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
if (command.includes('version')) {
|
if (command.includes('version')) {
|
||||||
return toolVersion;
|
return toolVersion;
|
||||||
@ -191,11 +187,6 @@ describe('cache-restore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalGithubWorkspace === undefined) {
|
|
||||||
delete process.env['GITHUB_WORKSPACE'];
|
|
||||||
} else {
|
|
||||||
process.env['GITHUB_WORKSPACE'] = originalGithubWorkspace;
|
|
||||||
}
|
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user