mirror of
https://github.com/flynx/test.js.git
synced 2025-10-28 18:30:08 +00:00
adde --list-found + mode docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ed00ce4bab
commit
090ba740be
61
README.md
61
README.md
@ -107,24 +107,26 @@ This is the traditional self-contained test approach.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```shell_session
|
```shell_session
|
||||||
$ npm install -g ig-test
|
$ npm install -i ig-test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
And to install the global CLI interface
|
||||||
```shell_session
|
```shell_session
|
||||||
$ npm install -i ig-test
|
$ npm install -g ig-test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
XXX script naming...
|
|
||||||
|
|
||||||
Create a test script
|
Create a test script
|
||||||
```shell_session
|
```shell_session
|
||||||
$ touch test.js
|
$ touch test.js
|
||||||
$ chmod +x test.js
|
$ chmod +x test.js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that the test script should be named either `"test.js"` or `"<something>-test.js"`
|
||||||
|
for the system to find it automatically.
|
||||||
|
|
||||||
The code:
|
The code:
|
||||||
```javascript
|
```javascript
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
@ -178,14 +180,59 @@ $ runtests
|
|||||||
$ npm install -g ig-test
|
$ npm install -g ig-test
|
||||||
```
|
```
|
||||||
|
|
||||||
XXX help
|
Basic help
|
||||||
```shell_session
|
```shell_session
|
||||||
$ runtests --help
|
$ runtests --help
|
||||||
|
Usage: test.js [OPTIONS] [CHAIN] ...
|
||||||
|
|
||||||
|
Run tests.
|
||||||
|
|
||||||
|
Tests run by test.js can be specified in one of the
|
||||||
|
following formats:
|
||||||
|
|
||||||
|
<case>
|
||||||
|
<setup>:<test>
|
||||||
|
<setup>:<modifier>:<test>
|
||||||
|
|
||||||
|
Each of the items in the test spec can be a "*" indicating
|
||||||
|
that all relevant items should be used, for example:
|
||||||
|
|
||||||
|
$ ./test.js basic:*:*
|
||||||
|
|
||||||
|
Here test.js is instructed to run all tests and modifiers
|
||||||
|
only on the basic setup.
|
||||||
|
|
||||||
|
Zero or more sets of tests can be specified.
|
||||||
|
|
||||||
|
When no tests specified test.js will run all tests.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help - print this message and exit
|
||||||
|
-v, --version - show test.js verion and exit
|
||||||
|
-l, --list=PATH - list available tests;
|
||||||
|
note that if passing files via -f explicitly they
|
||||||
|
must precede the -l/-list flag;
|
||||||
|
this has the same defaults as -f
|
||||||
|
--list-found=PATH - like -list but print found test modules and exit
|
||||||
|
-f, --test-file=PATH - test script or filename pattern, supports glob;
|
||||||
|
this flag can be given multiple times for
|
||||||
|
multiple paths/patterns
|
||||||
|
(default: **/?(*-)test.js)
|
||||||
|
-i, --ignore=PATH - path/pattern to ignore in test file search
|
||||||
|
(default: node_modules/**)
|
||||||
|
--verbose - verbose mode
|
||||||
|
(env: $VERBOSE)
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
$ ./test.js - run all tests.
|
||||||
|
$ ./test.js basic:*:* - run all tests and modifiers on "basic" setup.
|
||||||
|
(see test.js -l for more info)
|
||||||
|
$ ./test.js -v example - run "example" test in verbose mode.
|
||||||
|
$ ./test.js native:gen3:methods init:gen3:methods
|
||||||
|
- run two tests/patterns.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
List available test components
|
||||||
XXX list available test components
|
|
||||||
```shell_session
|
```shell_session
|
||||||
$ runtests --list
|
$ runtests --list
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-test",
|
"name": "ig-test",
|
||||||
"version": "1.4.2",
|
"version": "1.4.3",
|
||||||
"description": "experimental test runner....",
|
"description": "experimental test runner....",
|
||||||
"main": "test.js",
|
"main": "test.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
62
test.js
62
test.js
@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
|
* - list found files...
|
||||||
* - flexible test chains with 0 or more modifiers...
|
* - flexible test chains with 0 or more modifiers...
|
||||||
* - might be a good idea to detect test module type and run only our
|
* - might be a good idea to detect test module type and run only our
|
||||||
* ones...
|
* ones...
|
||||||
@ -550,6 +551,7 @@ argv.Parser({
|
|||||||
// NOTE: this uses .helpColumnOffset to align origins...
|
// NOTE: this uses .helpColumnOffset to align origins...
|
||||||
default_files: undefined,
|
default_files: undefined,
|
||||||
|
|
||||||
|
// XXX if we do the printing in .stop(..) this will see all the modules...
|
||||||
'-l': '-list',
|
'-l': '-list',
|
||||||
'-list': {
|
'-list': {
|
||||||
doc: ['list available tests;',
|
doc: ['list available tests;',
|
||||||
@ -564,6 +566,10 @@ argv.Parser({
|
|||||||
&& (path != this.default_files
|
&& (path != this.default_files
|
||||||
|| this.test_modules == null)
|
|| this.test_modules == null)
|
||||||
&& this.handle('-f', [], key, path)
|
&& this.handle('-f', [], key, path)
|
||||||
|
|
||||||
|
// load the queued modules...
|
||||||
|
this.loadModule()
|
||||||
|
|
||||||
var offset = (this.helpColumnOffset || 3) * 8
|
var offset = (this.helpColumnOffset || 3) * 8
|
||||||
// get key value...
|
// get key value...
|
||||||
var keys = function(s){
|
var keys = function(s){
|
||||||
@ -621,8 +627,52 @@ argv.Parser({
|
|||||||
process.exit() }},
|
process.exit() }},
|
||||||
|
|
||||||
|
|
||||||
// add files/patterns...
|
// list found modules...
|
||||||
|
//
|
||||||
|
// XXX use tab size...
|
||||||
|
'-list-found': {
|
||||||
|
doc: 'like -list but print found test modules and exit',
|
||||||
|
arg: 'PATH',
|
||||||
|
handler: function(args, key, path){
|
||||||
|
path = path || this.default_files
|
||||||
|
// load path or the defaults if nothing loaded...
|
||||||
|
path
|
||||||
|
&& (path != this.default_files
|
||||||
|
|| this.test_modules == null)
|
||||||
|
&& this.handle('-f', [], key, path)
|
||||||
|
var modules = Object.keys(this.test_modules || {})
|
||||||
|
console.log([
|
||||||
|
`Found modules (${ modules.length+'' }):`,
|
||||||
|
...modules
|
||||||
|
// XXX use tab size...
|
||||||
|
].join('\n '))
|
||||||
|
process.exit() }},
|
||||||
|
|
||||||
|
|
||||||
|
// queue files/patterns...
|
||||||
|
// XXX should this energetically load modules (current) or queue
|
||||||
|
// them for later loading (on .then(..))...
|
||||||
|
// ...should this be an option???
|
||||||
test_modules: undefined,
|
test_modules: undefined,
|
||||||
|
queueModule: function(path){
|
||||||
|
;(this.test_modules = this.test_modules || {})[path] = undefined
|
||||||
|
return this },
|
||||||
|
loadModule: function(path){
|
||||||
|
var that = this
|
||||||
|
path = path || Object.keys(this.test_modules || {})
|
||||||
|
path = path instanceof Array ?
|
||||||
|
path
|
||||||
|
: [path]
|
||||||
|
path
|
||||||
|
// do not reload modules...
|
||||||
|
.filter(function(path){
|
||||||
|
return !(that.test_modules || {})[path] })
|
||||||
|
.forEach(function(path){
|
||||||
|
console.log('Loading module:', path)
|
||||||
|
// XXX should we handle the load error here???
|
||||||
|
;(that.test_modules = that.test_modules || {})[path] =
|
||||||
|
require(process.cwd() +'/'+ path.slice(0, -3)) })
|
||||||
|
return this },
|
||||||
|
|
||||||
// XXX revise error handling...
|
// XXX revise error handling...
|
||||||
'-f': '-test-file',
|
'-f': '-test-file',
|
||||||
@ -635,7 +685,6 @@ argv.Parser({
|
|||||||
return this.default_files },
|
return this.default_files },
|
||||||
handler: function(args, key, path){
|
handler: function(args, key, path){
|
||||||
var that = this
|
var that = this
|
||||||
this.test_modules = this.test_modules || {}
|
|
||||||
|
|
||||||
;(path instanceof Array ?
|
;(path instanceof Array ?
|
||||||
path
|
path
|
||||||
@ -654,10 +703,8 @@ argv.Parser({
|
|||||||
if(!/.*\.js$/.test(path)){
|
if(!/.*\.js$/.test(path)){
|
||||||
throw argv.ParserError(
|
throw argv.ParserError(
|
||||||
`${key}: only support .js modules, got: "${path}"`) }
|
`${key}: only support .js modules, got: "${path}"`) }
|
||||||
console.log('Loading module:', path)
|
//that.loadModule(path) }) }) }},
|
||||||
// XXX should we handle the load error here???
|
that.queueModule(path) }) }) }},
|
||||||
that.test_modules[path] =
|
|
||||||
require(process.cwd() +'/'+ path.slice(0, -3)) }) }) }},
|
|
||||||
|
|
||||||
|
|
||||||
// ignore paths...
|
// ignore paths...
|
||||||
@ -688,6 +735,9 @@ argv.Parser({
|
|||||||
// XXX might be a good idea to check chain syntax here...
|
// XXX might be a good idea to check chain syntax here...
|
||||||
'@*': undefined,
|
'@*': undefined,
|
||||||
})
|
})
|
||||||
|
// load the modules...
|
||||||
|
.then(function(){
|
||||||
|
this.loadModule() })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user