mirror of
https://github.com/actions/setup-node.git
synced 2026-03-01 06:41:05 +08:00
address Copilot suggestions
This commit is contained in:
parent
fb1387391a
commit
584350e7a0
@ -8,9 +8,13 @@ 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 setWorkspaceFor = (pm: 'npm' | 'yarn' | 'pnpm') => {
|
const packageManagers = ['yarn', 'npm', 'pnpm'] as const;
|
||||||
|
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';
|
||||||
}
|
}
|
||||||
@ -130,11 +134,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 as 'npm' | 'yarn' | 'pnpm');
|
setWorkspaceFor(packageManager);
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
if (command.includes('version')) {
|
if (command.includes('version')) {
|
||||||
return toolVersion;
|
return toolVersion;
|
||||||
@ -162,11 +166,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 as 'npm' | 'yarn' | 'pnpm');
|
setWorkspaceFor(packageManager);
|
||||||
getCommandOutputSpy.mockImplementation((command: string) => {
|
getCommandOutputSpy.mockImplementation((command: string) => {
|
||||||
if (command.includes('version')) {
|
if (command.includes('version')) {
|
||||||
return toolVersion;
|
return toolVersion;
|
||||||
@ -187,6 +191,11 @@ 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