|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var exec = require('node:child_process').exec; |
| 4 | +var path = require('node:path'); |
| 5 | + |
| 6 | +// Regression test for https://github.com/mochajs/mocha/issues/5380 |
| 7 | +describe('support ESM only module loader packages', function () { |
| 8 | + it('should support ESM .js extension', function (done) { |
| 9 | + exec( |
| 10 | + '"' + |
| 11 | + process.execPath + |
| 12 | + '" "' + |
| 13 | + path.join('bin', 'mocha') + |
| 14 | + '" -R json --require "@test/esm-only-loader" "test/compiler-esm/*.js"', |
| 15 | + {cwd: path.join(__dirname, '..', '..')}, |
| 16 | + function (error, stdout) { |
| 17 | + if (error && !stdout) { |
| 18 | + return done(error); |
| 19 | + } |
| 20 | + var results = JSON.parse(stdout); |
| 21 | + expect(results, 'to have property', 'tests'); |
| 22 | + var titles = []; |
| 23 | + for (var index = 0; index < results.tests.length; index += 1) { |
| 24 | + expect(results.tests[index], 'to have property', 'fullTitle'); |
| 25 | + titles.push(results.tests[index].fullTitle); |
| 26 | + } |
| 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); |
| 35 | + done(); |
| 36 | + } |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + 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 | + ); |
| 70 | + }); |
| 71 | +}); |
0 commit comments