-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: restore removed export paths for backward compat with older test runners #8029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
v-next/hardhat/src/internal/builtin-plugins/coverage/exports.ts
This file contains hidden or 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,5 @@ | ||
| export { | ||
| markTestRunStart, | ||
| markTestRunDone, | ||
| markTestWorkerDone, | ||
| } from "./helpers.js"; |
27 changes: 27 additions & 0 deletions
27
v-next/hardhat/src/internal/builtin-plugins/coverage/helpers.ts
This file contains hidden or 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,5 +1,32 @@ | ||
| import path from "node:path"; | ||
|
|
||
| import { | ||
| testRunDone, | ||
| testRunStart, | ||
| testWorkerDone, | ||
| } from "./hook-handlers/test.js"; | ||
|
|
||
| export function getCoveragePath(rootPath: string): string { | ||
| return path.join(rootPath, "coverage"); | ||
| } | ||
|
|
||
| /** | ||
| * 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/coverage". | ||
| */ | ||
|
|
||
| export async function markTestRunStart(id: string): Promise<void> { | ||
| const { default: hre } = await import("../../../index.js"); | ||
| await testRunStart(hre, id); | ||
| } | ||
|
|
||
| export async function markTestWorkerDone(id: string): Promise<void> { | ||
| const { default: hre } = await import("../../../index.js"); | ||
| await testWorkerDone(hre, id); | ||
| } | ||
|
|
||
| export async function markTestRunDone(id: string): Promise<void> { | ||
| const { default: hre } = await import("../../../index.js"); | ||
| await testRunDone(hre, id); | ||
| } |
77 changes: 51 additions & 26 deletions
77
v-next/hardhat/src/internal/builtin-plugins/coverage/hook-handlers/test.ts
This file contains hidden or 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,43 +1,68 @@ | ||
| import type { TestHooks } from "../../../../types/hooks.js"; | ||
| import type { HookContext, TestHooks } from "../../../../types/hooks.js"; | ||
|
|
||
| import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors"; | ||
| import { isObject } from "@nomicfoundation/hardhat-utils/lang"; | ||
|
|
||
| import { HardhatRuntimeEnvironmentImplementation } from "../../../core/hre.js"; | ||
| import { CoverageManagerImplementation } from "../coverage-manager.js"; | ||
|
|
||
| export default async (): Promise<Partial<TestHooks>> => ({ | ||
| onTestRunStart: async (context, id, next) => { | ||
| await next(context, id); | ||
|
|
||
| if (context.globalOptions.coverage === true) { | ||
| assertHardhatInvariant( | ||
| context instanceof HardhatRuntimeEnvironmentImplementation, | ||
| "Expected context to be an instance of HardhatRuntimeEnvironmentImplementation", | ||
| ); | ||
| await context._coverage.clearData(id); | ||
| } | ||
| await testRunStart(context, id); | ||
| }, | ||
|
|
||
| onTestWorkerDone: async (context, id, next) => { | ||
| await next(context, id); | ||
|
|
||
| if (context.globalOptions.coverage === true) { | ||
| assertHardhatInvariant( | ||
| context instanceof HardhatRuntimeEnvironmentImplementation, | ||
| "Expected context to be an instance of HardhatRuntimeEnvironmentImplementation", | ||
| ); | ||
| await context._coverage.saveData(id); | ||
| } | ||
| await testWorkerDone(context, id); | ||
| }, | ||
|
|
||
| onTestRunDone: async (context, id, next) => { | ||
| await next(context, id); | ||
|
|
||
| if (context.globalOptions.coverage === true) { | ||
| assertHardhatInvariant( | ||
| context instanceof HardhatRuntimeEnvironmentImplementation, | ||
| "Expected context to be an instance of HardhatRuntimeEnvironmentImplementation", | ||
| ); | ||
| await context._coverage.report(id); | ||
| } | ||
| await testRunDone(context, id); | ||
| }, | ||
| }); | ||
|
|
||
| export async function testRunStart( | ||
| context: HookContext, | ||
| id: string, | ||
| ): Promise<void> { | ||
| if (context.globalOptions.coverage === true) { | ||
| assertHardhatInvariant( | ||
| "_coverage" in context && | ||
| isObject(context._coverage) && | ||
| context._coverage instanceof CoverageManagerImplementation, | ||
| "Expected HookContext#_coverage to be an instance of CoverageManagerImplementation", | ||
| ); | ||
| await context._coverage.clearData(id); | ||
| } | ||
| } | ||
|
|
||
| export async function testWorkerDone( | ||
| context: HookContext, | ||
| id: string, | ||
| ): Promise<void> { | ||
| if (context.globalOptions.coverage === true) { | ||
| assertHardhatInvariant( | ||
| "_coverage" in context && | ||
| isObject(context._coverage) && | ||
| context._coverage instanceof CoverageManagerImplementation, | ||
| "Expected HookContext#_coverage to be an instance of CoverageManagerImplementation", | ||
| ); | ||
| await context._coverage.saveData(id); | ||
| } | ||
| } | ||
|
|
||
| export async function testRunDone( | ||
| context: HookContext, | ||
| id: string, | ||
| ): Promise<void> { | ||
| if (context.globalOptions.coverage === true) { | ||
| assertHardhatInvariant( | ||
| "_coverage" in context && | ||
| isObject(context._coverage) && | ||
| context._coverage instanceof CoverageManagerImplementation, | ||
| "Expected HookContext#_coverage to be an instance of CoverageManagerImplementation", | ||
| ); | ||
| await context._coverage.report(id); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/exports.ts
This file contains hidden or 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,5 @@ | ||
| export { | ||
| markTestRunStart, | ||
| markTestRunDone, | ||
| markTestWorkerDone, | ||
| } from "./helpers.js"; |
26 changes: 26 additions & 0 deletions
26
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/helpers.ts
This file contains hidden or 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,26 @@ | ||
| import { | ||
| testRunDone, | ||
| testRunStart, | ||
| testWorkerDone, | ||
| } from "./hook-handlers/test.js"; | ||
|
|
||
| /** | ||
| * 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: string): Promise<void> { | ||
| const { default: hre } = await import("../../../index.js"); | ||
| await testRunStart(hre, id); | ||
| } | ||
|
|
||
| export async function markTestWorkerDone(id: string): Promise<void> { | ||
| const { default: hre } = await import("../../../index.js"); | ||
| await testWorkerDone(hre, id); | ||
| } | ||
|
|
||
| export async function markTestRunDone(id: string): Promise<void> { | ||
| const { default: hre } = await import("../../../index.js"); | ||
| await testRunDone(hre, id); | ||
| } | ||
77 changes: 51 additions & 26 deletions
77
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.ts
This file contains hidden or 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,43 +1,68 @@ | ||
| import type { TestHooks } from "../../../../types/hooks.js"; | ||
| import type { HookContext, TestHooks } from "../../../../types/hooks.js"; | ||
|
|
||
| import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors"; | ||
| import { isObject } from "@nomicfoundation/hardhat-utils/lang"; | ||
|
|
||
| import { HardhatRuntimeEnvironmentImplementation } from "../../../core/hre.js"; | ||
| import { GasAnalyticsManagerImplementation } from "../gas-analytics-manager.js"; | ||
|
|
||
| export default async (): Promise<Partial<TestHooks>> => ({ | ||
| onTestRunStart: async (context, id, next) => { | ||
| await next(context, id); | ||
|
|
||
| if (context.globalOptions.gasStats === true) { | ||
| assertHardhatInvariant( | ||
| context instanceof HardhatRuntimeEnvironmentImplementation, | ||
| "Expected context to be an instance of HardhatRuntimeEnvironmentImplementation", | ||
| ); | ||
| await context._gasAnalytics.clearGasMeasurements(id); | ||
| } | ||
| await testRunStart(context, id); | ||
| }, | ||
|
|
||
| onTestWorkerDone: async (context, id, next) => { | ||
| await next(context, id); | ||
|
|
||
| if (context.globalOptions.gasStats === true) { | ||
| assertHardhatInvariant( | ||
| context instanceof HardhatRuntimeEnvironmentImplementation, | ||
| "Expected context to be an instance of HardhatRuntimeEnvironmentImplementation", | ||
| ); | ||
| await context._gasAnalytics.saveGasMeasurements(id); | ||
| } | ||
| await testWorkerDone(context, id); | ||
| }, | ||
|
|
||
| onTestRunDone: async (context, id, next) => { | ||
| await next(context, id); | ||
|
|
||
| if (context.globalOptions.gasStats === true) { | ||
| assertHardhatInvariant( | ||
| context instanceof HardhatRuntimeEnvironmentImplementation, | ||
| "Expected context to be an instance of HardhatRuntimeEnvironmentImplementation", | ||
| ); | ||
| await context._gasAnalytics.reportGasStats(id); | ||
| } | ||
| await testRunDone(context, id); | ||
| }, | ||
| }); | ||
|
|
||
| export async function testRunStart( | ||
| context: HookContext, | ||
| id: string, | ||
| ): Promise<void> { | ||
| if (context.globalOptions.gasStats === true) { | ||
| assertHardhatInvariant( | ||
| "_gasAnalytics" in context && | ||
| isObject(context._gasAnalytics) && | ||
| context._gasAnalytics instanceof GasAnalyticsManagerImplementation, | ||
| "Expected HookContext#_gasAnalytics to be an instance of GasAnalyticsManagerImplementation", | ||
| ); | ||
| await context._gasAnalytics.clearGasMeasurements(id); | ||
| } | ||
| } | ||
|
|
||
| export async function testWorkerDone( | ||
| context: HookContext, | ||
| id: string, | ||
| ): Promise<void> { | ||
| if (context.globalOptions.gasStats === true) { | ||
| assertHardhatInvariant( | ||
| "_gasAnalytics" in context && | ||
| isObject(context._gasAnalytics) && | ||
| context._gasAnalytics instanceof GasAnalyticsManagerImplementation, | ||
| "Expected HookContext#_gasAnalytics to be an instance of GasAnalyticsManagerImplementation", | ||
| ); | ||
| await context._gasAnalytics.saveGasMeasurements(id); | ||
| } | ||
| } | ||
|
|
||
| export async function testRunDone( | ||
| context: HookContext, | ||
| id: string, | ||
| ): Promise<void> { | ||
| if (context.globalOptions.gasStats === true) { | ||
| assertHardhatInvariant( | ||
| "_gasAnalytics" in context && | ||
| isObject(context._gasAnalytics) && | ||
| context._gasAnalytics instanceof GasAnalyticsManagerImplementation, | ||
| "Expected HookContext#_gasAnalytics to be an instance of GasAnalyticsManagerImplementation", | ||
| ); | ||
| await context._gasAnalytics.reportGasStats(id); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.