diff --git a/packages/hardhat-core/test/builtin-tasks/flatten.ts b/packages/hardhat-core/test/builtin-tasks/flatten.ts index cc5c508816..6249b3cf1c 100644 --- a/packages/hardhat-core/test/builtin-tasks/flatten.ts +++ b/packages/hardhat-core/test/builtin-tasks/flatten.ts @@ -416,14 +416,17 @@ describe("Flatten task", () => { it("should write to an output file when the parameter output is specified", async function () { const outputFile = `${tmpdir()}/flatten.sol`; - await this.env.run(TASK_FLATTEN, { - files: ["contracts/A.sol", "contracts/D.sol"], - output: outputFile, - }); - const expected = await getExpectedSol(); - const actual = readFileSync(outputFile, "utf8"); - assert.equal(actual, expected); - removeSync(outputFile); + try { + await this.env.run(TASK_FLATTEN, { + files: ["contracts/A.sol", "contracts/D.sol"], + output: outputFile, + }); + const expected = await getExpectedSol(); + const actual = readFileSync(outputFile, "utf8"); + assert.equal(actual, expected); + } finally { + removeSync(outputFile); + } }); describe("No contracts to flatten", () => {