feat(e2e-tests): upload to server

This commit is contained in:
Ken Sodemann
2017-11-06 16:36:57 -06:00
parent 75b450b4f5
commit 8511ff2a76
2 changed files with 100 additions and 30 deletions

View File

@ -9,6 +9,7 @@ const webdriver = require('selenium-webdriver');
const Snapshot = require('./Snapshot');
let snapshot;
let specIndex = 0;
let takeScreenshots = false;
function startDevServer() {
@ -18,6 +19,16 @@ function startDevServer() {
return server.run(cmdArgs);
}
function generateTestId() {
let chars = 'abcdefghjkmnpqrstuvwxyz';
let id = chars.charAt(Math.floor(Math.random() * chars.length));
chars += '0123456789';
while (id.length < 3) {
id += chars.charAt(Math.floor(Math.random() * chars.length));
}
return id;
}
function getTestFiles() {
return new Promise((resolve, reject) => {
const src = path.join(__dirname, '../src/**/*.e2e-spec.js');
@ -46,13 +57,20 @@ function registerE2ETest(desc, tst) {
await tst(driver);
if (takeScreenshots) {
await snapshot.takeScreenshot(driver, {
name: this.test.fullTitle()
name: this.test.fullTitle(),
specIndex: specIndex++
});
}
return driver.quit();
});
}
function getTotalTests(suite) {
let ttl = suite.tests.length;
suite.suites.forEach(s => (ttl += getTotalTests(s)));
return ttl;
}
async function run() {
const mocha = new Mocha({
timeout: 5000,
@ -61,24 +79,41 @@ async function run() {
processCommandLine();
snapshot = new Snapshot({
platformDefaults: {
params: {
height: 800,
width: 400
}
}
});
const devServer = await startDevServer();
const files = await getTestFiles();
files.forEach(f => mocha.addFile(f));
mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures); // exit with non-zero status if there were failures
mocha.loadFiles(() => {
specIndex = 0;
snapshot = new Snapshot({
groupId: 'ionic-core',
appId: 'snapshots',
testId: generateTestId(),
domain: 'ionic-snapshot-go.appspot.com',
// domain: 'localhost:8080',
sleepBetweenSpecs: 300,
totalSpecs: getTotalTests(mocha.suite),
platformDefaults: {
browser: 'chrome',
platform: 'linux',
params: {
platform_id: 'chrome_400x800',
platform_index: 0,
platform_count: 1,
width: 400,
height: 800
}
},
accessKey: process.env.IONIC_SNAPSHOT_KEY
});
mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures); // exit with non-zero status if there were failures
});
devServer.close();
});
devServer.close();
});
}