1
1
import assert from "node:assert/strict" ;
2
- import { describe , it , afterEach } from "node:test" ;
2
+ import path from "node:path" ;
3
+ import { describe , it } from "node:test" ;
3
4
4
5
import { HardhatError } from "@ignored/hardhat-vnext-errors" ;
5
6
import {
@@ -11,16 +12,16 @@ describe("Hardhat Mocha plugin", () => {
11
12
describe ( "Success" , ( ) => {
12
13
useFixtureProject ( "test-project" ) ;
13
14
14
- afterEach ( async ( ) => {
15
- const { _resetGlobalHardhatRuntimeEnvironment } = await import (
16
- "@ignored/hardhat-vnext"
15
+ it ( "should work" , async ( ) => {
16
+ const { createHardhatRuntimeEnvironment } = await import (
17
+ "@ignored/hardhat-vnext/hre "
17
18
) ;
18
19
19
- _resetGlobalHardhatRuntimeEnvironment ( ) ;
20
- } ) ;
20
+ const hardhatConfig = await import (
21
+ path . resolve ( process . cwd ( ) , "hardhat.config.ts" )
22
+ ) ;
21
23
22
- it ( "should work" , async ( ) => {
23
- const hre = await import ( "@ignored/hardhat-vnext" ) ;
24
+ const hre = await createHardhatRuntimeEnvironment ( hardhatConfig . default ) ;
24
25
25
26
const result = await hre . tasks . getTask ( "test" ) . run ( { } ) ;
26
27
@@ -31,21 +32,20 @@ describe("Hardhat Mocha plugin", () => {
31
32
describe ( "Failure" , ( ) => {
32
33
useFixtureProject ( "invalid-mocha-config" ) ;
33
34
34
- afterEach ( async ( ) => {
35
- const { _resetGlobalHardhatRuntimeEnvironment } = await import (
36
- "@ignored/hardhat-vnext"
35
+ it ( "should fail" , async ( ) => {
36
+ const { createHardhatRuntimeEnvironment } = await import (
37
+ "@ignored/hardhat-vnext/hre "
37
38
) ;
38
39
39
- _resetGlobalHardhatRuntimeEnvironment ( ) ;
40
- } ) ;
41
-
42
- it ( "should fail" , async ( ) => {
43
40
const errors =
44
41
"\t* Config error in config.mocha.delay: Expected boolean, received number" ;
45
42
43
+ const hardhatConfig = await import (
44
+ path . resolve ( process . cwd ( ) , "hardhat.config.ts" )
45
+ ) ;
46
+
46
47
await assertRejectsWithHardhatError (
47
- // @ts -expect-error -- we need to invalidate the import cache to re-import the HRE
48
- import ( "@ignored/hardhat-vnext?config=invalid" ) ,
48
+ createHardhatRuntimeEnvironment ( hardhatConfig . default ) ,
49
49
HardhatError . ERRORS . GENERAL . INVALID_CONFIG ,
50
50
{ errors } ,
51
51
) ;
0 commit comments