Skip to content

Commit

Permalink
Fix format diagnostics on old TypeScript versions
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Nov 8, 2019
1 parent 234f2e7 commit 87a5b14
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
56 changes: 29 additions & 27 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,41 +370,43 @@ describe('ts-node', function () {
expect(() => require(moduleTestPath)).to.not.throw()
})

it('should support compiler scopes', function () {
const calls: string[] = []
if (semver.gte(ts.version, '2.7.0')) {
it('should support compiler scopes', function () {
const calls: string[] = []

registered.enabled(false)
registered.enabled(false)

const compilers = [
register({ cwd: join(TEST_DIR, 'scope/a'), scope: true }),
register({ cwd: join(TEST_DIR, 'scope/b'), scope: true })
]
const compilers = [
register({ cwd: join(TEST_DIR, 'scope/a'), scope: true }),
register({ cwd: join(TEST_DIR, 'scope/b'), scope: true })
]

compilers.forEach(c => {
const old = c.compile
c.compile = (code, fileName, lineOffset) => {
calls.push(fileName)
compilers.forEach(c => {
const old = c.compile
c.compile = (code, fileName, lineOffset) => {
calls.push(fileName)

return old(code, fileName, lineOffset)
}
})
return old(code, fileName, lineOffset)
}
})

try {
expect(require('../tests/scope/a').ext).to.equal('.ts')
expect(require('../tests/scope/b').ext).to.equal('.ts')
} finally {
compilers.forEach(c => c.enabled(false))
}
try {
expect(require('../tests/scope/a').ext).to.equal('.ts')
expect(require('../tests/scope/b').ext).to.equal('.ts')
} finally {
compilers.forEach(c => c.enabled(false))
}

expect(calls).to.deep.equal([
join(TEST_DIR, 'scope/a/index.ts'),
join(TEST_DIR, 'scope/b/index.ts')
])
expect(calls).to.deep.equal([
join(TEST_DIR, 'scope/a/index.ts'),
join(TEST_DIR, 'scope/b/index.ts')
])

delete require.cache[moduleTestPath]
delete require.cache[moduleTestPath]

expect(() => require(moduleTestPath)).to.throw()
})
expect(() => require(moduleTestPath)).to.throw()
})
}

it('should compile through js and ts', function () {
const m = require('../tests/complex')
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export function register (opts: Options = {}): Register {
})

const formatDiagnostics = process.stdout.isTTY || options.pretty
? ts.formatDiagnosticsWithColorAndContext
? (ts.formatDiagnosticsWithColorAndContext || ts.formatDiagnostics)
: ts.formatDiagnostics

function createTSError (diagnostics: ReadonlyArray<_ts.Diagnostic>) {
Expand Down

0 comments on commit 87a5b14

Please sign in to comment.