Skip to content

Commit e71e2bc

Browse files
committed
fix test coverage
1 parent 6734ec4 commit e71e2bc

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

src/index.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ describe('ts-node', function () {
724724
describe('esm', () => {
725725
this.slow(1000)
726726

727-
const cmd = `node --loader ts-node/esm.mjs`
727+
const cmd = `node --loader ts-node/esm`
728728

729729
if (semver.gte(process.version, '13.0.0')) {
730730
it('should compile and execute as ESM', (done) => {
@@ -735,6 +735,19 @@ describe('ts-node', function () {
735735
return done()
736736
})
737737
})
738+
it('should use source maps', function (done) {
739+
exec(`${cmd} throw.ts`, { cwd: join(__dirname, '../tests/esm') }, function (err, stdout) {
740+
expect(err).not.to.equal(null)
741+
expect(err!.message).to.contain([
742+
`${join(__dirname, '../tests/esm/throw.ts')}:100`,
743+
' bar () { throw new Error(\'this is a demo\') }',
744+
' ^',
745+
'Error: this is a demo'
746+
].join('\n'))
747+
748+
return done()
749+
})
750+
})
738751
it('supports --experimental-specifier-resolution=node', (done) => {
739752
exec(`${cmd} --experimental-specifier-resolution=node index.ts`, { cwd: join(__dirname, '../tests/esm-node-resolver') }, function (err, stdout) {
740753
expect(err).to.equal(null)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export function create (rawOptions: CreateOptions = {}): Register {
451451
// If it's a file URL, convert to local path
452452
// Note: fileURLToPath does not exist on early node v10
453453
// I could not find a way to handle non-URLs except to swallow an error
454-
if (fileURLToPath && path.startsWith('file://')) {
454+
if (options.experimentalEsmLoader && path.startsWith('file://')) {
455455
try {
456456
path = fileURLToPath(path)
457457
} catch (e) {/* swallow error */}

tests/esm/throw.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
2+
// 100 lines is meant to be far more space than the helper functions would take.
3+
class Foo {
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
constructor () { this.bar() }
100+
bar () { throw new Error('this is a demo') }
101+
}
102+
new Foo()

0 commit comments

Comments
 (0)