diff --git a/src/index.spec.ts b/src/index.spec.ts index 7ae28a13c..8e2063942 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -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') diff --git a/src/index.ts b/src/index.ts index ff42d4a0f..234c98f66 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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>) {