From 03beba54dbf044fb43edbf0d8066fb9c52c3d5c7 Mon Sep 17 00:00:00 2001 From: "Didier Villevalois (Ptitjes)" Date: Sun, 12 Nov 2017 17:40:00 +0100 Subject: [PATCH] test(nodejs): enhance test infrastructure to also test in nodejs --- .travis.yml | 10 +++++++++- bin/run-test.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 8 +++++--- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 bin/run-test.js diff --git a/.travis.yml b/.travis.yml index 1f0c4bd..dd6ca8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/bin/run-test.js b/bin/run-test.js new file mode 100644 index 0000000..23ee653 --- /dev/null +++ b/bin/run-test.js @@ -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); + }); +} diff --git a/package.json b/package.json index 5b3e819..15edcf7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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"