Skip to content

Commit

Permalink
Add regression test for corrupted packages
Browse files Browse the repository at this point in the history
  • Loading branch information
agoldis committed Feb 2, 2018
1 parent 70e7716 commit 9ab2dfb
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
2 changes: 0 additions & 2 deletions __tests__/commands/add.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* @flow */

import type {Prompt} from 'inquirer';

import {ConsoleReporter} from '../../src/reporters/index.js';
import * as reporters from '../../src/reporters/index.js';
import {
Expand Down
9 changes: 8 additions & 1 deletion __tests__/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ test('list', async (): Promise<void> => {
});
});

test('ls with scoped package', async (): Promise<void> => {
test('list skips corrupted package', async (): Promise<void> => {
await runCache(['list'], {}, 'corrupted', (config, reporter, stdout) => {
expect(stdout).not.toContain(JSON.stringify('corrupted'));
expect(stdout).toContain(JSON.stringify('good-module'));
});
});

test('ls with scoped packages', async (): Promise<void> => {
await runInstall({}, 'install-from-authed-private-registry', async (config): Promise<void> => {
const reporter = new BufferReporter();
await run(config, reporter, {}, ['list']);
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"manifest": {
"name": "corrupted",
"json-misformatted"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"manifest": {
"name": "good-module",
"version": "0.0.0"
}
}
8 changes: 5 additions & 3 deletions src/cli/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ async function getPackagesPaths(config, currentPath): Object {

async function getCachedPackages(config): Object {
const paths = await getPackagesPaths(config, config.cacheFolder);
return Promise.all(paths.map(config.readPackageMetadata.bind(config)));
return Promise.all(paths.map(path => config.readPackageMetadata(path).catch(error => undefined))).then(packages =>
packages.filter(p => !!p),
);
}

async function list(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
const filterOut = ({registry, package: manifest, remote}) => {
const filterOut = ({registry, package: manifest, remote} = {}) => {
if (flags.pattern && !micromatch.contains(manifest.name, flags.pattern)) {
return false;
}
return true;
};

const forReport = ({registry, package: manifest, remote}) => [
const forReport = ({registry, package: manifest, remote} = {}) => [
manifest.name,
manifest.version,
registry,
Expand Down

0 comments on commit 9ab2dfb

Please sign in to comment.