mirror of
https://gitea.com/actions/setup-node.git
synced 2024-11-22 10:09:33 +01:00
3d0d4edb10
* first iteration for implementation of caching * add logs * add debug line * fix build command * fix path * add possible post-if * remove braces * test new action post-if variant * work on built-in caching * remove post-if * pass version * work on yarn support * fix return value * change names and remove logs * worked on resolving comments * check post-if for null * add success() condition * remove primary key field * work on resolving comments * remove logs * resolving comments * resolving comments * resolving comments * resolving comments * fix getpackageManagerVersion * run clean for unstaged changes * fix falling version tests * work on resolving comments * resolving comments * fix comment * resolve comments * Add tests to cover node's caching (#3) * add tests to cover node's caching * work on fixing tests * fix e2e tests * rebuild and fix test * fixing tests * change name of describes, it and fix test * add names for jobs * fix issue
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import * as core from '@actions/core';
|
|
import path from 'path';
|
|
import * as utils from '../src/cache-utils';
|
|
|
|
describe('cache-utils', () => {
|
|
const commonPath = '/some/random/path';
|
|
const versionYarn1 = '1.2.3';
|
|
const versionYarn2 = '2.3.4';
|
|
|
|
let debugSpy: jest.SpyInstance;
|
|
let getCommandOutputSpy: jest.SpyInstance;
|
|
|
|
function getPackagePath(name: string) {
|
|
if (name === utils.supportedPackageManagers.npm.getCacheFolderCommand) {
|
|
return `${commonPath}/npm`;
|
|
} else {
|
|
if (name === utils.supportedPackageManagers.yarn1.getCacheFolderCommand) {
|
|
return `${commonPath}/yarn1`;
|
|
} else {
|
|
return `${commonPath}/yarn2`;
|
|
}
|
|
}
|
|
}
|
|
|
|
beforeEach(() => {
|
|
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
|
debugSpy = jest.spyOn(core, 'debug');
|
|
debugSpy.mockImplementation(msg => {});
|
|
|
|
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
|
});
|
|
|
|
describe('getPackageManagerInfo', () => {
|
|
it.each([
|
|
['npm', utils.supportedPackageManagers.npm],
|
|
['yarn', utils.supportedPackageManagers.yarn1],
|
|
['yarn1', null],
|
|
['yarn2', null],
|
|
['npm7', null]
|
|
])('getPackageManagerInfo for %s is %o', async (packageManager, result) => {
|
|
getCommandOutputSpy.mockImplementationOnce(() => versionYarn1);
|
|
await expect(utils.getPackageManagerInfo(packageManager)).resolves.toBe(
|
|
result
|
|
);
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
jest.clearAllMocks();
|
|
});
|
|
});
|