mirror of
https://github.com/actions/setup-node
synced 2026-07-18 05:41:01 +08:00
Some checks failed
Basic validation / Basic validation (push) Failing after 1s
Check dist / Check dist/ (push) Failing after 0s
CodeQL analysis / CodeQL analysis (push) Failing after 3s
e2e-cache / Test npm (Node 20, ubuntu-latest) (push) Successful in 13m8s
e2e-cache / Test npm (Node 22, ubuntu-latest) (push) Successful in 17m56s
e2e-cache / Test npm (Node 24, ubuntu-latest) (push) Successful in 38m58s
e2e-cache / Test pnpm (Node 20, ubuntu-latest) (push) Failing after 17m2s
e2e-cache / Test pnpm (Node 22, ubuntu-latest) (push) Failing after 1m37s
e2e-cache / Test pnpm (Node 24, ubuntu-latest) (push) Failing after 35s
e2e-cache / Test yarn 1 (Node 20, ubuntu-latest) (push) Failing after 32s
e2e-cache / Test yarn 1 (Node 22, ubuntu-latest) (push) Failing after 33s
e2e-cache / Test yarn 1 (Node 24, ubuntu-latest) (push) Failing after 13s
e2e-cache / Test yarn 3 (Node 20, ubuntu-latest) (push) Failing after 9s
e2e-cache / Test yarn 3 (Node 22, ubuntu-latest) (push) Failing after 9s
e2e-cache / Test yarn 3 (Node 24, ubuntu-latest) (push) Failing after 10s
e2e-cache / Test yarn subprojects (20) (push) Failing after 9s
e2e-cache / Test yarn subprojects (22) (push) Failing after 9s
e2e-cache / Test yarn subprojects (24) (push) Failing after 10s
e2e-cache / Test yarn subprojects all locally managed (20) (push) Failing after 8s
e2e-cache / Test yarn subprojects all locally managed (22) (push) Failing after 8s
e2e-cache / Test yarn subprojects all locally managed (24) (push) Failing after 9s
e2e-cache / Test yarn subprojects some locally managed (20) (push) Failing after 9s
e2e-cache / Test yarn subprojects some locally managed (22) (push) Failing after 15s
e2e-cache / Test yarn subprojects some locally managed (24) (push) Failing after 15s
e2e-cache / Test yarn subprojects managed by git (20) (push) Failing after 15s
e2e-cache / Test yarn subprojects managed by git (22) (push) Failing after 13s
e2e-cache / Test yarn subprojects managed by git (24) (push) Failing after 9s
e2e-cache / Test auto cache with top-level packageManager (20, ubuntu-latest) (push) Successful in 9m34s
e2e-cache / Test auto cache with top-level packageManager (22, ubuntu-latest) (push) Successful in 9m40s
e2e-cache / Test auto cache with top-level packageManager (24, ubuntu-latest) (push) Successful in 9m49s
e2e-cache / Test auto cache with devEngines.packageManager (20, ubuntu-latest) (push) Failing after 15m53s
e2e-cache / Test auto cache with devEngines.packageManager (22, ubuntu-latest) (push) Successful in 9m44s
e2e-cache / Test auto cache with devEngines.packageManager (24, ubuntu-latest) (push) Successful in 9m42s
Licensed / Licensed (push) Failing after 1s
proxy / test-proxy (push) Failing after 13s
proxy / test-bypass-proxy (push) Failing after 58s
versions / local-cache (20, ubuntu-latest) (push) Successful in 28s
versions / local-cache (22, ubuntu-latest) (push) Successful in 18s
versions / local-cache (24, ubuntu-latest) (push) Successful in 19s
versions / lts-syntax (lts/*, ubuntu-latest) (push) Failing after 18s
versions / lts-syntax (lts/-1, ubuntu-latest) (push) Failing after 18s
versions / lts-syntax (lts/dubnium, ubuntu-latest) (push) Failing after 12m43s
versions / lts-syntax (lts/erbium, ubuntu-latest) (push) Failing after 1m37s
versions / lts-syntax (lts/fermium, ubuntu-latest) (push) Failing after 32s
versions / v8-canary-syntax (20-v8-canary, ubuntu-latest) (push) Failing after 33s
versions / v8-canary-syntax (20.0.0-v8-canary, ubuntu-latest) (push) Failing after 17m10s
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, ubuntu-latest) (push) Failing after 32s
versions / nightly-syntax (20-nightly, ubuntu-latest) (push) Failing after 32s
versions / nightly-syntax (24.0.0-nightly, ubuntu-latest) (push) Failing after 17m3s
versions / nightly-syntax (25-nightly, ubuntu-latest) (push) Successful in 41s
versions / rc-syntax (20.0.0-rc.1, ubuntu-latest) (push) Successful in 45s
versions / rc-syntax (22.14.0-rc.1, ubuntu-latest) (push) Successful in 53s
versions / rc-syntax (24.0.0-rc.4, ubuntu-latest) (push) Successful in 41s
versions / manifest (20.10.0, ubuntu-latest) (push) Successful in 28m53s
versions / manifest (22.0.0, ubuntu-latest) (push) Failing after 17m3s
versions / manifest (24.9.0, ubuntu-latest) (push) Successful in 5m50s
versions / check-latest (20, ubuntu-latest) (push) Successful in 53s
versions / check-latest (22, ubuntu-latest) (push) Successful in 39s
versions / check-latest (24, ubuntu-latest) (push) Successful in 33s
versions / version-file (.nvmrc, ubuntu-latest) (push) Successful in 18s
versions / version-file (.tool-versions, ubuntu-latest) (push) Successful in 1h48m45s
versions / version-file (.tool-versions-node, ubuntu-latest) (push) Successful in 23s
versions / version-file (package.json, ubuntu-latest) (push) Successful in 18s
versions / version-file-dev-engines (ubuntu-latest) (push) Successful in 18s
versions / version-file-volta (ubuntu-latest) (push) Successful in 22s
versions / version-file-volta-extends (ubuntu-latest) (push) Successful in 19s
versions / node-dist (21, ubuntu-latest) (push) Successful in 45s
versions / node-dist (23, ubuntu-latest) (push) Successful in 55s
versions / old-versions (ubuntu-latest) (push) Successful in 36s
versions / node-latest-aliases (current, ubuntu-latest) (push) Successful in 45m30s
versions / node-latest-aliases (latest, ubuntu-latest) (push) Successful in 25s
versions / node-latest-aliases (node, ubuntu-latest) (push) Successful in 20s
e2e-cache / Test npm (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 20, macos-latest-large) (push) Has been cancelled
e2e-cache / Test npm (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 22, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 22, macos-latest-large) (push) Has been cancelled
e2e-cache / Test npm (Node 22, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 24, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 24, macos-latest-large) (push) Has been cancelled
e2e-cache / Test npm (Node 24, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 20, macos-latest-large) (push) Has been cancelled
e2e-cache / Test pnpm (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 22, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 22, macos-latest-large) (push) Has been cancelled
e2e-cache / Test pnpm (Node 22, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 24, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 24, macos-latest-large) (push) Has been cancelled
e2e-cache / Test pnpm (Node 24, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 20, macos-latest-large) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 22, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 22, macos-latest-large) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 22, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 24, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 24, macos-latest-large) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 24, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 20, macos-latest-large) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 22, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 22, macos-latest-large) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 22, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 24, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 24, macos-latest-large) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 24, windows-latest) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (20, macos-latest) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (20, macos-latest-large) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (20, windows-latest) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (22, macos-latest) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (22, macos-latest-large) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (22, windows-latest) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (24, macos-latest) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (24, macos-latest-large) (push) Has been cancelled
e2e-cache / Test auto cache with top-level packageManager (24, windows-latest) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (20, macos-latest) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (20, macos-latest-large) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (20, windows-latest) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (22, macos-latest) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (22, macos-latest-large) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (22, windows-latest) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (24, macos-latest) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (24, macos-latest-large) (push) Has been cancelled
e2e-cache / Test auto cache with devEngines.packageManager (24, windows-latest) (push) Has been cancelled
versions / local-cache (20, macos-latest) (push) Has been cancelled
versions / local-cache (20, macos-latest-large) (push) Has been cancelled
versions / local-cache (20, windows-latest) (push) Has been cancelled
versions / local-cache (22, macos-latest) (push) Has been cancelled
versions / local-cache (22, macos-latest-large) (push) Has been cancelled
versions / local-cache (22, windows-latest) (push) Has been cancelled
versions / local-cache (24, macos-latest) (push) Has been cancelled
versions / local-cache (24, macos-latest-large) (push) Has been cancelled
versions / local-cache (24, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/*, macos-latest-large) (push) Has been cancelled
versions / lts-syntax (lts/*, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/-1, macos-latest-large) (push) Has been cancelled
versions / lts-syntax (lts/-1, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, macos-latest-large) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/erbium, macos-latest-large) (push) Has been cancelled
versions / lts-syntax (lts/erbium, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/fermium, macos-latest-large) (push) Has been cancelled
versions / lts-syntax (lts/fermium, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, macos-latest-large) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, macos-latest-large) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, macos-latest-large) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, windows-latest) (push) Has been cancelled
versions / nightly-syntax (20-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (20-nightly, macos-latest-large) (push) Has been cancelled
versions / nightly-syntax (20-nightly, windows-latest) (push) Has been cancelled
versions / nightly-syntax (24.0.0-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (24.0.0-nightly, macos-latest-large) (push) Has been cancelled
versions / nightly-syntax (24.0.0-nightly, windows-latest) (push) Has been cancelled
versions / nightly-syntax (25-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (25-nightly, macos-latest-large) (push) Has been cancelled
versions / nightly-syntax (25-nightly, windows-latest) (push) Has been cancelled
versions / rc-syntax (20.0.0-rc.1, macos-latest) (push) Has been cancelled
versions / rc-syntax (20.0.0-rc.1, macos-latest-large) (push) Has been cancelled
versions / rc-syntax (20.0.0-rc.1, windows-latest) (push) Has been cancelled
versions / rc-syntax (22.14.0-rc.1, macos-latest) (push) Has been cancelled
versions / rc-syntax (22.14.0-rc.1, macos-latest-large) (push) Has been cancelled
versions / rc-syntax (22.14.0-rc.1, windows-latest) (push) Has been cancelled
versions / rc-syntax (24.0.0-rc.4, macos-latest) (push) Has been cancelled
versions / rc-syntax (24.0.0-rc.4, macos-latest-large) (push) Has been cancelled
versions / rc-syntax (24.0.0-rc.4, windows-latest) (push) Has been cancelled
versions / manifest (20.10.0, macos-latest) (push) Has been cancelled
versions / manifest (20.10.0, macos-latest-large) (push) Has been cancelled
versions / manifest (20.10.0, windows-latest) (push) Has been cancelled
versions / manifest (22.0.0, macos-latest) (push) Has been cancelled
versions / manifest (22.0.0, macos-latest-large) (push) Has been cancelled
versions / manifest (22.0.0, windows-latest) (push) Has been cancelled
versions / manifest (24.9.0, macos-latest) (push) Has been cancelled
versions / manifest (24.9.0, macos-latest-large) (push) Has been cancelled
versions / manifest (24.9.0, windows-latest) (push) Has been cancelled
versions / check-latest (20, macos-latest) (push) Has been cancelled
versions / check-latest (20, macos-latest-large) (push) Has been cancelled
versions / check-latest (20, windows-latest) (push) Has been cancelled
versions / check-latest (22, macos-latest) (push) Has been cancelled
versions / check-latest (22, macos-latest-large) (push) Has been cancelled
versions / check-latest (22, windows-latest) (push) Has been cancelled
versions / check-latest (24, macos-latest) (push) Has been cancelled
versions / check-latest (24, macos-latest-large) (push) Has been cancelled
versions / check-latest (24, windows-latest) (push) Has been cancelled
versions / version-file (.nvmrc, macos-latest) (push) Has been cancelled
versions / version-file (.nvmrc, macos-latest-large) (push) Has been cancelled
versions / version-file (.nvmrc, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions, macos-latest) (push) Has been cancelled
versions / version-file (.tool-versions, macos-latest-large) (push) Has been cancelled
versions / version-file (.tool-versions, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, macos-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, macos-latest-large) (push) Has been cancelled
versions / version-file (.tool-versions-node, windows-latest) (push) Has been cancelled
versions / version-file (package.json, macos-latest) (push) Has been cancelled
versions / version-file (package.json, macos-latest-large) (push) Has been cancelled
versions / version-file (package.json, windows-latest) (push) Has been cancelled
versions / version-file-dev-engines (macos-latest) (push) Has been cancelled
versions / version-file-dev-engines (windows-latest) (push) Has been cancelled
versions / version-file-volta (macos-latest) (push) Has been cancelled
versions / version-file-volta (macos-latest-large) (push) Has been cancelled
versions / version-file-volta (windows-latest) (push) Has been cancelled
versions / version-file-volta-extends (macos-latest) (push) Has been cancelled
versions / version-file-volta-extends (macos-latest-large) (push) Has been cancelled
versions / version-file-volta-extends (windows-latest) (push) Has been cancelled
versions / node-dist (21, macos-latest) (push) Has been cancelled
versions / node-dist (21, macos-latest-large) (push) Has been cancelled
versions / node-dist (21, windows-latest) (push) Has been cancelled
versions / node-dist (23, macos-latest) (push) Has been cancelled
versions / node-dist (23, macos-latest-large) (push) Has been cancelled
versions / node-dist (23, windows-latest) (push) Has been cancelled
versions / old-versions (macos-latest-large) (push) Has been cancelled
versions / old-versions (windows-latest) (push) Has been cancelled
versions / arch (push) Has been cancelled
versions / node-latest-aliases (current, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (current, macos-latest-large) (push) Has been cancelled
versions / node-latest-aliases (current, windows-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, macos-latest-large) (push) Has been cancelled
versions / node-latest-aliases (latest, windows-latest) (push) Has been cancelled
versions / node-latest-aliases (node, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (node, macos-latest-large) (push) Has been cancelled
versions / node-latest-aliases (node, windows-latest) (push) Has been cancelled
* Migrate to ESM * updated package.json version * Update README for v6 and clean up dev dependencies * Remove unused ts-node * fix audit issue --------- Co-authored-by: gowridurgad <gowridurgad@gmail.com>
459 lines
14 KiB
TypeScript
459 lines
14 KiB
TypeScript
import {jest, describe, it, expect, beforeEach, afterEach} from '@jest/globals';
|
|
import {fileURLToPath} from 'url';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
// Mock @actions modules before importing anything that depends on them
|
|
jest.unstable_mockModule('@actions/core', () => ({
|
|
info: jest.fn(),
|
|
warning: jest.fn(),
|
|
debug: jest.fn(),
|
|
error: jest.fn(),
|
|
notice: jest.fn(),
|
|
setFailed: jest.fn(),
|
|
setOutput: jest.fn(),
|
|
getInput: jest.fn(),
|
|
getBooleanInput: jest.fn(),
|
|
getMultilineInput: jest.fn(),
|
|
addPath: jest.fn(),
|
|
exportVariable: jest.fn(),
|
|
saveState: jest.fn(),
|
|
getState: jest.fn(),
|
|
setSecret: jest.fn(),
|
|
isDebug: jest.fn(() => false),
|
|
startGroup: jest.fn(),
|
|
endGroup: jest.fn(),
|
|
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
|
|
toPlatformPath: jest.fn((p: string) => p),
|
|
toWin32Path: jest.fn((p: string) => p),
|
|
toPosixPath: jest.fn((p: string) => p)
|
|
}));
|
|
|
|
jest.unstable_mockModule('@actions/cache', () => ({
|
|
saveCache: jest.fn(),
|
|
restoreCache: jest.fn(),
|
|
isFeatureAvailable: jest.fn(),
|
|
ValidationError: class ValidationError extends Error {
|
|
constructor(message: string) {
|
|
super(message);
|
|
this.name = 'ValidationError';
|
|
}
|
|
}
|
|
}));
|
|
|
|
jest.unstable_mockModule('@actions/glob', () => ({
|
|
hashFiles: jest.fn(),
|
|
create: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('@actions/exec', () => ({
|
|
exec: jest.fn(),
|
|
getExecOutput: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('@actions/io', () => ({
|
|
which: jest.fn(),
|
|
mkdirP: jest.fn(),
|
|
rmRF: jest.fn(),
|
|
mv: jest.fn(),
|
|
cp: jest.fn()
|
|
}));
|
|
|
|
// Dynamic imports after mocking
|
|
const core = await import('@actions/core');
|
|
const cache = await import('@actions/cache');
|
|
const glob = await import('@actions/glob');
|
|
const exec = await import('@actions/exec');
|
|
const utils = await import('../src/cache-utils.js');
|
|
const {run} = await import('../src/cache-save.js');
|
|
const {State} = await import('../src/constants.js');
|
|
|
|
describe('run', () => {
|
|
const yarnFileHash =
|
|
'b8a0bae5243251f7c07dd52d1f78ff78281dfefaded700a176261b6b54fa245b';
|
|
const npmFileHash =
|
|
'abf7c9b306a3149dcfba4673e2362755503bcceaab46f0e4e6fee0ade493e20c';
|
|
const pnpmFileHash =
|
|
'26309058093e84713f38869c50cf1cee9b08155ede874ec1b44ce3fca8c68c70';
|
|
const commonPath = '/some/random/path';
|
|
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
|
|
|
const inputs = {} as any;
|
|
|
|
let getInputSpy: jest.Mock;
|
|
let infoSpy: jest.Mock;
|
|
let warningSpy: jest.Mock;
|
|
let debugSpy: jest.Mock;
|
|
let setFailedSpy: jest.Mock;
|
|
let getStateSpy: jest.Mock;
|
|
let saveCacheSpy: jest.Mock;
|
|
let getExecOutputSpy: jest.Mock;
|
|
let hashFilesSpy: jest.Mock;
|
|
let existsSpy: jest.SpiedFunction<typeof fs.existsSync>;
|
|
|
|
beforeEach(() => {
|
|
getInputSpy = core.getInput as jest.Mock;
|
|
getInputSpy.mockImplementation((name: any) => inputs[name]);
|
|
|
|
infoSpy = core.info as jest.Mock;
|
|
infoSpy.mockImplementation(() => undefined);
|
|
|
|
warningSpy = core.warning as jest.Mock;
|
|
warningSpy.mockImplementation(() => undefined);
|
|
|
|
setFailedSpy = core.setFailed as jest.Mock;
|
|
setFailedSpy.mockImplementation(() => undefined);
|
|
|
|
debugSpy = core.debug as jest.Mock;
|
|
debugSpy.mockImplementation(() => undefined);
|
|
|
|
getStateSpy = core.getState as jest.Mock;
|
|
|
|
// cache
|
|
saveCacheSpy = cache.saveCache as jest.Mock;
|
|
saveCacheSpy.mockImplementation(() => undefined);
|
|
|
|
// glob
|
|
hashFilesSpy = glob.hashFiles as jest.Mock;
|
|
hashFilesSpy.mockImplementation((pattern: any) => {
|
|
if (pattern.includes('package-lock.json')) {
|
|
return npmFileHash;
|
|
} else if (pattern.includes('yarn.lock')) {
|
|
return yarnFileHash;
|
|
} else {
|
|
return '';
|
|
}
|
|
});
|
|
|
|
existsSpy = jest.spyOn(fs, 'existsSync');
|
|
existsSpy.mockImplementation(() => true);
|
|
|
|
// exec
|
|
getExecOutputSpy = exec.getExecOutput as jest.Mock;
|
|
});
|
|
|
|
afterEach(() => {
|
|
existsSpy.mockRestore();
|
|
jest.resetAllMocks();
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('Package manager validation', () => {
|
|
it('Package manager is not provided, skip caching', async () => {
|
|
inputs['cache'] = '';
|
|
getStateSpy.mockImplementation(() => '');
|
|
|
|
await run();
|
|
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
expect(infoSpy).not.toHaveBeenCalled();
|
|
expect(saveCacheSpy).not.toHaveBeenCalled();
|
|
expect(debugSpy).toHaveBeenLastCalledWith(
|
|
"Caching for '' is not supported"
|
|
);
|
|
});
|
|
|
|
it('Package manager is not valid, skip caching', async () => {
|
|
inputs['cache'] = 'yarn3';
|
|
getStateSpy.mockImplementation(key =>
|
|
key === State.CachePackageManager ? inputs['cache'] : ''
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
expect(infoSpy).not.toHaveBeenCalled();
|
|
expect(saveCacheSpy).not.toHaveBeenCalled();
|
|
expect(debugSpy).toHaveBeenLastCalledWith(
|
|
"Caching for 'yarn3' is not supported"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('Validate unchanged cache is not saved', () => {
|
|
it('should not save cache for yarn1', async () => {
|
|
inputs['cache'] = 'yarn';
|
|
getStateSpy.mockImplementation(key =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not save cache for yarn2', async () => {
|
|
inputs['cache'] = 'yarn';
|
|
getStateSpy.mockImplementation(key =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not save cache for npm', async () => {
|
|
inputs['cache'] = 'npm';
|
|
getStateSpy.mockImplementation(key =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
getExecOutputSpy.mockImplementationOnce(() => ({
|
|
stdout: `${commonPath}/npm`,
|
|
stderr: '',
|
|
exitCode: 0
|
|
}));
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not save cache for pnpm', async () => {
|
|
inputs['cache'] = 'pnpm';
|
|
getStateSpy.mockImplementation(key =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('action saves the cache', () => {
|
|
it('saves cache from yarn 1', async () => {
|
|
inputs['cache'] = 'yarn';
|
|
getStateSpy.mockImplementation((key: any) =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CacheMatchedKey
|
|
? yarnFileHash
|
|
: key === State.CachePrimaryKey
|
|
? npmFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
|
|
);
|
|
expect(saveCacheSpy).toHaveBeenCalled();
|
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
|
`Cache saved with the key: ${npmFileHash}`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('saves cache from yarn 2', async () => {
|
|
inputs['cache'] = 'yarn';
|
|
getStateSpy.mockImplementation((key: any) =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CacheMatchedKey
|
|
? yarnFileHash
|
|
: key === State.CachePrimaryKey
|
|
? npmFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${yarnFileHash}, not saving cache.`
|
|
);
|
|
expect(saveCacheSpy).toHaveBeenCalled();
|
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
|
`Cache saved with the key: ${npmFileHash}`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('saves cache from npm', async () => {
|
|
inputs['cache'] = 'npm';
|
|
getStateSpy.mockImplementation((key: any) =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CacheMatchedKey
|
|
? npmFileHash
|
|
: key === State.CachePrimaryKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
|
|
);
|
|
expect(saveCacheSpy).toHaveBeenCalled();
|
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
|
`Cache saved with the key: ${yarnFileHash}`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('saves cache from pnpm', async () => {
|
|
inputs['cache'] = 'pnpm';
|
|
getStateSpy.mockImplementation((key: any) =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CacheMatchedKey
|
|
? pnpmFileHash
|
|
: key === State.CachePrimaryKey
|
|
? npmFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${pnpmFileHash}, not saving cache.`
|
|
);
|
|
expect(saveCacheSpy).toHaveBeenCalled();
|
|
expect(infoSpy).toHaveBeenLastCalledWith(
|
|
`Cache saved with the key: ${npmFileHash}`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('save with -1 cacheId , should not fail workflow', async () => {
|
|
inputs['cache'] = 'npm';
|
|
getStateSpy.mockImplementation((key: any) =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CacheMatchedKey
|
|
? npmFileHash
|
|
: key === State.CachePrimaryKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
saveCacheSpy.mockImplementation(() => {
|
|
return -1;
|
|
});
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledWith(
|
|
`Cache was not saved for the key: ${yarnFileHash}`
|
|
);
|
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
|
|
);
|
|
expect(saveCacheSpy).toHaveBeenCalled();
|
|
expect(infoSpy).not.toHaveBeenLastCalledWith(
|
|
`Cache saved with the key: ${yarnFileHash}`
|
|
);
|
|
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('saves with error from toolkit, should fail workflow', async () => {
|
|
inputs['cache'] = 'npm';
|
|
getStateSpy.mockImplementation((key: any) =>
|
|
key === State.CachePackageManager
|
|
? inputs['cache']
|
|
: key === State.CacheMatchedKey
|
|
? npmFileHash
|
|
: key === State.CachePrimaryKey
|
|
? yarnFileHash
|
|
: key === State.CachePaths
|
|
? '["/foo/bar"]'
|
|
: 'not expected'
|
|
);
|
|
saveCacheSpy.mockImplementation(() => {
|
|
throw new cache.ValidationError('Validation failed');
|
|
});
|
|
|
|
await run();
|
|
|
|
expect(getInputSpy).not.toHaveBeenCalled();
|
|
expect(getStateSpy).toHaveBeenCalledTimes(4);
|
|
expect(getExecOutputSpy).toHaveBeenCalledTimes(0);
|
|
expect(debugSpy).toHaveBeenCalledTimes(0);
|
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
|
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
|
|
);
|
|
expect(saveCacheSpy).toHaveBeenCalled();
|
|
expect(setFailedSpy).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|