couchdb-harness
Advanced tools
Comparing version 0.1.5 to 0.1.6
130
index.js
@@ -69,72 +69,92 @@ "use strict"; | ||
run: function (port, tests, callback) { | ||
run: function (addr, opts, callback) { | ||
// parse args | ||
if (typeof addr === 'function') { | ||
callback = addr; | ||
addr = null; | ||
} else if (typeof addr === 'object' && addr !== null) { | ||
opts = addr; | ||
addr = null; | ||
} else if (typeof addr === 'number') { | ||
addr = 'http://127.0.0.1:' + addr + '/'; | ||
} | ||
// The couchjs binary file will fail if the server.uri file doesn't | ||
// have a linebreak at the end. | ||
var addr = 'http://127.0.0.1:' + (port || 5984) + '/\n'; | ||
addr = (addr || 'http://127.0.0.1:5984/') + '\n'; | ||
if (tests && tests.length) { | ||
tests = tests.map(function (test) { | ||
if (typeof opts === 'function') { | ||
callback = opts; | ||
opts = null; | ||
} | ||
opts = opts || {}; | ||
if (Array.isArray(opts)) { | ||
opts = {tests: opts}; | ||
} | ||
if (opts.tests && opts.tests.length) { | ||
opts.tests = opts.tests.map(function (test) { | ||
return 'javascript/tests/' + test + '.js'; | ||
}); | ||
} else { | ||
tests = glob.sync('javascript/tests/*.js', { cwd: cwd }); | ||
opts.tests = glob.sync('javascript/tests/*.js', {cwd: cwd}); | ||
} | ||
callback = callback || function () {}; | ||
tests = tests.filter(function(test) { | ||
// filter tests by black list | ||
var skipping = opts.tests.filter(function (test) { | ||
return blacklist.indexOf(test) !== -1; | ||
}); | ||
opts.tests = opts.tests.filter(function(test) { | ||
return blacklist.indexOf(test) === -1; | ||
}); | ||
console.log(colors.cyan('skipping:\n') + blacklist.join('\n') + '\n'); | ||
function runTests(tests, cb, code) { | ||
if (code) { | ||
return cb(code); | ||
} | ||
if (!tests.length) { | ||
return cb(null, 0); | ||
} | ||
var test = tests.shift(); | ||
console.log(colors.green("\nStarting " + test)); | ||
var files = [ | ||
'couchdb-harness-extra.js', | ||
'javascript/json2.js', | ||
'javascript/sha1.js', | ||
'javascript/oauth.js', | ||
'javascript/couch.js', | ||
'javascript/replicator_db_inc.js', | ||
'javascript/couch_test_runner.js', | ||
'javascript/couch_http.js', | ||
'javascript/test_setup.js', | ||
test, | ||
'javascript/cli_runner.js' | ||
].map(function (fp) { | ||
return path.resolve(cwd, fp); | ||
}); | ||
var cmd = spawn(couchjs, ['-H', '-u', uri].concat(files)); | ||
cmd.stdout.on('data', function (data) { | ||
process.stdout.write(colors.grey(data)); | ||
}); | ||
cmd.stderr.on('data', function (data) { | ||
process.stdout.write(data); | ||
}); | ||
cmd.on('exit', function (code) { | ||
runTests(tests, cb, code); | ||
}); | ||
if (skipping.length) { | ||
console.log(colors.cyan('skipping:\n') + skipping.join('\n')); | ||
} | ||
fs.writeFile(uri, addr, { encoding: 'utf8' }, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
runTests(tests, callback); | ||
fs.writeFile(uri, addr, {encoding: 'utf8'}, function (err) { | ||
runTests(opts, callback); | ||
}); | ||
} | ||
}; | ||
function runTests(opts, cb, code) { | ||
if (!opts.tests.length || (opts.bail && code)) { | ||
return cb(code); | ||
} | ||
var test = opts.tests.shift(); | ||
runTest(test, function (newCode) { | ||
runTests(opts, cb, code || newCode); | ||
}); | ||
} | ||
}; | ||
function runTest(test, cb) { | ||
console.log('\n' + test + ': ' + colors.cyan('starting')); | ||
var files = [ | ||
'couchdb-harness-extra.js', | ||
'javascript/json2.js', | ||
'javascript/sha1.js', | ||
'javascript/oauth.js', | ||
'javascript/couch.js', | ||
'javascript/replicator_db_inc.js', | ||
'javascript/couch_test_runner.js', | ||
'javascript/couch_http.js', | ||
'javascript/test_setup.js', | ||
test, | ||
'javascript/cli_runner.js' | ||
].map(function (fp) { | ||
return path.resolve(cwd, fp); | ||
}); | ||
var cmd = spawn(couchjs, ['-H', '-u', uri].concat(files)); | ||
cmd.stdout.on('data', function (data) { | ||
process.stdout.write(colors.grey(data)); | ||
}); | ||
cmd.stderr.on('data', function (data) { | ||
process.stdout.write(data); | ||
}); | ||
cmd.on('exit', function (code) { | ||
var message = code ? colors.red('fail') : colors.green('pass'); | ||
console.log(test + ': ' + message); | ||
return cb(code); | ||
}); | ||
} |
{ | ||
"name": "couchdb-harness", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "A generalized port of the CouchDB JavaScript test harness.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -22,11 +22,20 @@ # CouchDB Harness | ||
But the binary also accepts arguments to specify the port that the harness | ||
should run against, as well as which files to test, | ||
should run against, as well as which files to test: | ||
``` | ||
```bash | ||
./bin/couchdb-harness -p 5984 basics all_docs | ||
``` | ||
#### Available options | ||
- ``-b``: bail (a flag) | ||
- ``-a``: address | ||
- ``-p``: port | ||
All options are further described below. | ||
### Node.js | ||
``` | ||
#### Examples | ||
```javascript | ||
var harness = require('couchdb-harness'); | ||
@@ -38,2 +47,30 @@ harness.run(5984, ['basics', 'all_docs'], function (exitCode) { | ||
```javascript | ||
var harness = require('couchdb-harness'); | ||
harness.run('http://192.168.1.31:5985/', {bail: true}, function (code) { | ||
process.exit(code); | ||
}) | ||
``` | ||
#### API | ||
``harness.run([addr[, opts[, callback]]])`` | ||
- ``addr``: The address of the server with a CouchDB-style API to test. | ||
Defaults to ``"http://127.0.0.1:5984/"``. If the server you want to | ||
test runs on localhost and you just want to change the port, you can | ||
also just pass in the port number instead. | ||
- ``opts``: Either an array of tests as demonstrated in the first | ||
example, or a JavaScript object with the following (optional) | ||
properties: | ||
- ``tests``: The aforementioned array of tests. Defaults to all the | ||
test files. | ||
- ``bail``: When ``true``, couchdb-harness will stop running on the | ||
first failure it encounters. This does not have any influence on the | ||
``exitCode``. One failure is still enough to make it non-zero. | ||
Defaults to ``false``. | ||
- ``callback``: Called when done running the tests. Gets one argument: | ||
the exit code. It's zero when the tests all passed, otherwise | ||
non-zero. | ||
## License | ||
@@ -40,0 +77,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
754391
16234
89
107