Skip to content

Commit 87a5b14

Browse files
committed
Fix format diagnostics on old TypeScript versions
1 parent 234f2e7 commit 87a5b14

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/index.spec.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -370,41 +370,43 @@ describe('ts-node', function () {
370370
expect(() => require(moduleTestPath)).to.not.throw()
371371
})
372372

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

376-
registered.enabled(false)
377+
registered.enabled(false)
377378

378-
const compilers = [
379-
register({ cwd: join(TEST_DIR, 'scope/a'), scope: true }),
380-
register({ cwd: join(TEST_DIR, 'scope/b'), scope: true })
381-
]
379+
const compilers = [
380+
register({ cwd: join(TEST_DIR, 'scope/a'), scope: true }),
381+
register({ cwd: join(TEST_DIR, 'scope/b'), scope: true })
382+
]
382383

383-
compilers.forEach(c => {
384-
const old = c.compile
385-
c.compile = (code, fileName, lineOffset) => {
386-
calls.push(fileName)
384+
compilers.forEach(c => {
385+
const old = c.compile
386+
c.compile = (code, fileName, lineOffset) => {
387+
calls.push(fileName)
387388

388-
return old(code, fileName, lineOffset)
389-
}
390-
})
389+
return old(code, fileName, lineOffset)
390+
}
391+
})
391392

392-
try {
393-
expect(require('../tests/scope/a').ext).to.equal('.ts')
394-
expect(require('../tests/scope/b').ext).to.equal('.ts')
395-
} finally {
396-
compilers.forEach(c => c.enabled(false))
397-
}
393+
try {
394+
expect(require('../tests/scope/a').ext).to.equal('.ts')
395+
expect(require('../tests/scope/b').ext).to.equal('.ts')
396+
} finally {
397+
compilers.forEach(c => c.enabled(false))
398+
}
398399

399-
expect(calls).to.deep.equal([
400-
join(TEST_DIR, 'scope/a/index.ts'),
401-
join(TEST_DIR, 'scope/b/index.ts')
402-
])
400+
expect(calls).to.deep.equal([
401+
join(TEST_DIR, 'scope/a/index.ts'),
402+
join(TEST_DIR, 'scope/b/index.ts')
403+
])
403404

404-
delete require.cache[moduleTestPath]
405+
delete require.cache[moduleTestPath]
405406

406-
expect(() => require(moduleTestPath)).to.throw()
407-
})
407+
expect(() => require(moduleTestPath)).to.throw()
408+
})
409+
}
408410

409411
it('should compile through js and ts', function () {
410412
const m = require('../tests/complex')

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export function register (opts: Options = {}): Register {
268268
})
269269

270270
const formatDiagnostics = process.stdout.isTTY || options.pretty
271-
? ts.formatDiagnosticsWithColorAndContext
271+
? (ts.formatDiagnosticsWithColorAndContext || ts.formatDiagnostics)
272272
: ts.formatDiagnostics
273273

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

0 commit comments

Comments
 (0)