Because we can.
Tell everyone about your TypeScript Test Driven Project!
See sample of usage: in micro-bench project.
-
Install ts-x-unit with npm
$ npm install ts-x-unit --save-dev
-
Add next tasks to npm scripts: 3.1. Task for build suite cases launch map from your test-classes:
"suite-builder": "suite-builder",
3.2. Update LaunchMap and compile all tests before run tests:
"pretest": "suite-builder tests/ && tsc",
3.3. Run tests in suite:
"test": "node tests/suite.js"
Now, you can use one simple command npm test
for rebuild and run you tests!
Your test-classes must:
- extend one of next base classes:
- AbstractUnitTestCase
- AbstractDomTestCase
- end with "Test.ts", for example
FooBarTest.ts
- test methods must be starting with "test" prefix, for example
public testCalculateValue(){}
See more info in project wiki on github.
Base test class has basic assertions and can be useful for unit-testing environment independent (or Node.js code). You can use mockBuilder for prepare Fake objects, based on abstract or normal TypeScript classes and JavaScript Objects. This Builder based on JSMockito.
AbstractDomTestCase extend AbstractUnitTestCase and designed for test client-side code.
It contain assertions for DOM inspection, like assertElementHasClass(), assertElementExists(), assertElementsCount() etc.
For create virtual Document use DocumentBuilder: it can prepare document with HTML-fixture from local file or url.
Also you can create Window with WindowBuilder and Location object with LocationBuilder, dispatch Events and make most manipulation with DOM in tests runned from CLI, without real browser.
This implementation based on jsdom.
After your complete all installation steps, npm task test
in your package.json run file tests/suite.js.
Pretest task call LaunchBuilder: it collect all *Test.ts files, generate map of test cases and compile all test code from TS to JS.
Clone this repo:
$ git clone [email protected]:FreeElephants/TSxUnit.git
Install dependencies:
$ npm install
To run tests use:
$ npm test
This script (re-)build launch-builder tool, update LaunchMap, compile and run tests, compute coverage. See package.json for details.
Install istanbul
and remap-istanbul
:
npm install istanbul remap-istanbul --save-dev
Add task as npm script:
"scripts": {
...
"istanbul": "istanbul",
"remap-istanbul": "remap-istanbul",
"coverage": "npm run pretest && rm -rf coverage/* && istanbul cover tests/suite.js && remap-istanbul --input coverage/coverage.json --output coverage/html-report --type html && remap-istanbul --input coverage/coverage.json --output coverage/coverage-final.json"
...
Configure you tests transpiling with sourceMap:
# update package.json
"scripts": {
...
"pretest": "suite-builder tests/ && tsc && tsc tests/suite.ts --sourceMap",
...
}
# or via tests/tsconfig.json:
{
"compilerOptions": {
...
"sourceMap": true
...
},
...
}
Now you can run tests with coverage analysis:
npm run coverage
Click on graph, and it will opens separately. You can click any rectangle to see code coverage of represented class.
See ROADMAP for planned features.