Skip to content

Commit

Permalink
Normalize paths when looking up items on outputCache (#1038)
Browse files Browse the repository at this point in the history
* Normalize paths when looking up items on outputCache

* Tweak tests to be absolutely sure sourcemaps are working
  • Loading branch information
cspotcode authored May 13, 2020
1 parent 2397f3a commit 907935c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('ts-node', function () {
}

expect(err.message).to.contain([
`${join(__dirname, '../tests/throw.ts')}:3`,
`${join(__dirname, '../tests/throw.ts')}:100`,
' bar () { throw new Error(\'this is a demo\') }',
' ^',
'Error: this is a demo'
Expand All @@ -206,7 +206,7 @@ describe('ts-node', function () {
}

expect(err.message).to.contain([
`${join(__dirname, '../tests/throw.ts')}:3`,
`${join(__dirname, '../tests/throw.ts')}:100`,
' bar () { throw new Error(\'this is a demo\') }',
' ^'
].join('\n'))
Expand Down Expand Up @@ -611,7 +611,7 @@ describe('ts-node', function () {
} catch (error) {
expect(error.stack).to.contain([
'Error: this is a demo',
` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:3:18)`
` at Foo.bar (${join(__dirname, '../tests/throw.ts')}:100:18)`
].join('\n'))

done()
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export function create (rawOptions: CreateOptions = {}): Register {
sourceMapSupport.install({
environment: 'node',
retrieveFile (path: string) {
return outputCache.get(path)?.content || ''
return outputCache.get(normalizeSlashes(path))?.content || ''
}
})

Expand Down
97 changes: 97 additions & 0 deletions tests/throw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,101 @@
// intentional whitespace to prove that sourcemaps are working. Throw should happen on line 100.
// 100 lines is meant to be far more space than the helper functions would take.
class Foo {































































































constructor () { this.bar() }
bar () { throw new Error('this is a demo') }
}
Expand Down

0 comments on commit 907935c

Please sign in to comment.