cleanup of e2e script

This commit is contained in:
Wyatt Johnson
2018-02-27 20:59:40 -07:00
parent 8305223639
commit 435afff2df
2 changed files with 80 additions and 54 deletions
+2 -2
View File
@@ -21,9 +21,9 @@ fi
if [[ -n "$BROWSERSTACK_KEY" ]]; then
echo Testing on browserstack
yarn e2e --reports-folder "$REPORTS_FOLDER" --bs-key "$BROWSERSTACK_KEY" --retries "$E2E_MAX_RETRIES" --timeout "$E2E_WAIT_FOR_TIMEOUT" --browsers "$E2E_BROWSERS"
node scripts/e2e.js --reports-folder "$REPORTS_FOLDER" --retries "$E2E_MAX_RETRIES" --timeout "$E2E_WAIT_FOR_TIMEOUT" --browsers "$E2E_BROWSERS" --browserstack
else
# When browserstack is not available test locally using chrome headless.
echo Testing locally
yarn e2e --reports-folder "$REPORTS_FOLDER" --retries "$E2E_MAX_RETRIES" --headless
node scripts/e2e.js --reports-folder "$REPORTS_FOLDER" --retries "$E2E_MAX_RETRIES" --timeout "$E2E_WAIT_FOR_TIMEOUT" --browsers "$E2E_BROWSERS" --headless
fi
+78 -52
View File
@@ -139,61 +139,81 @@ async function runBrowserTests(
return Object.keys(succeeded).length === browsers.length;
}
async function start(program) {
const localIdentifier = uuid();
let browsers = program.browsers.split(',');
const retries = Number.parseInt(program.retries);
const browserstack = {};
const date = new Date()
.toISOString()
.replace(/[T.]/g, '-')
.replace(/:/g, '');
const timeout = program.timeout;
const reportsFolder = `${program.reportsFolder}/${date}`;
let exitCode = 0;
let config = 'nightwatch.conf.js';
try {
if (program.tunnel && program.bsKey) {
await startTunnel(program.bsKey, localIdentifier);
class E2E {
constructor(opts) {
this.browserstackEnabled = Boolean(opts.bsKey && opts.browserstack);
if (this.browserstackEnabled && opts.headless) {
console.error('--browserstack and --headless cannot be combined');
process.exit(1);
}
console.log('Dropping test database');
await mongoose.connection.dropDatabase();
await serve();
if (program.bsKey) {
config = 'nightwatch-browserstack.conf.js';
browserstack.localIdentifier = localIdentifier;
browserstack.key = program.bsKey;
browserstack.user = program.bsUser;
} else {
// Install selenium standalone.
await seleniumInstall();
if (program.headless) {
browsers = browsers.map(b => `${b}-headless`);
this.localIdentifier = uuid();
this.retries = Number.parseInt(opts.retries);
this.browserstack = {};
this.date = new Date()
.toISOString()
.replace(/[T.]/g, '-')
.replace(/:/g, '');
this.browsers = opts.browsers.split(',').map(browser => {
if (opts.headless) {
return `${browser}-headless`;
}
}
const succeeded = await runBrowserTests(
browsers,
config,
retries,
reportsFolder,
browserstack,
timeout
);
if (!succeeded) {
exitCode = 1;
}
} catch (ex) {
console.log('There was an error:\n\n');
process.stderr.write(`${ex.stack}\n`);
process.exit(2);
} finally {
console.log('Shutting down');
shutdown();
return browser;
});
this.timeout = opts.timeout;
this.reportsFolder = `${opts.reportsFolder}/${this.date}`;
this.config = this.browserstackEnabled
? 'nightwatch-browserstack.conf.js'
: 'nightwatch.conf.js';
this.tunnel = opts.tunnel;
this.bsKey = opts.bsKey;
this.bsUser = opts.bsUser;
}
async start() {
let exitCode = 0;
try {
if (this.tunnel && this.bsKey) {
await startTunnel(this.bsKey, this.localIdentifier);
}
console.log('Dropping test database');
await mongoose.connection.dropDatabase();
console.log('Starting the server');
await serve();
if (this.browserstackEnabled) {
browserstack.localIdentifier = this.localIdentifier;
browserstack.key = this.bsKey;
browserstack.user = this.bsUser;
} else {
// Install selenium standalone.
await seleniumInstall();
}
// Run the tests.
const succeeded = await runBrowserTests(
this.browsers,
this.config,
this.retries,
this.reportsFolder,
browserstack,
this.timeout
);
if (!succeeded) {
exitCode = 1;
}
} catch (err) {
console.log('There was an error:\n\n');
process.stderr.write(`${err.stack}\n`);
process.exit(2);
} finally {
console.log('Shutting down');
shutdown();
process.exit(exitCode);
}
}
process.exit(exitCode);
}
program
@@ -202,7 +222,12 @@ program
'Perform e2e testing locally or if browserstack credentials are provided on browserstack.'
)
.option('-u, --bs-user [user]', 'Browserstack user', 'coralproject2')
.option('-k, --bs-key [key]', 'Browserstack api key')
.option(
'-k, --bs-key [key]',
'Browserstack api key',
process.env.BROWSERSTACK_KEY
)
.option('--browserstack', 'Enables Browserstack testing')
.option('--no-tunnel', 'Dont start browserstack-local')
.option('-b, --browsers [list of browsers]', 'Browsers to test', 'chrome')
.option('-r, --retries [number]', 'Number of retries before failing', '1')
@@ -211,4 +236,5 @@ program
.option('--timeout [number]', 'Timeout for WaitForConditions', '10000')
.parse(process.argv);
start(program);
const e2e = new E2E(program);
e2e.start();