mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 17:16:25 +00:00
c3fc80a285
Co-authored-by: Rhys Arkins <rhys@arkins.net>
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { exec as _exec } from 'child_process';
|
|
import { envMock, mockExecAll } from '../../../../test/execUtil';
|
|
import { mocked } from '../../../../test/util';
|
|
import * as _env from '../../../util/exec/env';
|
|
import * as _fs from '../../../util/fs/proxies';
|
|
import { PostUpdateConfig } from '../../common';
|
|
import * as _pnpmHelper from './pnpm';
|
|
|
|
jest.mock('child_process');
|
|
jest.mock('../../../util/exec/env');
|
|
jest.mock('../../../util/fs/proxies');
|
|
jest.mock('./node-version');
|
|
|
|
const exec: jest.Mock<typeof _exec> = _exec as any;
|
|
const env = mocked(_env);
|
|
const fs = mocked(_fs);
|
|
const pnpmHelper = mocked(_pnpmHelper);
|
|
delete process.env.NPM_CONFIG_CACHE;
|
|
|
|
describe('generateLockFile', () => {
|
|
let config: PostUpdateConfig;
|
|
beforeEach(() => {
|
|
config = { cacheDir: 'some-cache-dir', compatibility: { pnpm: '^2.0.0' } };
|
|
env.getChildProcessEnv.mockReturnValue(envMock.basic);
|
|
});
|
|
it('generates lock files', async () => {
|
|
config.dockerMapDotfiles = true;
|
|
const execSnapshots = mockExecAll(exec);
|
|
fs.readFile = jest.fn(() => 'package-lock-contents') as never;
|
|
const res = await pnpmHelper.generateLockFile('some-dir', {}, config);
|
|
expect(fs.readFile).toHaveBeenCalledTimes(1);
|
|
expect(res.lockFile).toEqual('package-lock-contents');
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
});
|
|
it('catches errors', async () => {
|
|
const execSnapshots = mockExecAll(exec);
|
|
fs.readFile = jest.fn(() => {
|
|
throw new Error('not found');
|
|
}) as never;
|
|
const res = await pnpmHelper.generateLockFile('some-dir', {}, config);
|
|
expect(fs.readFile).toHaveBeenCalledTimes(1);
|
|
expect(res.error).toBe(true);
|
|
expect(res.lockFile).not.toBeDefined();
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
});
|
|
it('finds pnpm globally', async () => {
|
|
const execSnapshots = mockExecAll(exec);
|
|
fs.readFile = jest.fn(() => 'package-lock-contents') as never;
|
|
const res = await pnpmHelper.generateLockFile('some-dir', {}, config);
|
|
expect(fs.readFile).toHaveBeenCalledTimes(1);
|
|
expect(res.lockFile).toEqual('package-lock-contents');
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
});
|
|
it('performs lock file maintenance', async () => {
|
|
const execSnapshots = mockExecAll(exec);
|
|
fs.readFile = jest.fn(() => 'package-lock-contents') as never;
|
|
const res = await pnpmHelper.generateLockFile('some-dir', {}, config, [
|
|
{ isLockFileMaintenance: true },
|
|
]);
|
|
expect(fs.readFile).toHaveBeenCalledTimes(1);
|
|
expect(fs.remove).toHaveBeenCalledTimes(1);
|
|
expect(res.lockFile).toEqual('package-lock-contents');
|
|
expect(execSnapshots).toMatchSnapshot();
|
|
});
|
|
});
|