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