Skip to content

Commit

Permalink
fix: do not call process.exit; set process.exitCode instead
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Jul 31, 2024
1 parent 9cae5e7 commit 570f79d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/hardhat-solhint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ task("check", async (_, { run }, runSuper) => {
);

if (errorsCount > 0) {
process.exit(1);
process.exitCode = 1;
return;
}
});
14 changes: 5 additions & 9 deletions packages/hardhat-solhint/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,24 @@ describe("Solhint plugin", function () {
);
});

it("should run the check task and exit", async function () {
it("should run the check task and set the exit code to 1", async function () {
const consoleLogStub = sinon.stub(console, "log");
const processExitStub = sinon.stub(process, "exit");
await this.env.run("check");
assert.isTrue(consoleLogStub.calledOnce);
assert.isTrue(processExitStub.calledOnceWith(1));
assert.strictEqual(process.exitCode, 1);
consoleLogStub.restore();
processExitStub.restore();
process.exitCode = undefined;
});
});

describe("Project with no errors", function () {
useEnvironment("no-errors-project");

it("should run the check task and not exit", async function () {
it("should run the check task and not set the exit code", async function () {
const consoleLogStub = sinon.stub(console, "log");
const processExitStub = sinon.stub(process, "exit");
await this.env.run("check");
assert.isTrue(consoleLogStub.calledOnce);
assert.isTrue(processExitStub.notCalled);
consoleLogStub.restore();
processExitStub.restore();
assert.strictEqual(process.exitCode, undefined);
});
});

Expand Down

0 comments on commit 570f79d

Please sign in to comment.