Skip to content

Commit

Permalink
fix: handle empty cases for all manifests (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
arajkumar authored Feb 9, 2021
1 parent 158b1b1 commit 5a20da2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/collector/package.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class DependencyCollector implements IDependencyCollector {
constructor(public classes: Array<string> = ["dependencies"]) {}

async collect(contents: string): Promise<Array<IDependency>> {
const ast = jsonAst(contents);
const ast = jsonAst(contents || '{}');
return ast.children.
filter(c => this.classes.includes(c.key.value)).
flatMap(c => c.value.children).
Expand Down
7 changes: 7 additions & 0 deletions test/collector/go.mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ github.com/stretchr/testify`);
});
});

it('tests empty go.mod', async () => {
fake(getGoLangImportsCmd(), `github.com/alecthomas/units
github.com/stretchr/testify`);
const deps = await collector.collect(``);
expect(deps).is.eql([]);
});

it('tests empty lines in go.mod', async () => {
fake(getGoLangImportsCmd(), `github.com/alecthomas/units
github.com/stretchr/testify`);
Expand Down
5 changes: 5 additions & 0 deletions test/collector/package.json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { DependencyCollector } from '../../src/collector/package.json';
describe('npm package.json parser test', () => {
const collector = new DependencyCollector();

it('tests empty package.json file content', async () => {
const deps = await collector.collect(``);
expect(deps.length).equal(0);
});

it('tests empty package.json', async () => {
const deps = await collector.collect(`
{}
Expand Down
5 changes: 5 additions & 0 deletions test/collector/requirements.txt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ describe('PyPi requirements.txt parser test', () => {
}]);
});

it('tests empty requirements.txt', async () => {
const deps = await collector.collect(``);
expect(deps).is.eql([]);
});

it('tests empty lines', async () => {
const deps = await collector.collect(`
Expand Down

0 comments on commit 5a20da2

Please sign in to comment.