From af84d41471f2e84be9f6a565eb5a22bce4790013 Mon Sep 17 00:00:00 2001 From: ChrisD <18092467+ChristopherDedominici@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:04:25 +0100 Subject: [PATCH] use flag to initialize chai-matchers only one --- .../src/internal/hook-handlers/network.ts | 7 ++++++- .../test/multi-network-connections.ts | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/v-next/hardhat-chai-matchers/src/internal/hook-handlers/network.ts b/v-next/hardhat-chai-matchers/src/internal/hook-handlers/network.ts index 14d528c730..ba9bb2d835 100644 --- a/v-next/hardhat-chai-matchers/src/internal/hook-handlers/network.ts +++ b/v-next/hardhat-chai-matchers/src/internal/hook-handlers/network.ts @@ -10,12 +10,17 @@ import type { import { addChaiMatchers } from "../add-chai-matchers.js"; export default async (): Promise> => { + let isInitialized = false; + const handlers: Partial = { async newConnection( context: HookContext, next: (context: HookContext) => Promise>, ) { - addChaiMatchers(); + if (!isInitialized) { + addChaiMatchers(); + isInitialized = true; + } return next(context); }, diff --git a/v-next/hardhat-chai-matchers/test/multi-network-connections.ts b/v-next/hardhat-chai-matchers/test/multi-network-connections.ts index 90c899d7f7..c9f4060ccd 100644 --- a/v-next/hardhat-chai-matchers/test/multi-network-connections.ts +++ b/v-next/hardhat-chai-matchers/test/multi-network-connections.ts @@ -11,9 +11,7 @@ import { createHardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/hre"; import hardhatEthersPlugin from "@ignored/hardhat-vnext-ethers"; import { expect } from "chai"; -import { addChaiMatchers } from "../src/internal/add-chai-matchers.js"; - -addChaiMatchers(); +import hardhatChaiMatchersPlugin from "../src/index.js"; describe("handle multiple connections", () => { let sender: HardhatEthersSigner; @@ -30,7 +28,7 @@ describe("handle multiple connections", () => { before(async () => { const hre = await createHardhatRuntimeEnvironment({ - plugins: [hardhatEthersPlugin], + plugins: [hardhatChaiMatchersPlugin, hardhatEthersPlugin], networks: { test1: { type: "edr",