Skip to content

Commit

Permalink
Add forceTerminalOutputFormat option (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Feb 28, 2024
1 parent 6b7758b commit fa09272
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"eslint": "eslint 'src/**/*.ts' 'test/**/*.ts' -c ./eslintrc.js",
"test": "scripts/run-tests.sh",
"test:integration": "mocha test/integration/*.ts --timeout 100000 --exit",
"test:unit": "mocha test/unit/*.ts",
"test:unit": "mocha test/unit/*.ts --timeout 10000",
"prepublishOnly": "tsc --project tsconfig.prod.json",
"build": "tsc --project tsconfig.prod.json",
"buidl": "tsc",
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ start_hardhat_node() {
########
# Units
########
npx mocha test/unit/*.ts
npx mocha test/unit/*.ts --timeout 10000

########
# Tasks
Expand Down
7 changes: 7 additions & 0 deletions src/lib/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ export function render(hre: HardhatRuntimeEnvironment, data: GasData, options: G
if (options.forceTerminalOutput){
const originalOutputFile = options.outputFile;
const originalNoColors = options.noColors;
const originalReportFormat = options.reportFormat;

options.outputFile = undefined;
options.noColors = false;

options.reportFormat = (options.forceTerminalOutputFormat)
? options.forceTerminalOutputFormat
: options.reportFormat;

table = getTableForFormat(hre, data, options);
console.log(table);

// Reset the options, since they might be read in JSON below here
options.outputFile = originalOutputFile;
options.noColors = originalNoColors;
options.reportFormat = originalReportFormat;
}
} else {
console.log(table);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export interface GasReporterOptions {
/** @property Write to terminal even when saving output to file */
forceTerminalOutput?: boolean;

/** @property Table format to output forced terminal output in */
forceTerminalOutputFormat?: 'legacy' | 'terminal' | 'markdown';

/** @property Gwei price per gas unit (eg: 20) */
gasPrice?: number;

Expand Down
3 changes: 3 additions & 0 deletions test/integration/options.b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe("Options B", function () {
assert.equal(options.token, "ETC");
assert.equal(options.tokenPrice, "200.00");
assert.equal(options.gasPrice, 40);
assert.equal(options.forceTerminalOutput, true);
assert.equal(options.forceTerminalOutputFormat, 'legacy');
assert.equal(options.reportFormat, 'terminal');
});

it("wrote table to file", function () {
Expand Down
4 changes: 3 additions & 1 deletion test/projects/options/hardhat.options.b.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* TESTS:
* + user-configured token and gasPrice
* + write-to-custom-file-name (JSON & txt)
* + force terminal output w/ custom output
* + show uncalled methods
*/

Expand Down Expand Up @@ -35,7 +36,8 @@ const config: HardhatUserConfig = {
showUncalledMethods: true,
outputFile: "./testGasReport.txt",
outputJSONFile: "./gas.json",
forceTerminalOutput: true
forceTerminalOutput: true,
forceTerminalOutputFormat: 'legacy'
}
};

Expand Down

0 comments on commit fa09272

Please sign in to comment.