@@ -5,13 +5,18 @@ var path = require('node:path');
55
66// Regression test for https://github.com/mochajs/mocha/issues/5380
77describe ( '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 ) {
914 exec (
1015 '"' +
1116 process . execPath +
1217 '" "' +
1318 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 } "` ,
1520 { cwd : path . join ( __dirname , '..' , '..' ) } ,
1621 function ( error , stdout ) {
1722 if ( error && ! stdout ) {
@@ -24,48 +29,26 @@ describe('support ESM only module loader packages', function () {
2429 expect ( results . tests [ index ] , 'to have property' , 'fullTitle' ) ;
2530 titles . push ( results . tests [ index ] . fullTitle ) ;
2631 }
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 ) ;
3538 done ( ) ;
3639 }
3740 ) ;
41+ }
42+
43+ it ( 'should support ESM .js extension' , function ( done ) {
44+ loadAndExpect ( 'test/compiler-esm/*.js' , done ) ;
3845 } ) ;
3946
4047 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 ) ;
7053 } ) ;
7154} ) ;
0 commit comments