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,18 @@ 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
22
+ . resolve ( process . cwd ( ) , "hardhat.config.ts" )
23
+ . replaceAll ( "/" , path . sep )
24
+ ) ;
21
25
22
- it ( "should work" , async ( ) => {
23
- const hre = await import ( "@ignored/hardhat-vnext" ) ;
26
+ const hre = await createHardhatRuntimeEnvironment ( hardhatConfig . default ) ;
24
27
25
28
const result = await hre . tasks . getTask ( "test" ) . run ( { } ) ;
26
29
@@ -31,21 +34,22 @@ describe("Hardhat Mocha plugin", () => {
31
34
describe ( "Failure" , ( ) => {
32
35
useFixtureProject ( "invalid-mocha-config" ) ;
33
36
34
- afterEach ( async ( ) => {
35
- const { _resetGlobalHardhatRuntimeEnvironment } = await import (
36
- "@ignored/hardhat-vnext"
37
+ it ( "should fail" , async ( ) => {
38
+ const { createHardhatRuntimeEnvironment } = await import (
39
+ "@ignored/hardhat-vnext/hre "
37
40
) ;
38
41
39
- _resetGlobalHardhatRuntimeEnvironment ( ) ;
40
- } ) ;
41
-
42
- it ( "should fail" , async ( ) => {
43
42
const errors =
44
43
"\t* Config error in config.mocha.delay: Expected boolean, received number" ;
45
44
45
+ const hardhatConfig = await import (
46
+ path
47
+ . resolve ( process . cwd ( ) , "hardhat.config.ts" )
48
+ . replaceAll ( "/" , path . sep )
49
+ ) ;
50
+
46
51
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" ) ,
52
+ createHardhatRuntimeEnvironment ( hardhatConfig . default ) ,
49
53
HardhatError . ERRORS . GENERAL . INVALID_CONFIG ,
50
54
{ errors } ,
51
55
) ;
0 commit comments