From 366ac0b2aa466216b261b5bb6e7fc1913258b914 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Sun, 22 Mar 2020 14:17:18 -0700 Subject: [PATCH] Add test covering `--files` flag (#987) --- src/index.spec.ts | 34 +++++++++++++++++++++++++++++----- tests/issue-986/index.ts | 1 + tests/issue-986/tsconfig.json | 5 +++++ tests/issue-986/types.ts | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 tests/issue-986/index.ts create mode 100644 tests/issue-986/tsconfig.json create mode 100644 tests/issue-986/types.ts diff --git a/src/index.spec.ts b/src/index.spec.ts index cfb7f4ffe..725bb8b1d 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -340,12 +340,36 @@ describe('ts-node', function () { }) }) - it('issue #884', function (done) { - exec(`node "${BIN_PATH}" --project tests/issue-884/tsconfig.json tests/issue-884`, function (err, stdout) { - expect(err).to.equal(null) - expect(stdout).to.equal('') + describe('issue #884', function () { + it('should compile', function (done) { + exec(`node "${BIN_PATH}" --project tests/issue-884/tsconfig.json tests/issue-884`, function (err, stdout) { + expect(err).to.equal(null) + expect(stdout).to.equal('') - return done() + return done() + }) + }) + }) + + describe('issue #986', function () { + it('should not compile', function (done) { + exec(`node "${BIN_PATH}" --project tests/issue-986/tsconfig.json tests/issue-986`, function (err, stdout, stderr) { + expect(err).not.to.equal(null) + expect(stderr).to.contain('Cannot find name \'TEST\'') // TypeScript error. + expect(stdout).to.equal('') + + return done() + }) + }) + + it('should compile with `--files`', function (done) { + exec(`node "${BIN_PATH}" --files --project tests/issue-986/tsconfig.json tests/issue-986`, function (err, stdout, stderr) { + expect(err).not.to.equal(null) + expect(stderr).to.contain('ReferenceError: TEST is not defined') // Runtime error. + expect(stdout).to.equal('') + + return done() + }) }) }) diff --git a/tests/issue-986/index.ts b/tests/issue-986/index.ts new file mode 100644 index 000000000..fb8e23051 --- /dev/null +++ b/tests/issue-986/index.ts @@ -0,0 +1 @@ +console.log(TEST) diff --git a/tests/issue-986/tsconfig.json b/tests/issue-986/tsconfig.json new file mode 100644 index 000000000..28900bb1b --- /dev/null +++ b/tests/issue-986/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "module": "CommonJS" + } +} diff --git a/tests/issue-986/types.ts b/tests/issue-986/types.ts new file mode 100644 index 000000000..88473dfa4 --- /dev/null +++ b/tests/issue-986/types.ts @@ -0,0 +1 @@ +declare const TEST: string