Skip to content

Commit c9c443c

Browse files
committed
Test coverage: add test case to confirm that moduleType overrides are applied for ts-node in loader mode
1 parent dcbd916 commit c9c443c

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

src/test/index.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,5 +1888,12 @@ test.suite('ts-node', (test) => {
18881888
expect(stdout).to.contain('CommonJS');
18891889
});
18901890
}
1891+
1892+
test('moduleTypes can override module type to CJS in an ESM loader project', async () => {
1893+
const { err, stderr, stdout } = await exec(
1894+
`${cmd} ./module-types/test.esm.js`
1895+
);
1896+
expect(err).to.equal(null);
1897+
});
18911898
});
18921899
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const cjs: boolean = true;
2+
3+
export const requireType = typeof require;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const cjs: boolean = true;
2+
3+
export const requireType = typeof require;

tests/module-types/test.esm.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import assert from 'assert';
2+
3+
import cjsSubdirCJS from './src/cjs-subdir';
4+
import cjsSubdirESM from './src/cjs-subdir/esm-exception';
5+
6+
assert(cjsSubdirCJS.requireType === 'function');
7+
assert(cjsSubdirESM.requireType === 'undefined');

0 commit comments

Comments
 (0)