|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var exec = require('node:child_process').exec; |
| 4 | +var path = require('node:path'); |
| 5 | + |
| 6 | +describe('support CJS require.extension compilers with esm syntax', function () { |
| 7 | + it('should support .js extension', function (done) { |
| 8 | + exec( |
| 9 | + '"' + |
| 10 | + process.execPath + |
| 11 | + '" "' + |
| 12 | + path.join('bin', 'mocha') + |
| 13 | + '" -R json --require test/compiler-fixtures/js.fixture "test/compiler-cjs/*.js"', |
| 14 | + {cwd: path.join(__dirname, '..', '..')}, |
| 15 | + function (error, stdout) { |
| 16 | + if (error && !stdout) { |
| 17 | + return done(error); |
| 18 | + } |
| 19 | + var results = JSON.parse(stdout); |
| 20 | + expect(results, 'to have property', 'tests'); |
| 21 | + var titles = []; |
| 22 | + for (var index = 0; index < results.tests.length; index += 1) { |
| 23 | + expect(results.tests[index], 'to have property', 'fullTitle'); |
| 24 | + titles.push(results.tests[index].fullTitle); |
| 25 | + } |
| 26 | + expect( |
| 27 | + titles, |
| 28 | + 'to contain', |
| 29 | + 'cjs written in esm should work', |
| 30 | + ).and('to have length', 1); |
| 31 | + done(); |
| 32 | + } |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should support .ts extension', function (done) { |
| 37 | + exec( |
| 38 | + '"' + |
| 39 | + process.execPath + |
| 40 | + '" "' + |
| 41 | + path.join('bin', 'mocha') + |
| 42 | + '" -R json --require test/compiler-fixtures/ts.fixture "test/compiler-cjs/*.ts"', |
| 43 | + {cwd: path.join(__dirname, '..', '..')}, |
| 44 | + function (error, stdout) { |
| 45 | + if (error && !stdout) { |
| 46 | + return done(error); |
| 47 | + } |
| 48 | + var results = JSON.parse(stdout); |
| 49 | + expect(results, 'to have property', 'tests'); |
| 50 | + var titles = []; |
| 51 | + for (var index = 0; index < results.tests.length; index += 1) { |
| 52 | + expect(results.tests[index], 'to have property', 'fullTitle'); |
| 53 | + titles.push(results.tests[index].fullTitle); |
| 54 | + } |
| 55 | + expect( |
| 56 | + titles, |
| 57 | + 'to contain', |
| 58 | + 'cts written in esm should work', |
| 59 | + ).and('to have length', 1); |
| 60 | + done(); |
| 61 | + } |
| 62 | + ); |
| 63 | + }); |
| 64 | +}); |
0 commit comments