Skip to content

Commit

Permalink
fix: properly handle non-existing dependencies (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneslumpe authored Jun 19, 2019
1 parent 36c37db commit 3aee569
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/cli/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ Dependency sets
});
});

describe('non existing dependencies in sets', () => {
it('should not fail', async () => {
await executeCliWithCopiedConfigFixture(
'check/simple-config-non-existing-dep',
)('check', '--verbose');
expect(getCleanedMockStdout()).toBe(trim`
┌─────────────┬───────────┬─────────┬────────┬───────────────────────────────┐
│Application │Dependency │Installed│Required│Valid │
├─────────────┼───────────┼─────────┼────────┼───────────────────────────────┤
│application_a│nonexisting│- │1.x │⚠ Infinity days left to upgrade│
└─────────────┴───────────┴─────────┴────────┴───────────────────────────────┘
Check tentatively passed!
`);
});
});

describe('some invalid entries within grace period', () => {
// needs to be in sync with value used in config fixtures
const DEPENDENCY_ADDED_DATE = 1560081600000;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/versionCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function colorTextForStatus(
function getDependencyResultRow(result: DependencyResult): HorizontalTableRow {
return [
colorTextForStatus(result.dependency, result.result),
colorTextForStatus(result.currentVersion, result.result),
colorTextForStatus(result.currentVersion || '-', result.result),
colorTextForStatus(result.requiredVersion, result.result),
result.result === 'TENTATIVE_PASS'
? `${logSymbols.warning} ${formatDuration(
Expand Down
26 changes: 15 additions & 11 deletions src/core/versionCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,22 @@ export function checkDependencies({
for (const application of applicationsToCheck) {
const dependencyVersion =
dependenciesByApplication[application.path][dependency];
// TODO fix directly value access
const { value } = getMinSemverVersion(
dependencyVersion,
dependency,
);
if (value instanceof Error) {
throw value;
// instantly fail if dependency does not exist at all
let dependencySatisfied = !!dependencyVersion;
if (dependencyVersion) {
// TODO fix directly value access
const { value } = getMinSemverVersion(
dependencyVersion,
dependency,
);
if (value instanceof Error) {
throw value;
}
dependencySatisfied = semver.satisfies(
value,
semver.validRange(requiredDependencyVersion),
);
}
const dependencySatisfied = semver.satisfies(
value,
semver.validRange(requiredDependencyVersion),
);
const appResult =
applicationDependencyResults[application.path] ||
(applicationDependencyResults[application.path] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "application-a",
"dependencies": {
"dep_a": "^1.0.0",
"dep_b": "1.2.3",
"dep_c": "~1.5.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"all-valid-a": {
"applications": [{ "path": "application_a", "name": "application-a"}],
"dependencies": {
"public": {
"dependencySemvers": {
"nonexisting": {
"dateAdded": 1560081600000,
"semver": "nonexisting@1.x"
}
},
"gracePeriod": Infinity
}
}
}
}

0 comments on commit 3aee569

Please # to comment.