Skip to content

Commit

Permalink
Remove redundant directory name variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyEckstein committed Nov 17, 2021
1 parent 782eb1f commit 007052f
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jest.mock('chalk', () => ({
const { join: mockJoin } = path;
jest.mock('path', () => ({ join: jest.fn() }));

const dir = 'foo';

const mockExecAsync = getMockExecAsync();

describe('lib/index', () => {
Expand All @@ -31,8 +33,6 @@ describe('lib/index', () => {
});

test('should upgrade upto patch versions when versions prefixed with ~', async () => {
const dir = 'dir1';

mockJoin.mockImplementation(() => '../test-helpers/test1.js');
mockExecAsync
.mockImplementationOnce(() =>
Expand All @@ -52,8 +52,6 @@ describe('lib/index', () => {
});

test('should upgrade upto minor versions when versions prefixed with ^', async () => {
const dir = 'dir2';

mockJoin.mockImplementation(() => '../test-helpers/test2.js');

mockExecAsync
Expand All @@ -74,8 +72,6 @@ describe('lib/index', () => {
});

test('should not upgrade locked versions', async () => {
const dir = 'dir3';

mockJoin.mockImplementation(() => '../test-helpers/test3.js');

await expect(verifyDeps({ dir, logger })).resolves.toBeUndefined();
Expand All @@ -85,7 +81,6 @@ describe('lib/index', () => {
});

test('should compare installed dependencies to latest NPM versions', async () => {
const dir = 'dir4';
mockJoin.mockImplementation(() => '../test-helpers/test4.js');

mockExecAsync
Expand All @@ -101,8 +96,6 @@ describe('lib/index', () => {
});

test('should compare installed devDpendencies to latest NPM versions', async () => {
const dir = 'dir5';

mockJoin.mockImplementation(() => '../test-helpers/test5.js');

mockExecAsync
Expand All @@ -118,7 +111,6 @@ describe('lib/index', () => {
});

test('should show dependency update required when using semver and later version in range is available', async () => {
const dir = 'dir6';
mockJoin
.mockImplementationOnce(() => '../test-helpers/test6.js')
.mockImplementationOnce(() => '../test-helpers/test6.js')
Expand Down Expand Up @@ -151,7 +143,6 @@ describe('lib/index', () => {
});

test('should not show dependency update required when using semver and later version is out of range', async () => {
const dir = 'dir7';
mockJoin.mockImplementation(() => '../test-helpers/test7.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '2.0.0']) }))
Expand All @@ -165,7 +156,6 @@ describe('lib/index', () => {
});

test('should show dependency update required when version is locked if non-major-version update available', async () => {
const dir = 'dir8';
mockJoin.mockImplementation(() => '../test-helpers/test8.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0']) }))
Expand Down Expand Up @@ -199,7 +189,6 @@ describe('lib/index', () => {
});

test('should not show dependency update required when version is locked if major-version update available', async () => {
const dir = 'dir9';
mockJoin.mockImplementation(() => '../test-helpers/test9.js');

mockExecAsync
Expand All @@ -218,7 +207,6 @@ describe('lib/index', () => {
});

test('should show dependency install required if module cannot be found', async () => {
const dir = 'dir10';
mockJoin.mockImplementation(() => '../test-helpers/test10.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -241,7 +229,6 @@ describe('lib/index', () => {
});

test('should show dependency install required if fetching versions does not return valid JSON output', async () => {
const dir = 'dir11';
mockJoin.mockImplementation(() => '../test-helpers/test11.js');
const invalidOutput = 'boo';
mockExecAsync.mockImplementationOnce(() => ({ stdout: invalidOutput }));
Expand All @@ -257,7 +244,6 @@ describe('lib/index', () => {
});

test('should show dependency install required if fetching tags does not return valid JSON output', async () => {
const dir = 'dir12';
mockJoin.mockImplementation(() => '../test-helpers/test12.js');
const invalidOutput = 'boo';
mockExecAsync
Expand All @@ -277,7 +263,6 @@ describe('lib/index', () => {
});

test('throw error when getting latest versions fails', async () => {
const dir = 'dir13';
mockJoin.mockImplementation(() => '../test-helpers/test13.js');
mockExecAsync.mockImplementation(() => {
throw new Error('foo');
Expand All @@ -288,7 +273,6 @@ describe('lib/index', () => {
});

test('throw error when getting latest tag fails', async () => {
const dir = 'dir14';
mockJoin.mockImplementation(() => '../test-helpers/test14.js');
mockExecAsync
.mockImplementationOnce(() =>
Expand All @@ -303,7 +287,6 @@ describe('lib/index', () => {
});

test('should show dependency install required if latest module is installed but not reflected in package.json', async () => {
const dir = 'dir15';
mockJoin.mockImplementation(() => '../test-helpers/test15.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -326,7 +309,6 @@ describe('lib/index', () => {
});

test('should not throw an error if no dependencies are in package.json', async () => {
const dir = 'dir16';
mockJoin.mockImplementation(() => '../test-helpers/test16.js');
await verifyDeps({ dir, logger });
expect(logger.info).toHaveBeenCalledTimes(2);
Expand All @@ -337,7 +319,7 @@ describe('lib/index', () => {
test('should default to native console when no logger is passed', async () => {
const consoleInfo = console.info;
console.info = jest.fn();
const dir = 'dir17';

mockJoin.mockImplementation(() => '../test-helpers/test17.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand Down Expand Up @@ -372,7 +354,6 @@ describe('lib/index', () => {
});

test('should update to version aliased as latest when aliased latest is less that most recent published version', async () => {
const dir = 'dir19';
mockJoin.mockImplementation(() => '../test-helpers/test19.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.2.4', '1.2.5']) }))
Expand Down Expand Up @@ -400,7 +381,6 @@ describe('lib/index', () => {
});

test('should upgrade pre-release versions to latest pre-release version available', async () => {
const dir = 'dir20';
mockJoin.mockImplementation(() => '../test-helpers/test20.js');
mockExecAsync
.mockImplementationOnce(() =>
Expand All @@ -423,7 +403,6 @@ describe('lib/index', () => {
});

test('should not upgrade when no version available for major version of pre-release', async () => {
const dir = 'dir21';
mockJoin.mockImplementation(() => '../test-helpers/test21.js');
mockExecAsync
.mockImplementationOnce(() => {
Expand All @@ -447,7 +426,6 @@ describe('lib/index', () => {
});

test('should throw an error when version in package.json is invalid (likely unpublished)', async () => {
const dir = 'dir22';
mockJoin.mockImplementation(() => '../test-helpers/test22.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.2.1']) }))
Expand All @@ -461,7 +439,6 @@ describe('lib/index', () => {
});

test('autoUpgrade modules', async () => {
const dir = 'dir23';
mockJoin.mockImplementation(() => '../test-helpers/test23.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand Down Expand Up @@ -489,15 +466,13 @@ describe('lib/index', () => {
});

test('throw error when npm module name is invalid', async () => {
const dir = 'dir24';
mockJoin.mockImplementation(() => '../test-helpers/test24.js');
await expect(verifyDeps({ autoUpgrade: true, dir, logger })).rejects.toThrow(
'NPM package name: "bad name Dependency" is invalid. name can only contain URL-friendly characters'
);
});

test('should verify dependencies when npm module has one version available, npm view returns string instead of array', async () => {
const dir = 'dir25';
mockJoin.mockImplementation(() => '../test-helpers/test25.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: '"1.1.1"' }))
Expand Down

0 comments on commit 007052f

Please sign in to comment.