Skip to content

Instantly share code, notes, and snippets.

@atrunelle
Last active March 31, 2019 11:29
Show Gist options
  • Save atrunelle/a4ad3dbe0161f1abb81cb8566235fbd9 to your computer and use it in GitHub Desktop.
Save atrunelle/a4ad3dbe0161f1abb81cb8566235fbd9 to your computer and use it in GitHub Desktop.
const Nightwatch = require('nightwatch');
const browserstack = require('browserstack-local');
const spawn = require('cross-spawn');
const browserstackConfig = require('./browserstack.config');
if (process.env.RUNNER === browserstackConfig.RUNNER) {
let bs_local;
try {
process.mainModule.filename = './node_modules/.bin/nightwatch';
// Code to start browserstack local before start of test
console.log('Connecting local');
Nightwatch.bs_local = bs_local = new browserstack.Local();
bs_local.start({ key: browserstackConfig.KEY, forceLocal: 'true' }, (error) => {
if (error) throw error;
console.log('Connected. Now testing...');
Nightwatch.cli((argv) => {
argv.config = 'nightwatch.config.js';
Nightwatch.CliRunner(argv)
.setup(null, () => {
// Code to stop browserstack local after end of parallel test
bs_local.stop(() => {});
})
.runTests(() => {
// Code to stop browserstack local after end of single test
bs_local.stop(() => {});
});
});
});
} catch (ex) {
console.log('There was an error while starting the test runner:\n\n');
process.stderr.write(`${ex.stack}\n`);
process.exit(2);
}
} else {
const options = process.argv.slice(2);
options.unshift('test:e2e');
spawn('./node_modules/.bin/vue-cli-service', options, { stdio: 'inherit' });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment