mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
8866603a46
* fix(deps): update dependency get-installed-path to v4.0.3 * fix
94 lines
3.4 KiB
JavaScript
94 lines
3.4 KiB
JavaScript
const npmHelper = require('../../../lib/workers/branch/npm');
|
|
const logger = require('../../_fixtures/logger');
|
|
const { getInstalledPath } = require('get-installed-path');
|
|
|
|
jest.mock('fs-extra');
|
|
jest.mock('child-process-promise');
|
|
jest.mock('get-installed-path');
|
|
|
|
getInstalledPath.mockImplementation(() => null);
|
|
|
|
const fs = require('fs-extra');
|
|
const { exec } = require('child-process-promise');
|
|
|
|
describe('generateLockFile', () => {
|
|
it('generates lock files', async () => {
|
|
getInstalledPath.mockReturnValueOnce('node_modules/npm');
|
|
exec.mockReturnValueOnce({
|
|
stdout: '',
|
|
stderror: '',
|
|
});
|
|
fs.readFileSync = jest.fn(() => 'package-lock-contents');
|
|
const lockFile = await npmHelper.generateLockFile('some-dir', logger);
|
|
expect(fs.readFileSync.mock.calls.length).toEqual(1);
|
|
expect(lockFile).toEqual('package-lock-contents');
|
|
});
|
|
it('catches errors', async () => {
|
|
getInstalledPath.mockReturnValueOnce('node_modules/npm');
|
|
exec.mockReturnValueOnce({
|
|
stdout: '',
|
|
stderror: 'some-error',
|
|
});
|
|
fs.readFileSync = jest.fn(() => {
|
|
throw new Error('not found');
|
|
});
|
|
const lockFile = await npmHelper.generateLockFile('some-dir', logger);
|
|
expect(fs.readFileSync.mock.calls.length).toEqual(1);
|
|
expect(lockFile).toBe(null);
|
|
});
|
|
it('finds npm embedded in renovate', async () => {
|
|
getInstalledPath.mockImplementationOnce(() => {
|
|
throw new Error('not found');
|
|
});
|
|
getInstalledPath.mockImplementationOnce(() => '/node_modules/renovate');
|
|
getInstalledPath.mockImplementationOnce(
|
|
() => '/node_modules/renovate/node_modules/npm'
|
|
);
|
|
exec.mockReturnValueOnce({
|
|
stdout: '',
|
|
stderror: '',
|
|
});
|
|
fs.readFileSync = jest.fn(() => 'package-lock-contents');
|
|
const lockFile = await npmHelper.generateLockFile('some-dir', logger);
|
|
expect(fs.readFileSync.mock.calls.length).toEqual(1);
|
|
expect(lockFile).toEqual('package-lock-contents');
|
|
});
|
|
it('finds npm globally', async () => {
|
|
getInstalledPath.mockImplementationOnce(() => {
|
|
throw new Error('not found');
|
|
});
|
|
getInstalledPath.mockImplementationOnce(() => '/node_modules/renovate');
|
|
getInstalledPath.mockImplementationOnce(() => {
|
|
throw new Error('not found');
|
|
});
|
|
getInstalledPath.mockImplementationOnce(() => '/node_modules/npm');
|
|
exec.mockReturnValueOnce({
|
|
stdout: '',
|
|
stderror: '',
|
|
});
|
|
fs.readFileSync = jest.fn(() => 'package-lock-contents');
|
|
const lockFile = await npmHelper.generateLockFile('some-dir', logger);
|
|
expect(fs.readFileSync.mock.calls.length).toEqual(1);
|
|
expect(lockFile).toEqual('package-lock-contents');
|
|
});
|
|
it('uses fallback npm', async () => {
|
|
getInstalledPath.mockImplementationOnce(() => {
|
|
throw new Error('not found');
|
|
});
|
|
getInstalledPath.mockImplementationOnce(() => '/node_modules/renovate');
|
|
getInstalledPath.mockImplementationOnce(() => {
|
|
throw new Error('not found');
|
|
});
|
|
getInstalledPath.mockImplementationOnce(() => {
|
|
throw new Error('not found');
|
|
});
|
|
exec.mockReturnValueOnce({
|
|
stdout: '',
|
|
stderror: '',
|
|
});
|
|
fs.readFileSync = jest.fn(() => 'package-lock-contents');
|
|
const lockFile = await npmHelper.generateLockFile('some-dir', logger);
|
|
expect(fs.readFileSync.mock.calls.length).toEqual(1);
|
|
expect(lockFile).toEqual('package-lock-contents');
|
|
});
|
|
});
|