@@ -3,14 +3,21 @@ import { describe, it } from "node:test";
3
3
4
4
import { createHardhatRuntimeEnvironment } from "../../src/hre.js" ;
5
5
import { builtinPlugins } from "../../src/internal/builtin-plugins/index.js" ;
6
- import { getHardhatRuntimeEnvironmentSingleton } from "../../src/internal/hre-singleton.js" ;
6
+ import { resolveConfigPath } from "../../src/internal/helpers/config-loading.js" ;
7
+ import {
8
+ getHardhatRuntimeEnvironmentSingleton ,
9
+ resetHardhatRuntimeEnvironmentSingleton ,
10
+ } from "../../src/internal/hre-singleton.js" ;
11
+ import { useFixtureProject } from "../helpers/project.js" ;
7
12
8
13
describe ( "HRE" , ( ) => {
9
14
describe ( "createHardhatRuntimeEnvironment" , ( ) => {
10
15
it ( "should include the built-in plugins" , async ( ) => {
11
16
const hre = await createHardhatRuntimeEnvironment ( { } ) ;
12
17
13
18
assert . deepEqual ( hre . config . plugins , builtinPlugins ) ;
19
+
20
+ resetHardhatRuntimeEnvironmentSingleton ( ) ;
14
21
} ) ;
15
22
} ) ;
16
23
@@ -30,6 +37,82 @@ describe("HRE", () => {
30
37
{ id : "custom task" } ,
31
38
) ;
32
39
assert . deepEqual ( hre1 , hre2 ) ;
40
+
41
+ resetHardhatRuntimeEnvironmentSingleton ( ) ;
42
+ } ) ;
43
+ } ) ;
44
+
45
+ describe ( "config loading" , ( ) => {
46
+ describe ( "resolveConfigPath" , async ( ) => {
47
+ it ( "should return the HARDHAT_CONFIG env variable if it is set" , async ( ) => {
48
+ process . env . HARDHAT_CONFIG = "env.config.js" ;
49
+
50
+ assert . equal ( await resolveConfigPath ( ) , "env.config.js" ) ;
51
+
52
+ delete process . env . HARDHAT_CONFIG ;
53
+ } ) ;
54
+
55
+ it ( "should throw if the config file is not found" , async ( ) => {
56
+ await assert . rejects ( resolveConfigPath ( ) , {
57
+ message : "HHE5: No Hardhat config file found" ,
58
+ } ) ;
59
+ } ) ;
60
+
61
+ describe ( "javascript config" , ( ) => {
62
+ describe ( "current dir" , ( ) => {
63
+ useFixtureProject ( "config-js" ) ;
64
+
65
+ it ( "should load a config file in the current directory" , async ( ) => {
66
+ const configPath = await resolveConfigPath ( ) ;
67
+
68
+ assert ( configPath . endsWith ( "hardhat.config.js" ) ) ;
69
+ } ) ;
70
+ } ) ;
71
+
72
+ describe ( "nested dir" , ( ) => {
73
+ useFixtureProject ( "config-js" , "nested-folder" ) ;
74
+
75
+ it ( "should load a config file in the parent directory" , async ( ) => {
76
+ const configPath = await resolveConfigPath ( ) ;
77
+
78
+ assert ( configPath . endsWith ( "hardhat.config.js" ) ) ;
79
+ } ) ;
80
+ } ) ;
81
+ } ) ;
82
+
83
+ describe ( "typescript config" , ( ) => {
84
+ describe ( "current dir" , ( ) => {
85
+ useFixtureProject ( "config-ts" ) ;
86
+
87
+ it ( "should load a config file in the current directory" , async ( ) => {
88
+ const configPath = await resolveConfigPath ( ) ;
89
+
90
+ assert ( configPath . endsWith ( "hardhat.config.ts" ) ) ;
91
+ } ) ;
92
+ } ) ;
93
+
94
+ describe ( "nested dir" , ( ) => {
95
+ useFixtureProject ( "config-ts" , "nested-folder" ) ;
96
+
97
+ it ( "should load a config file in the parent directory" , async ( ) => {
98
+ const configPath = await resolveConfigPath ( ) ;
99
+
100
+ assert ( configPath . endsWith ( "hardhat.config.ts" ) ) ;
101
+ } ) ;
102
+ } ) ;
103
+ } ) ;
104
+ } ) ;
105
+
106
+ describe ( "programmatic API" , ( ) => {
107
+ useFixtureProject ( "loaded-config" ) ;
108
+
109
+ it ( "should load the config file" , async ( ) => {
110
+ const hre = await import ( "../../src/index.js" ) ;
111
+
112
+ assert . deepEqual ( hre . config . plugins , [ { id : "test-plugin" } ] ) ;
113
+
114
+ resetHardhatRuntimeEnvironmentSingleton ( ) ;
115
+ } ) ;
33
116
} ) ;
34
117
} ) ;
35
118
} ) ;
0 commit comments