1
1
import assert from "node:assert/strict" ;
2
- import { describe , it } from "node:test" ;
2
+ import { describe , it , afterEach } from "node:test" ;
3
3
4
- import { useFixtureProject } from "@nomicfoundation/hardhat-test-utils" ;
4
+ import { HardhatError } from "@ignored/hardhat-vnext-errors" ;
5
+ import {
6
+ assertRejectsWithHardhatError ,
7
+ useFixtureProject ,
8
+ } from "@nomicfoundation/hardhat-test-utils" ;
5
9
6
10
describe ( "Hardhat Mocha plugin" , ( ) => {
7
11
describe ( "Success" , ( ) => {
8
12
useFixtureProject ( "test-project" ) ;
9
13
14
+ afterEach ( async ( ) => {
15
+ const { _resetGlobalHardhatRuntimeEnvironment } = await import (
16
+ "@ignored/hardhat-vnext"
17
+ ) ;
18
+
19
+ _resetGlobalHardhatRuntimeEnvironment ( ) ;
20
+ } ) ;
21
+
10
22
it ( "should work" , async ( ) => {
11
23
const hre = await import ( "@ignored/hardhat-vnext" ) ;
12
24
@@ -19,10 +31,23 @@ describe("Hardhat Mocha plugin", () => {
19
31
describe ( "Failure" , ( ) => {
20
32
useFixtureProject ( "invalid-mocha-config" ) ;
21
33
34
+ afterEach ( async ( ) => {
35
+ const { _resetGlobalHardhatRuntimeEnvironment } = await import (
36
+ "@ignored/hardhat-vnext"
37
+ ) ;
38
+
39
+ _resetGlobalHardhatRuntimeEnvironment ( ) ;
40
+ } ) ;
41
+
22
42
it ( "should fail" , async ( ) => {
23
- await assert . rejects (
24
- ( ) => import ( "@ignored/hardhat-vnext" ) ,
25
- / C o n f i g e r r o r i n c o n f i g \. m o c h a \. d e l a y : E x p e c t e d b o o l e a n , r e c e i v e d n u m b e r / ,
43
+ const errors =
44
+ "\t* Config error in config.mocha.delay: Expected boolean, received number" ;
45
+
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" ) ,
49
+ HardhatError . ERRORS . GENERAL . INVALID_CONFIG ,
50
+ { errors } ,
26
51
) ;
27
52
} ) ;
28
53
} ) ;
0 commit comments