Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support running with NodeJS #176

Merged
merged 5 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,32 @@ after_script:
# upload the updated package-lock.json
- greenkeeper-lockfile-upload

script: npm test
script: npm run $COMMAND

env:
global:
- NPM_CONFIG_PROGRESS="false"
- secure: "U7yqHtQrvzNob8YMh9iH34piyr4N0ZoX/G45VUuGlOoXe2gjhwHMAERRISZLtdzHawYu780SZ7g42HP2jsgwXqGGUmxLNMTFY44V19030Fn2QFEIZ30Ni/t0VRpvt1gwiAwRQJlVyKxS4B6qctf6HGm+hS2gQHnGuj4uX9WMZ8A="
- secure: "LjHjFT855IQ66dfXDroe5fmsBNohyO7j5M0sEHOaNvtqnVYVAfMgwW3JpESXhXY0mEgSSKSOtCEGK2iqhsGL1ou4nYP0TarV/aKBjclNotMWcBI+VdgvooCtV4D2LCmFWqJ8agxZnmkeqX+VmnMieEttZAcagXslcNARq96m9v0="
- secure: "UqQRT/Fn3cIHWXd9quN0mFD4BG8WeyxJKlghPXF+q3BZOeRyXe4FpG7RJBQohGHvJYzPY27Yi7mIlEOLCICFtC0Os/qNueK11/D+J6Zhr8rPqi/JTUJth0ybwhSBXyb6Vfm4Ce4m8hfKfLHTbo5FP533RuIUhPrThO3+APpxdCo="

matrix:
- CLIENT=node COMMAND=test
- CLIENT=phantom COMMAND=test
- CLIENT=saucelabs:Chrome COMMAND=test
- CLIENT=saucelabs:Firefox COMMAND=test
- CLIENT=saucelabs:Safari:7 COMMAND=test
- CLIENT="saucelabs:Internet Explorer:10:Windows 8" COMMAND=test
- CLIENT="saucelabs:Internet Explorer:11:Windows 10" COMMAND=test

matrix:
allow_failures:
# Waiting for pouchdb/pouchdb#6814
- env: CLIENT=node COMMAND=test
# Waiting for pouchdb/pouchdb#6855
- env: CLIENT="saucelabs:Internet Explorer:11:Windows 10" COMMAND=test

branches:
only:
- master
- /^greenkeeper/.*$/

env:
global:
- secure: "U7yqHtQrvzNob8YMh9iH34piyr4N0ZoX/G45VUuGlOoXe2gjhwHMAERRISZLtdzHawYu780SZ7g42HP2jsgwXqGGUmxLNMTFY44V19030Fn2QFEIZ30Ni/t0VRpvt1gwiAwRQJlVyKxS4B6qctf6HGm+hS2gQHnGuj4uX9WMZ8A="
108 changes: 108 additions & 0 deletions bin/run-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env node
'use strict';

var childProcess = require('child_process');
var karma = require('karma');

var binDir = 'node_modules/.bin/';

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

if (client === 'node') {
npmRun('mocha', ['--ui', 'bdd', 'test/*']);
} else {

// Karma base configuration
var options = {
basePath: '',
frameworks: ['mocha', 'chai', 'browserify'],
files: [
'test/**/*.js',
],
preprocessors: {
'test/**/*.js': ['browserify'],
},
browserify: {
debug: true,
transform: ['brfs'],
},
port: 9876,
colors: true,
reporters: ['mocha'],
concurrency: 1,
singleRun: client !== 'local',
};

if (client === 'phantom') {
options.browsers = ['PhantomJS'];
options.phantomJsLauncher = {
exitOnResourceError: true
};
} else if (client === 'local') {
options.browsers = [];
} else {
var tmp = (client || 'saucelabs:firefox').split(':');
client = {
runner: tmp[0] || 'saucelabs',
browser: tmp[1] || 'firefox',
version: tmp[2] || null, // Latest
platform: tmp[3] || null
};

if (process.env.TRAVIS &&
client.runner === 'saucelabs' &&
process.env.TRAVIS_SECURE_ENV_VARS === 'false') {
console.error('Not running test, cannot connect to saucelabs');
process.exit(0);
}

if (client.runner === 'saucelabs') {

// Standard SauceLabs configuration
options.sauceLabs = {
testName: 'pouchdb-authentication tests',
connectOptions: {
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER || 'tunnel-' + Date.now(),
},
};
options.customLaunchers = {
sl: {
base: 'SauceLabs',
browserName: client.browser,
platform: client.platform,
version: client.version,
},
};
options.browsers = ['sl'];
options.reporters.push('saucelabs');

// Longer timeouts for SauceLabs
options.captureTimeout = 2 * 60 * 1000;
options.browserNoActivityTimeout = 30 * 60 * 1000;
options.browserDisconnectTimeout = 30 * 60 * 1000;

// To account for distance between SauceLabs and CouchDB at Travis
options.client = {
mocha: {
timeout: 30 * 60 * 1000,
}
};
}
}

var server = new karma.Server(options);
server.start();
}

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

testProcess.on('close', function (code) {
process.exit(code);
});
}
Loading