-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --type-check option to enable type checking in ts-node (#67)
- Loading branch information
1 parent
c0e3dce
commit c0048c2
Showing
9 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as expect from 'expect'; | ||
import app from './app'; | ||
|
||
describe('Running TypeScript tests in ts-node runtime with type checks', () => { | ||
describe('typecheck app module', () => { | ||
it('should return the same value that was passed', () => { | ||
expect(app(3)).toBe(3); | ||
}); | ||
}); | ||
}); | ||
|
||
// Introduce a compile error. | ||
"not a number" as number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function(x: number): number { | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
process.env.TS_NODE_PROJECT = './test/paths/tsconfig.json'; | ||
process.env.TS_TYPE_CHECK = true; | ||
require('../..'); | ||
const Mocha = require('mocha'); | ||
const path = require('path'); | ||
const { TSError } = require('ts-node'); | ||
|
||
const mocha = new Mocha(); | ||
mocha.addFile(path.resolve(__dirname, `app.spec.ts`)); | ||
|
||
try { | ||
mocha.run(() => { | ||
process.on('exit', () => { | ||
process.exit(1); // exit with non-zero status if the tests were run at all | ||
}); | ||
}); | ||
} catch (error) { | ||
if (error instanceof TSError) { | ||
// Success, we found the compile error | ||
} else { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": "." | ||
} | ||
} |