mirror of
https://github.com/flynx/test.js.git
synced 2025-10-28 10:20:09 +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
|
||||
|
||||
```shell_session
|
||||
$ npm install -g ig-test
|
||||
$ npm install -i ig-test
|
||||
```
|
||||
|
||||
And to install the global CLI interface
|
||||
```shell_session
|
||||
$ npm install -i ig-test
|
||||
$ npm install -g ig-test
|
||||
```
|
||||
|
||||
|
||||
## Basic usage
|
||||
|
||||
XXX script naming...
|
||||
|
||||
Create a test script
|
||||
```shell_session
|
||||
$ touch 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:
|
||||
```javascript
|
||||
#!/usr/bin/env node
|
||||
@ -178,14 +180,59 @@ $ runtests
|
||||
$ npm install -g ig-test
|
||||
```
|
||||
|
||||
XXX help
|
||||
Basic help
|
||||
```shell_session
|
||||
$ 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.
|
||||
```
|
||||
|
||||
|
||||
XXX list available test components
|
||||
List available test components
|
||||
```shell_session
|
||||
$ runtests --list
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-test",
|
||||
"version": "1.4.2",
|
||||
"version": "1.4.3",
|
||||
"description": "experimental test runner....",
|
||||
"main": "test.js",
|
||||
"bin": {
|
||||
|
||||
62
test.js
62
test.js
@ -8,6 +8,7 @@
|
||||
*
|
||||
*
|
||||
* TODO:
|
||||
* - list found files...
|
||||
* - flexible test chains with 0 or more modifiers...
|
||||
* - might be a good idea to detect test module type and run only our
|
||||
* ones...
|
||||
@ -550,6 +551,7 @@ argv.Parser({
|
||||
// NOTE: this uses .helpColumnOffset to align origins...
|
||||
default_files: undefined,
|
||||
|
||||
// XXX if we do the printing in .stop(..) this will see all the modules...
|
||||
'-l': '-list',
|
||||
'-list': {
|
||||
doc: ['list available tests;',
|
||||
@ -564,6 +566,10 @@ argv.Parser({
|
||||
&& (path != this.default_files
|
||||
|| this.test_modules == null)
|
||||
&& this.handle('-f', [], key, path)
|
||||
|
||||
// load the queued modules...
|
||||
this.loadModule()
|
||||
|
||||
var offset = (this.helpColumnOffset || 3) * 8
|
||||
// get key value...
|
||||
var keys = function(s){
|
||||
@ -621,8 +627,52 @@ argv.Parser({
|
||||
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,
|
||||
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...
|
||||
'-f': '-test-file',
|
||||
@ -635,7 +685,6 @@ argv.Parser({
|
||||
return this.default_files },
|
||||
handler: function(args, key, path){
|
||||
var that = this
|
||||
this.test_modules = this.test_modules || {}
|
||||
|
||||
;(path instanceof Array ?
|
||||
path
|
||||
@ -654,10 +703,8 @@ argv.Parser({
|
||||
if(!/.*\.js$/.test(path)){
|
||||
throw argv.ParserError(
|
||||
`${key}: only support .js modules, got: "${path}"`) }
|
||||
console.log('Loading module:', path)
|
||||
// XXX should we handle the load error here???
|
||||
that.test_modules[path] =
|
||||
require(process.cwd() +'/'+ path.slice(0, -3)) }) }) }},
|
||||
//that.loadModule(path) }) }) }},
|
||||
that.queueModule(path) }) }) }},
|
||||
|
||||
|
||||
// ignore paths...
|
||||
@ -688,6 +735,9 @@ argv.Parser({
|
||||
// XXX might be a good idea to check chain syntax here...
|
||||
'@*': undefined,
|
||||
})
|
||||
// load the modules...
|
||||
.then(function(){
|
||||
this.loadModule() })
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user