File tree 3 files changed +24
-7
lines changed
packages/hardhat-core/src
3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " hardhat " : patch
3
+ ---
4
+
5
+ Added support for ESM test files
Original file line number Diff line number Diff line change @@ -7,7 +7,11 @@ import { HARDHAT_NETWORK_NAME } from "../internal/constants";
7
7
import { subtask , task } from "../internal/core/config/config-env" ;
8
8
import { HardhatError } from "../internal/core/errors" ;
9
9
import { ERRORS } from "../internal/core/errors-list" ;
10
- import { isRunningWithTypescript } from "../internal/core/typescript-support" ;
10
+ import {
11
+ isJavascriptFile ,
12
+ isRunningWithTypescript ,
13
+ isTypescriptFile ,
14
+ } from "../internal/core/typescript-support" ;
11
15
import { getForkCacheDirPath } from "../internal/hardhat-network/provider/utils/disk-cache" ;
12
16
import { showForkRecommendationsBannerIfNecessary } from "../internal/hardhat-network/provider/utils/fork-recomendations-banner" ;
13
17
import { pluralize } from "../internal/util/strings" ;
@@ -40,7 +44,7 @@ subtask(TASK_TEST_GET_TEST_FILES)
40
44
41
45
const jsFiles = await getAllFilesMatching (
42
46
config . paths . tests ,
43
- ( f ) => f . endsWith ( ".js" ) || f . endsWith ( ".cjs" ) || f . endsWith ( ".mjs" )
47
+ isJavascriptFile
44
48
) ;
45
49
46
50
if ( ! isRunningWithTypescript ( config ) ) {
@@ -49,7 +53,7 @@ subtask(TASK_TEST_GET_TEST_FILES)
49
53
50
54
const tsFiles = await getAllFilesMatching (
51
55
config . paths . tests ,
52
- ( f ) => f . endsWith ( ".ts" ) || f . endsWith ( ".cts" )
56
+ isTypescriptFile
53
57
) ;
54
58
55
59
return [ ...jsFiles , ...tsFiles ] ;
Original file line number Diff line number Diff line change @@ -13,14 +13,14 @@ let cachedIsTypescriptSupported: boolean | undefined;
13
13
*/
14
14
export function willRunWithTypescript ( configPath ?: string ) : boolean {
15
15
const config = resolveConfigPath ( configPath ) ;
16
- return isTypescriptFile ( config ) ;
16
+ return isNonEsmTypescriptFile ( config ) ;
17
17
}
18
18
19
19
/**
20
20
* Returns true if an Hardhat is already running with typescript.
21
21
*/
22
22
export function isRunningWithTypescript ( config : HardhatConfig ) : boolean {
23
- return isTypescriptFile ( config . paths . configFile ) ;
23
+ return isNonEsmTypescriptFile ( config . paths . configFile ) ;
24
24
}
25
25
26
26
export function isTypescriptSupported ( ) {
@@ -80,6 +80,14 @@ export function loadTsNode(
80
80
require ( tsNodeRequirement ) ;
81
81
}
82
82
83
- function isTypescriptFile ( path : string ) : boolean {
84
- return path . endsWith ( ".ts" ) || path . endsWith ( ".cts" ) ;
83
+ function isNonEsmTypescriptFile ( path : string ) : boolean {
84
+ return / \. ( t s | c t s ) $ / i. test ( path ) ;
85
+ }
86
+
87
+ export function isTypescriptFile ( path : string ) : boolean {
88
+ return / \. ( t s | c t s | m t s ) $ / i. test ( path ) ;
89
+ }
90
+
91
+ export function isJavascriptFile ( path : string ) : boolean {
92
+ return / \. ( j s | c j s | m j s ) $ / i. test ( path ) ;
85
93
}
You can’t perform that action at this time.
0 commit comments