renovate/test/workers/branch/npm.spec.js
renovate[bot] 8866603a46 fix(deps): update dependency get-installed-path to v4 (#892)
* fix(deps): update dependency get-installed-path to v4.0.3

* fix
2017-10-08 06:30:01 +02:00

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');
});
});