Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Jun 20, 2022
1 parent bf2ad5d commit 10afa9e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/cli/src/automigrate/fixes/npm7.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { NPMProxy } from '../../js-package-manager/NPMProxy';
import { npm7 } from './npm7';

const mockExecuteCommand = jest.fn();
class MockedNPMProxy extends NPMProxy {
executeCommand(...args) {
return mockExecuteCommand(...args);
}
}

function mockExecuteResults(map: Record<string, string>) {
mockExecuteCommand.mockImplementation((command, args) => {
const commandString = `${command} ${args.join(' ')}`;
if (map[commandString]) return map[commandString];

throw new Error(`Unexpected execution of '${commandString}'`);
});
}

describe('npm7 fix', () => {
describe('npm < 7', () => {
it('does not match', async () => {
mockExecuteResults({ 'npm --version': '6.0.0' });
expect(await npm7.check({ packageManager: new MockedNPMProxy() })).toEqual(null);
});
});

describe('npm 7+', () => {
it('matches if config is not installed', async () => {
mockExecuteResults({
'npm --version': '7.0.0',
'npm config get legacy-peer-deps --location=project': 'false',
});
expect(await npm7.check({ packageManager: new MockedNPMProxy() })).toEqual({
npmVersion: '7.0.0',
});
});

it('does not match if config is installed', async () => {
mockExecuteResults({
'npm --version': '7.0.0',
'npm config get legacy-peer-deps --location=project': 'true',
});
expect(await npm7.check({ packageManager: new MockedNPMProxy() })).toEqual(null);
});
});
});

0 comments on commit 10afa9e

Please sign in to comment.