hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
46 lines • 2.08 kB
JavaScript
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import chalk from "chalk";
import { HardhatRuntimeEnvironmentImplementation } from "../../core/hre.js";
import { GasAnalyticsManagerImplementation } from "./gas-analytics-manager.js";
import { testRunDone, testRunStart, testWorkerDone, } from "./hook-handlers/test.js";
export function getGasAnalyticsManager(hookContextOrHre) {
assertHardhatInvariant("_gasAnalytics" in hookContextOrHre &&
hookContextOrHre._gasAnalytics instanceof
GasAnalyticsManagerImplementation, "Expected _gasAnalytics to be an instance of GasAnalyticsManagerImplementation");
return hookContextOrHre._gasAnalytics;
}
export function setGasAnalyticsManager(hre, gasAnalyticsManager) {
assertHardhatInvariant(hre instanceof HardhatRuntimeEnvironmentImplementation, "Expected HRE to be an instance of HardhatRuntimeEnvironmentImplementation");
hre._gasAnalytics = gasAnalyticsManager;
}
/**
* The following helpers are kept for backward compatibility with older versions
* of test runner plugins (hardhat-mocha, hardhat-node-test-runner) that import
* from "hardhat/internal/gas-analytics".
*/
export async function markTestRunStart(id) {
const { default: hre } = await import("../../../index.js");
await testRunStart(hre, id);
}
export async function markTestWorkerDone(id) {
const { default: hre } = await import("../../../index.js");
await testWorkerDone(hre, id);
}
export async function markTestRunDone(id) {
const { default: hre } = await import("../../../index.js");
await testRunDone(hre, id);
}
export function formatSectionHeader(sectionName, { changedLength, addedLength, removedLength, }) {
const parts = [];
if (changedLength > 0) {
parts.push(`${changedLength} changed`);
}
if (addedLength > 0) {
parts.push(`${addedLength} added`);
}
if (removedLength > 0) {
parts.push(`${removedLength} removed`);
}
return `${sectionName}: ${chalk.gray(parts.join(", "))}`;
}
//# sourceMappingURL=helpers.js.map