Handle globs in cacheDependencyPath

This commit is contained in:
Sergey Dolin 2023-05-11 09:40:44 +02:00
parent 52e352b14a
commit 6af80f316c
11 changed files with 1714 additions and 290 deletions

View file

@ -210,97 +210,4 @@ describe('authutil tests', () => {
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
);
});
describe('getPackageManagerWorkingDir', () => {
let existsSpy: jest.SpyInstance;
let lstatSpy: jest.SpyInstance;
beforeEach(() => {
existsSpy = jest.spyOn(fs, 'existsSync');
existsSpy.mockImplementation(() => true);
lstatSpy = jest.spyOn(fs, 'lstatSync');
lstatSpy.mockImplementation(arg => ({
isDirectory: () => true
}));
});
afterEach(() => {
existsSpy.mockRestore();
lstatSpy.mockRestore();
});
it('getPackageManagerWorkingDir should return null for not yarn', async () => {
process.env['INPUT_CACHE'] = 'some';
delete process.env['INPUT_CACHE-DEPENDENCY-PATH'];
const dir = cacheUtils.getPackageManagerWorkingDir();
expect(dir).toBeNull();
});
it('getPackageManagerWorkingDir should return null for not yarn with cache-dependency-path', async () => {
process.env['INPUT_CACHE'] = 'some';
process.env['INPUT_CACHE-DEPENDENCY-PATH'] = '/foo/bar';
const dir = cacheUtils.getPackageManagerWorkingDir();
expect(dir).toBeNull();
});
it('getPackageManagerWorkingDir should return null for yarn but without cache-dependency-path', async () => {
process.env['INPUT_CACHE'] = 'yarn';
delete process.env['INPUT_CACHE-DEPENDENCY-PATH'];
const dir = cacheUtils.getPackageManagerWorkingDir();
expect(dir).toBeNull();
});
it('getPackageManagerWorkingDir should return null for yarn with cache-dependency-path for not-existing directory', async () => {
process.env['INPUT_CACHE'] = 'yarn';
const cachePath = '/foo/bar';
process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
lstatSpy.mockImplementation(arg => ({
isDirectory: () => false
}));
const dir = cacheUtils.getPackageManagerWorkingDir();
expect(dir).toBeNull();
});
it('getPackageManagerWorkingDir should return path for yarn with cache-dependency-path', async () => {
process.env['INPUT_CACHE'] = 'yarn';
const cachePath = '/foo/bar';
process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
const dir = cacheUtils.getPackageManagerWorkingDir();
expect(dir).toEqual(path.dirname(cachePath));
});
it('getCommandOutput(getPackageManagerVersion) should be called from with getPackageManagerWorkingDir result', async () => {
process.env['INPUT_CACHE'] = 'yarn';
const cachePath = '/foo/bar';
process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
const getCommandOutputSpy = jest
.spyOn(cacheUtils, 'getCommandOutput')
.mockReturnValue(Promise.resolve('baz'));
const version = await cacheUtils.getPackageManagerVersion('foo', 'bar');
expect(getCommandOutputSpy).toHaveBeenCalledWith(
`foo bar`,
path.dirname(cachePath)
);
});
it('getCommandOutput(getCacheDirectoryPath) should be called from with getPackageManagerWorkingDir result', async () => {
process.env['INPUT_CACHE'] = 'yarn';
const cachePath = '/foo/bar';
process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
const getCommandOutputSpy = jest
.spyOn(cacheUtils, 'getCommandOutput')
.mockReturnValue(Promise.resolve('baz'));
const version = await cacheUtils.getCacheDirectoryPath(
{lockFilePatterns: [], getCacheFolderCommand: 'quz'},
''
);
expect(getCommandOutputSpy).toHaveBeenCalledWith(
`quz`,
path.dirname(cachePath)
);
});
});
});