Skip to content

Commit

Permalink
test(nodejs): enhance test infrastructure to also test in nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjes committed Nov 14, 2017
1 parent 3e6ce19 commit 03beba5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ before_script:
- "./node_modules/.bin/add-cors-to-couchdb"
- "npm run jshint"

script: npm test
script: npm run $COMMAND

env:
global:
- NPM_CONFIG_PROGRESS="false"

matrix:
- CLIENT=node COMMAND=test
- CLIENT=phantom COMMAND=test

branches:
only:
Expand Down
35 changes: 35 additions & 0 deletions bin/run-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node
'use strict';

var childProcess = require('child_process');

var binDir = 'node_modules/.bin/';

var client = process.env.CLIENT || 'phantom';

if (client === 'node') {
npmRun('mocha', ['--ui', 'bdd', 'test/test.js']);
} else if (client === 'phantom') {
npm(['install', '--no-save', 'phantomjs-prebuilt']);
npmRun('zuul', ['--phantom', '--ui', 'mocha-bdd', 'test/test.js']);
} else if (client === 'local') {
npmRun('zuul', ['--local', '9000', '--no-coverage', '--ui', 'mocha-bdd', 'test/test.js']);
}

function npm(args) {
childProcess.spawnSync('npm', args, {
env: process.env,
stdio: 'inherit'
});
}

function npmRun(bin, args) {
var testProcess = childProcess.spawn(binDir + bin, args, {
env: process.env,
stdio: 'inherit'
});

testProcess.on('close', function (code) {
process.exit(code);
});
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
"build-js": "mkdirp dist && browserify . -p bundle-collapser/plugin -s PouchAuthentication > dist/pouchdb.authentication.js",
"min": "uglifyjs dist/pouchdb.authentication.js -mc > dist/pouchdb.authentication.min.js",
"build": "npm run build-js && npm run min",
"dev": "zuul --local 9000 --no-coverage --ui mocha-bdd test/test.js",
"test": "zuul --phantom --ui mocha-bdd test/test.js"
"dev": "npm run test-local",
"test": "node bin/run-test.js",
"test-local": "CLIENT=local npm run test",
"test-node": "CLIENT=node npm run test",
"test-phantom": "CLIENT=phantom npm run test"
},
"keywords": [
"pouch",
Expand Down Expand Up @@ -45,7 +48,6 @@
"jshint": "2.9.5",
"mkdirp": "^0.5.1",
"mocha": "^4.0.1",
"phantomjs-prebuilt": "2.1.16",
"pouchdb-memory": "^6.0.0",
"uglify-js": "^3.1.9",
"zuul": "^3.10.1"
Expand Down

0 comments on commit 03beba5

Please sign in to comment.