Skip to content

Commit

Permalink
Merge pull request #233 from lifion/bugfix/versions-filter-not-function
Browse files Browse the repository at this point in the history
Bugfix/versions filter not function
  • Loading branch information
jennyEckstein authored Oct 20, 2021
2 parents b8b0396 + 05a0ee5 commit bac7788
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async function getLatestVersions(name) {
isValidNpmPackageName(name);
const { stdout } = await execAsync(`npm view ${name} versions --json`);
try {
return JSON.parse(stdout);
const versions = JSON.parse(stdout);
return Array.isArray(versions) ? versions : [versions];
} catch (err) {
throw new Error(`Failed to parse output from NPM view - ${err.toString()}`);
}
Expand Down
13 changes: 13 additions & 0 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ describe('lib/index', () => {
'NPM package name: "bad name Dependency" is invalid. name can only contain URL-friendly characters'
);
});

test('should verify dependencies when npm module has only one version available, npm view returns string instead of array', async () => {
mockExports.version = '1.1.1';
mockExports.dependencies = { foo1: '1.1.1' };
mockExports.devDependencies = {};

mockExecAsync.mockImplementationOnce(() => Promise.resolve({ stdout: '"1.1.1"' }));
await verifyDeps({ dir, logger });

expect(logger.info).toHaveBeenCalledTimes(2);
expect(logger.info).toHaveBeenNthCalledWith(1, 'Verifying dependencies…\n');
expect(logger.info).toHaveBeenNthCalledWith(2, `All NPM modules are up to date.`);
});
});

module.exports = mockExports;

0 comments on commit bac7788

Please sign in to comment.