Skip to content

Commit

Permalink
fix: Handle NPM 7+'s message (error) response (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnturner committed May 17, 2022
1 parent 543fbe8 commit ea8bc44
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/npm-auditer.ts
Expand Up @@ -119,6 +119,8 @@ export async function audit(config: AuditCiConfig, reporter = reportAudit) {
if ("error" in parsedOutput) {
const { code, summary } = parsedOutput.error;
throw new Error(`code ${code}: ${summary}`);
} else if ("message" in parsedOutput) {
throw new Error(parsedOutput.message);
}
return report(parsedOutput, config, reporter);
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -62,7 +62,7 @@
"@types/yargs": "^17.0.9",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"audit-types": "^0.5.0",
"audit-types": "^0.5.1",
"chai": "^4.3.6",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
14 changes: 14 additions & 0 deletions test/npm7-auditer.spec.js
Expand Up @@ -277,6 +277,20 @@ describe("npm7-auditer", () => {
done();
});
});
it("fails with error code ECONNREFUSED on a live site with no registry", (done) => {
audit(
config({
directory: testDirectory("npm-low"),
levels: { low: true },
registry: "http://localhost",
})
)
.catch((error) => {
expect(error.message).to.include("ECONNREFUSED");
done();
})
.catch((error) => done(error));
});
it("reports summary with no vulnerabilities when critical devDependency and skip-dev is true", () => {
const summary = report(
reportNpmSkipDevelopment,
Expand Down

0 comments on commit ea8bc44

Please sign in to comment.