Skip to content

Commit

Permalink
Filter out entered dependencies without a version
Browse files Browse the repository at this point in the history
  • Loading branch information
jafeltra committed Feb 4, 2025
1 parent e0ace2a commit 1c217a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export function sliceDependency(dependencies) {
return trimmedDep;
}
const [packageId, version] = trimmedDep.split('#');
if (version == null) {
// Don't include the dependency if a version wasn't provided (or there was a typo and no # was provided)
return;
}
return { packageId, version };
})
.filter((d) => d); // filter out any empty strings
Expand Down
14 changes: 10 additions & 4 deletions tests/utils/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { sliceDependency } from '../../src/utils/helpers';
describe('#sliceDependency()', () => {
it('should correctly parse a given array of dependencies', () => {
const input = 'hl7.fhir.us.core#3.1.1, , testing#123';
const returnArr = sliceDependency(input);
expect(returnArr).toEqual([
const dependencies = sliceDependency(input);
expect(dependencies).toEqual([
{ packageId: 'hl7.fhir.us.core', version: '3.1.1' },
{ packageId: 'testing', version: '123' }
]);
});

it('should correctly parse an empty array of dependencies', () => {
const input = '';
const returnArr = sliceDependency(input);
expect(returnArr).toEqual([]);
const dependencies = sliceDependency(input);
expect(dependencies).toEqual([]);
});

it('should filter out dependencies that do not specify a version', () => {
const input = '[email protected], hl7.fhir.us.core#3.1.1, hl7.fhir.example.noversion';
const dependencies = sliceDependency(input);
expect(dependencies).toEqual([{ packageId: 'hl7.fhir.us.core', version: '3.1.1' }]);
});
});

0 comments on commit 1c217a9

Please sign in to comment.