Skip to content

Commit

Permalink
Move test helpers outside of lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyEckstein committed Nov 17, 2021
1 parent 4e1c194 commit 782eb1f
Show file tree
Hide file tree
Showing 26 changed files with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('lib/index', () => {
test('should upgrade upto patch versions when versions prefixed with ~', async () => {
const dir = 'dir1';

mockJoin.mockImplementation(() => './test_helpers/test1.js');
mockJoin.mockImplementation(() => '../test-helpers/test1.js');
mockExecAsync
.mockImplementationOnce(() =>
Promise.resolve({ stdout: JSON.stringify(['46.45.45', '46.46.0']) })
Expand All @@ -44,7 +44,6 @@ describe('lib/index', () => {
await expect(verifyDeps({ dir, logger })).rejects.toThrow(
'Please update your installed modules'
);
console.warn(logger.info.mock.calls);
expect(logger.info).toHaveBeenCalledTimes(4);
expect(logger.info).toHaveBeenNthCalledWith(1, 'Verifying dependencies…\n');
expect(logger.info).toHaveBeenNthCalledWith(2, 'foo1 is outdated: 46.45.44 → 46.45.45');
Expand All @@ -55,7 +54,7 @@ describe('lib/index', () => {
test('should upgrade upto minor versions when versions prefixed with ^', async () => {
const dir = 'dir2';

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

mockExecAsync
.mockImplementationOnce(() =>
Expand All @@ -77,7 +76,7 @@ describe('lib/index', () => {
test('should not upgrade locked versions', async () => {
const dir = 'dir3';

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

await expect(verifyDeps({ dir, logger })).resolves.toBeUndefined();
expect(logger.info).toHaveBeenCalledTimes(2);
Expand All @@ -87,7 +86,7 @@ describe('lib/index', () => {

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

mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -104,7 +103,7 @@ describe('lib/index', () => {
test('should compare installed devDpendencies to latest NPM versions', async () => {
const dir = 'dir5';

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

mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -121,8 +120,8 @@ 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')
.mockImplementationOnce(() => '../test-helpers/test6.js')
.mockImplementationOnce(() => '../test-helpers/test6.js')
.mockImplementationOnce(() => {
throw new Error('foo');
});
Expand Down Expand Up @@ -153,7 +152,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test7.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '2.0.0']) }))
.mockImplementationOnce(() =>
Expand All @@ -167,7 +166,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test8.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0']) }))
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.1.0']) }))
Expand Down Expand Up @@ -201,7 +200,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test9.js');

mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '2.0.0']) }))
Expand All @@ -220,7 +219,7 @@ describe('lib/index', () => {

test('should show dependency install required if module cannot be found', async () => {
const dir = 'dir10';
mockJoin.mockImplementation(() => './test_helpers/test10.js');
mockJoin.mockImplementation(() => '../test-helpers/test10.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -233,7 +232,6 @@ describe('lib/index', () => {
await expect(verifyDeps({ dir, logger })).rejects.toThrow(
'Please update your installed modules.'
);
console.warn(logger.info.mock.calls);
expect(logger.info).toHaveBeenCalledTimes(5);
expect(logger.info).toHaveBeenNthCalledWith(1, 'Verifying dependencies…\n');
expect(logger.info).toHaveBeenNthCalledWith(2, `eri is not installed`);
Expand All @@ -244,7 +242,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test11.js');
const invalidOutput = 'boo';
mockExecAsync.mockImplementationOnce(() => ({ stdout: invalidOutput }));
let syntaxError;
Expand All @@ -260,7 +258,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test12.js');
const invalidOutput = 'boo';
mockExecAsync
.mockImplementationOnce(() =>
Expand All @@ -280,7 +278,7 @@ describe('lib/index', () => {

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

test('throw error when getting latest tag fails', async () => {
const dir = 'dir14';
mockJoin.mockImplementation(() => './test_helpers/test14.js');
mockJoin.mockImplementation(() => '../test-helpers/test14.js');
mockExecAsync
.mockImplementationOnce(() =>
Promise.resolve({ stdout: JSON.stringify({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }) })
Expand All @@ -306,7 +304,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test15.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -329,7 +327,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test16.js');
await verifyDeps({ dir, logger });
expect(logger.info).toHaveBeenCalledTimes(2);
expect(logger.info).toHaveBeenNthCalledWith(1, 'Verifying dependencies…\n');
Expand All @@ -340,7 +338,7 @@ describe('lib/index', () => {
const consoleInfo = console.info;
console.info = jest.fn();
const dir = 'dir17';
mockJoin.mockImplementation(() => './test_helpers/test17.js');
mockJoin.mockImplementation(() => '../test-helpers/test17.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
Expand All @@ -361,7 +359,7 @@ describe('lib/index', () => {
});

test('should not throw type error if options are not passed', async () => {
mockJoin.mockImplementation(() => './test_helpers/test18.js');
mockJoin.mockImplementation(() => '../test-helpers/test18.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.0.1']) }))
.mockImplementationOnce(() =>
Expand All @@ -375,7 +373,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test19.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.2.4', '1.2.5']) }))
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.2.4', '1.2.5']) }))
Expand Down Expand Up @@ -403,7 +401,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test20.js');
mockExecAsync
.mockImplementationOnce(() =>
Promise.resolve({ stdout: JSON.stringify(['1.0.0-alpha.1', '1.0.0-alpha.2', '1.2.4']) })
Expand All @@ -426,7 +424,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test21.js');
mockExecAsync
.mockImplementationOnce(() => {
return Promise.resolve({
Expand All @@ -450,7 +448,7 @@ 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');
mockJoin.mockImplementation(() => '../test-helpers/test22.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: JSON.stringify(['1.0.0', '1.2.1']) }))
.mockImplementationOnce(() =>
Expand All @@ -464,7 +462,7 @@ describe('lib/index', () => {

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

test('throw error when npm module name is invalid', async () => {
const dir = 'dir24';
mockJoin.mockImplementation(() => './test_helpers/test24.js');
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');
mockJoin.mockImplementation(() => '../test-helpers/test25.js');
mockExecAsync
.mockImplementationOnce(() => Promise.resolve({ stdout: '"1.1.1"' }))
.mockImplementationOnce(() =>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 782eb1f

Please sign in to comment.