@@ -5,13 +5,18 @@ var path = require('node:path');
5
5
6
6
// Regression test for https://github.com/mochajs/mocha/issues/5380
7
7
describe ( 'support ESM only module loader packages' , function ( ) {
8
- it ( 'should support ESM .js extension' , function ( done ) {
8
+ /**
9
+ * Load the filename using an ESM-only loader and expect things to work
10
+ * @param {string } filename Name of the file to load
11
+ * @param {Function } done A Mocha done callback for when the test ends
12
+ */
13
+ function loadAndExpect ( filename , done ) {
9
14
exec (
10
15
'"' +
11
16
process . execPath +
12
17
'" "' +
13
18
path . join ( 'bin' , 'mocha' ) +
14
- ' " -R json --require "@test/esm-only-loader" "test/compiler-esm/*.js"' ,
19
+ ` " -R json --require "@test/esm-only-loader" "${ filename } "` ,
15
20
{ cwd : path . join ( __dirname , '..' , '..' ) } ,
16
21
function ( error , stdout ) {
17
22
if ( error && ! stdout ) {
@@ -24,48 +29,26 @@ describe('support ESM only module loader packages', function () {
24
29
expect ( results . tests [ index ] , 'to have property' , 'fullTitle' ) ;
25
30
titles . push ( results . tests [ index ] . fullTitle ) ;
26
31
}
27
- expect (
28
- titles ,
29
- 'to contain' ,
30
- 'esm written in esm should work' ,
31
- ) . and (
32
- 'to contain' ,
33
- 'esm written in esm with top-level-await should work' ,
34
- ) . and ( 'to have length' , 2 ) ;
32
+ expect ( titles , 'to contain' , 'esm written in esm should work' )
33
+ . and (
34
+ 'to contain' ,
35
+ 'esm written in esm with top-level-await should work'
36
+ )
37
+ . and ( 'to have length' , 2 ) ;
35
38
done ( ) ;
36
39
}
37
40
) ;
41
+ }
42
+
43
+ it ( 'should support ESM .js extension' , function ( done ) {
44
+ loadAndExpect ( 'test/compiler-esm/*.js' , done ) ;
38
45
} ) ;
39
46
40
47
it ( 'should support ESM .ts extension' , function ( done ) {
41
- exec (
42
- '"' +
43
- process . execPath +
44
- '" "' +
45
- path . join ( 'bin' , 'mocha' ) +
46
- '" -R json --require "@test/esm-only-loader" "test/compiler-esm/*.ts"' ,
47
- { cwd : path . join ( __dirname , '..' , '..' ) } ,
48
- function ( error , stdout ) {
49
- if ( error && ! stdout ) {
50
- return done ( error ) ;
51
- }
52
- var results = JSON . parse ( stdout ) ;
53
- expect ( results , 'to have property' , 'tests' ) ;
54
- var titles = [ ] ;
55
- for ( var index = 0 ; index < results . tests . length ; index += 1 ) {
56
- expect ( results . tests [ index ] , 'to have property' , 'fullTitle' ) ;
57
- titles . push ( results . tests [ index ] . fullTitle ) ;
58
- }
59
- expect (
60
- titles ,
61
- 'to contain' ,
62
- 'esm written in esm should work' ,
63
- ) . and (
64
- 'to contain' ,
65
- 'esm written in esm with top-level-await should work' ,
66
- ) . and ( 'to have length' , 2 ) ;
67
- done ( ) ;
68
- }
69
- ) ;
48
+ loadAndExpect ( 'test/compiler-esm/*.ts' , done ) ;
49
+ } ) ;
50
+
51
+ it ( 'should support ESM .mjs extension' , function ( done ) {
52
+ loadAndExpect ( 'test/compiler-esm/*.mjs' , done ) ;
70
53
} ) ;
71
54
} ) ;
0 commit comments