-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5807 from NomicFoundation/fix/deflake-init-tests
fix: disable console for init tests
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { after, before } from "node:test"; | ||
|
||
/** | ||
* Disables the console functions that directly interact with stdout/stderr. | ||
* | ||
* This function is useful when you want to test a function that use console | ||
* logging but you don't want to see the output in the test report. | ||
* In particular, we have observed that using console.log can cause errors like: | ||
* - Error: Unable to deserialize cloned data due to invalid or unsupported version. | ||
* | ||
* This function overwrites the original console.log/console.warn/console.dir | ||
* with no-op functions. | ||
* | ||
* If we ever want to inspect the stdout/stderr, we could accept | ||
* NodeJS.WritableStream arguments and write formatted messages to them instead. | ||
* | ||
* Another interesting extension to this function would be not to disable the | ||
* console streams if a DEBUG flag is set in the environment. | ||
*/ | ||
export function disableConsole(): void { | ||
const originalLog = console.log; | ||
const originalWarn = console.warn; | ||
const originalDir = console.dir; | ||
|
||
before(() => { | ||
console.log = () => {}; | ||
console.warn = () => {}; | ||
console.dir = () => {}; | ||
}); | ||
|
||
after(() => { | ||
console.log = originalLog; | ||
console.warn = originalWarn; | ||
console.dir = originalDir; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./console.js"; | ||
export * from "./fixture-projects.js"; | ||
export * from "./hardhat-error.js"; | ||
export * from "./fs.js"; | ||
export * from "./hardhat-error.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters