npm install typescript -g
npm install typings -g
npm install mocha -g
npm init --force
typings install dt~node --global --save
typings install dt~mocha --global --save
- Modify
package.json
using template in this gist to define npmbuild
andtest
scripts. - Create
tsconfig.json
using template in this gist to allow runningtsc
to build all TypeScript files in the directory. - Create
.gitignore
from template in this gist to avoid storing intermediate files produced by build in Git repository. - Create
.vscode/tasks.json
using template in this gist to define VSCodebuild
andtest
tasks. - Create
.vscode/launch.json
using template in this gist - Create
src\product.ts
using template in this gist - Create
test\product.ts
using template in this gist
- VSCode:
Ctrl+Shift+B
- Shell:
tsc
ornpm run build
How it works:
npm
runs thebuild
script defined inpackage.json
to invoketsc
command from thetypescript
module.tsc
looks fortsconfig.json
in the current directory and usesoutDir
property to maketsc
generate.js
files in thebuild
subfolder,sourceMaps
to generate.js.map
along with them.
- VSCode:
Ctrl+Shift+P
thenTasks: Run Test Task
- Shell:
mocha build/test
ornpm test
node build/index.js
How it works:
tsc
compilesindex.ts
toindex.js
in thebuild
directory based on thetsconfig.json
settingsnode
runs the JavaScript inindex.js
VS Code
Ctrl+Shift+D
to open Debugger view- select
Launch
debugger configuration F5
How it works:
.vsconfig/launch.json
definesLaunch
configurationprogram
property to indicate which.ts
file contains the application entry point,sourceMaps
property to make debugger use.js.map
files,outDir
property to specify where to find them.
- Shell
mocha build/test --debug-brk
- VS Code
Ctrl+Shift+D
to open Debugger view- select
Attach
debugger configuration F5
How it works:
mocha
tells node to stop as soon as it starts executing the test runner- Node starts listening on port 5858
- VS Code
Attach
configuration supplies debugger settingsaddress
tells debugger to connect tolocalhost
where node is runningport
tells debugger to connect to5858
where node is listening