@@ -4,7 +4,10 @@ import { describe, it } from "node:test";
4
4
import { createHardhatRuntimeEnvironment } from "../../src/hre.js" ;
5
5
import { builtinPlugins } from "../../src/internal/builtin-plugins/index.js" ;
6
6
import { resolveConfigPath } from "../../src/internal/helpers/config-loading.js" ;
7
- import { getHardhatRuntimeEnvironmentSingleton } from "../../src/internal/hre-singleton.js" ;
7
+ import {
8
+ getHardhatRuntimeEnvironmentSingleton ,
9
+ resetHardhatRuntimeEnvironmentSingleton ,
10
+ } from "../../src/internal/hre-singleton.js" ;
8
11
import { useFixtureProject } from "../helpers/project.js" ;
9
12
10
13
describe ( "HRE" , ( ) => {
@@ -13,6 +16,8 @@ describe("HRE", () => {
13
16
const hre = await createHardhatRuntimeEnvironment ( { } ) ;
14
17
15
18
assert . deepEqual ( hre . config . plugins , builtinPlugins ) ;
19
+
20
+ resetHardhatRuntimeEnvironmentSingleton ( ) ;
16
21
} ) ;
17
22
} ) ;
18
23
@@ -32,22 +37,24 @@ describe("HRE", () => {
32
37
{ id : "custom task" } ,
33
38
) ;
34
39
assert . deepEqual ( hre1 , hre2 ) ;
40
+
41
+ resetHardhatRuntimeEnvironmentSingleton ( ) ;
35
42
} ) ;
36
43
} ) ;
37
44
38
45
describe ( "config loading" , ( ) => {
39
46
describe ( "resolveConfigPath" , async ( ) => {
40
47
it ( "should return the HARDHAT_CONFIG env variable if it is set" , async ( ) => {
41
- process . env . HARDHAT_CONFIG = "hardhat .config.js" ;
48
+ process . env . HARDHAT_CONFIG = "env .config.js" ;
42
49
43
- assert . equal ( await resolveConfigPath ( ) , "hardhat .config.js" ) ;
50
+ assert . equal ( await resolveConfigPath ( ) , "env .config.js" ) ;
44
51
45
52
delete process . env . HARDHAT_CONFIG ;
46
53
} ) ;
47
54
48
55
it ( "should throw if the config file is not found" , async ( ) => {
49
56
await assert . rejects ( resolveConfigPath ( ) , {
50
- message : "No Hardhat config file found" ,
57
+ message : "HHE5: No Hardhat config file found" ,
51
58
} ) ;
52
59
} ) ;
53
60
@@ -96,18 +103,15 @@ describe("HRE", () => {
96
103
} ) ;
97
104
} ) ;
98
105
99
- // This test works individually but fails when running all tests
100
- // due to the hre singleton being used in tests above.
101
- // ESM modules cache is not accessible like `require.cache` in CJS,
102
- // so a workaround is needed.
103
- // TODO: Fix this test
104
- describe . skip ( "programmatic API" , ( ) => {
106
+ describe ( "programmatic API" , ( ) => {
105
107
useFixtureProject ( "loaded-config" ) ;
106
108
107
109
it ( "should load the config file" , async ( ) => {
108
110
const hre = await import ( "../../src/index.js" ) ;
109
111
110
112
assert . deepEqual ( hre . config . plugins , [ { id : "test-plugin" } ] ) ;
113
+
114
+ resetHardhatRuntimeEnvironmentSingleton ( ) ;
111
115
} ) ;
112
116
} ) ;
113
117
} ) ;
0 commit comments