testrun
A module to support a test.
Install
Install with npm
$ npm install testrun --save-dev
Usage
1. Create test cases.
samplejsconst testrun = mocha; { // `testcase` is a property of the 3rd argument of `testrun` if typeof testcasein === 'string' return testcasein; else throw ; } ;
2. Run the test cases.
$ mocha sample.js
test case group
✓ test for in: 'aaa' => 'aaa'
✓ test for in:[ 'a', 'b', 'c' ] => TypeError
0 passing (16ms)
Supporting test frameworks
-
const testrun = mocha;
-
const testrun = ;
NOTICE: If using lab on node version 0.10 or 0.12, you have to use lab version 6.2.
APIs
testrun(testname, testfn, testcases) => void
runs the specified test function for each test cases.
Parameters:
-
testname [string] : a test name.
-
testfn [function] : a test function. (see below.)
-
testcases [array] : an array of test cases.
#### testfn (testcase [, done]) => any
is a function to execute a testcase. The argument
testcase
is each property intestcases
passed totestrun
function.##### Parameters:
- testcase [object] : a test case object.
- done [function] : a callback to end.
- If this argument is not specified,
testfn
is required to return a result or to throw an error. - If this argument is specified,
testfn
is required to evaluate a testcase in own way and execute this argument to end it.
- If this argument is not specified,
#### testcase
##### Reserved words for properties of testcase:
- expected [any] : set an expected value of a test case.
- error [Error] : set an error type which a test case throws
- cases [array] : set a test case group.
- skip [boolean] : set
true
if you want to skip a test case or a test case group. - only [boolean] : set
true
if you want to run only a test case or a test case group.
testrun.byPlatform(valuesByPlatforms) => any
returns a value for the current platform.
Parameters:
- valuesByPlatforms [plain-object | any] : values by platforms.
Example:
testrun;// => 123 (on Windows)// => 999 (on other platform) testrun;// => 'abc'
testrun.scriptrun(templateFile, testDir) => function
returns a function which executes javascript based on content of templateFile
on child process.
Parameters:
- templateFile [string] : a path string of a javascript template file for a test case.
- testDir [string] : a path string of a directory to output a javascript file for a test case.
Example:
templatejsconst assert = ;var testcase = $testcase;assert;
const testfn = testrun; ;
License
Copyright (C) 2016 Takayuki Sato
This program is free software under MIT License. See the file LICENSE in this distribution for more details.