mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(snapshot): update snapshot scripts
This commit is contained in:
115
scripts/gulp/tasks/snapshot.ts
Normal file
115
scripts/gulp/tasks/snapshot.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import { task } from 'gulp';
|
||||
import { DIST_E2E_COMPONENTS_ROOT, PROJECT_ROOT, SCRIPTS_ROOT } from '../constants';
|
||||
import { mergeObjects } from '../util';
|
||||
import * as path from 'path';
|
||||
|
||||
|
||||
task('snapshot', ['e2e'], (done: Function) => {
|
||||
snapshot(false, done);
|
||||
});
|
||||
|
||||
task('snapshot.skipBuild', ['e2e.sass'], (done: Function) => {
|
||||
snapshot(false, done);
|
||||
});
|
||||
|
||||
task('snapshot.quick', ['e2e.sass'], (done: Function) => {
|
||||
snapshot(true, done);
|
||||
});
|
||||
|
||||
function snapshot(quickMode: boolean, callback: Function) {
|
||||
const snapshotConfig = require('../../snapshot/snapshot.config').config;
|
||||
const protractorConfigFile = path.resolve(SCRIPTS_ROOT, 'snapshot/protractor.config.js');
|
||||
const argv = require('yargs').argv;
|
||||
|
||||
const snapshotDefaults = snapshotConfig.platformDefaults || {};
|
||||
const snapshotValues: any = mergeObjects(snapshotDefaults, argv || {});
|
||||
|
||||
if (!snapshotConfig.accessKey || !snapshotConfig.accessKey.length) {
|
||||
console.error('Missing IONIC_SNAPSHOT_KEY environment variable');
|
||||
return callback(new Error('Missing IONIC_SNAPSHOT_KEY environment variable'));
|
||||
}
|
||||
|
||||
let component = '*';
|
||||
let e2eSpecs = '*';
|
||||
const folderArg: string = argv.folder || argv.f;
|
||||
if (folderArg && folderArg.length) {
|
||||
const folderArgPaths = folderArg.split('/');
|
||||
component = folderArgPaths[0];
|
||||
if (folderArgPaths.length > 1) {
|
||||
e2eSpecs = folderArgPaths[1];
|
||||
}
|
||||
}
|
||||
const specs = path.join(DIST_E2E_COMPONENTS_ROOT, component, 'test', e2eSpecs, '*e2e.js');
|
||||
console.log(`[snapshot] Specs: ${specs}`);
|
||||
|
||||
const testId = generateTestId();
|
||||
console.log(`[snapshot] TestId: ${testId}`);
|
||||
|
||||
snapshotValues.params.test_id = testId;
|
||||
snapshotValues.params.upload = !quickMode;
|
||||
|
||||
var protractorArgs = [
|
||||
'--browser ' + snapshotValues.browser,
|
||||
'--platform ' + snapshotValues.platform,
|
||||
'--params.platform_id=' + snapshotValues.params.platform_id,
|
||||
'--params.platform_index=' + snapshotValues.params.platform_index,
|
||||
'--params.platform_count=' + snapshotValues.params.platform_count,
|
||||
'--params.width=' + snapshotValues.params.width,
|
||||
'--params.height=' + snapshotValues.params.height,
|
||||
'--params.test_id=' + snapshotValues.params.test_id,
|
||||
'--params.upload=' + snapshotValues.params.upload,
|
||||
'--specs=' + specs
|
||||
];
|
||||
|
||||
return protractor(callback, [protractorConfigFile].concat(protractorArgs), testId);
|
||||
}
|
||||
|
||||
function protractor(callback, args, testId: string) {
|
||||
const connect = require('connect');
|
||||
const http = require('http');
|
||||
const serveStatic = require('serve-static');
|
||||
const buildConfig = require('../../build/config');
|
||||
const app = connect().use(serveStatic(PROJECT_ROOT));
|
||||
const protractorHttpServer = http.createServer(app).listen(buildConfig.protractorPort);
|
||||
|
||||
console.log(`Serving ${process.cwd()} on http://localhost:${buildConfig.protractorPort}`);
|
||||
|
||||
const cp = require('child_process');
|
||||
const child = cp.spawn('protractor', args, {
|
||||
stdio: [process.stdin, process.stdout, 'pipe']
|
||||
});
|
||||
|
||||
let errored = false;
|
||||
let callbackCalled = false;
|
||||
|
||||
child.stderr.on('data', function(data) {
|
||||
protractorHttpServer.close();
|
||||
console.error(data.toString());
|
||||
if (!errored) {
|
||||
errored = true;
|
||||
if (!callbackCalled) {
|
||||
callback('Protractor tests failed.');
|
||||
callbackCalled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
child.on('exit', function() {
|
||||
protractorHttpServer.close();
|
||||
if (!callbackCalled) {
|
||||
console.log(`[snapshot] TestId: ${testId}`);
|
||||
callback();
|
||||
callbackCalled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ var IonicSnapshot = function(options) {
|
||||
self.domain = options.domain || 'ionic-snapshot-go.appspot.com';
|
||||
self.groupId = options.groupId || 'test_group';
|
||||
self.appId = options.appId || 'test_app';
|
||||
self.sleepBetweenSpecs = options.sleepBetweenSpecs || 750;
|
||||
self.sleepBetweenSpecs = options.sleepBetweenSpecs || 500;
|
||||
self.testId = browser.params.test_id || 'test_id';
|
||||
self.shouldUpload = browser.params.upload !== 'false';
|
||||
self.platformId = browser.params.platform_id;
|
||||
@@ -114,10 +114,11 @@ var IonicSnapshot = function(options) {
|
||||
var specIdString = '[' + (spec.id+1) + '/' + self.testData.total_specs + ']';
|
||||
|
||||
self.testData.spec_index = spec.id;
|
||||
self.testData.description = spec.getFullName();
|
||||
self.testData.description = spec.getFullName().replace('/test/', '/');
|
||||
self.testData.highest_mismatch = self.highestMismatch;
|
||||
self.testData.png_base64 = pngBase64;
|
||||
self.testData.url = currentUrl.replace('dist/', '/').replace('&ionicanimate=false', '');
|
||||
self.testData.description = spec.getFullName().replace('test/', '');
|
||||
self.testData.url = currentUrl.replace('dist', '').replace('components/', '').replace('test/', '').replace('&ionicanimate=false', '');
|
||||
pngBase64 = null;
|
||||
|
||||
var requestDeferred = q.defer();
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
|
||||
var buildConfig = require('../build/config');
|
||||
var path = require('canonical-path');
|
||||
var projectRoot = path.resolve(__dirname, '../..');
|
||||
var snapshotConfig = require('./snapshot.config').config;
|
||||
|
||||
exports.config = {
|
||||
|
||||
// Spec patterns are relative to the location of the spec file. They may
|
||||
// include glob patterns.
|
||||
specs: [
|
||||
path.resolve(projectRoot, snapshotConfig.specs)
|
||||
],
|
||||
|
||||
// Options to be passed to Jasmine-node.
|
||||
jasmineNodeOpts: {
|
||||
showColors: true, // Use colors in the command line report.
|
||||
|
||||
@@ -8,12 +8,9 @@ exports.config = {
|
||||
domain: 'ionic-snapshot-go.appspot.com',
|
||||
//domain: 'localhost:8080',
|
||||
|
||||
specs: 'dist/e2e/**/*e2e.js',
|
||||
// specs: 'dist/e2e/button/**/*e2e.js',
|
||||
sleepBetweenSpecs: 300,
|
||||
|
||||
sleepBetweenSpecs: 700,
|
||||
|
||||
platformDefauls: {
|
||||
platformDefaults: {
|
||||
browser: 'chrome',
|
||||
platform: 'linux',
|
||||
params: {
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
|
||||
module.exports = function(gulp, argv, buildConfig) {
|
||||
|
||||
var snapshotConfig = require('./snapshot.config').config;
|
||||
var _ = require('lodash');
|
||||
var http = require('http');
|
||||
var connect = require('connect');
|
||||
var serveStatic = require('serve-static');
|
||||
var cp = require('child_process');
|
||||
var path = require('canonical-path');
|
||||
|
||||
var projectRoot = path.resolve(__dirname, '../..');
|
||||
var protractorHttpServer;
|
||||
var snapshotValues = _.merge(snapshotConfig.platformDefauls, argv);
|
||||
|
||||
gulp.task('protractor-server', function() {
|
||||
var app = connect().use(serveStatic(projectRoot)); // serve everything that is static
|
||||
protractorHttpServer = http.createServer(app).listen(buildConfig.protractorPort);
|
||||
console.log('Serving `dist` on http://localhost:' + buildConfig.protractorPort);
|
||||
});
|
||||
|
||||
gulp.task('snapshot', ['e2e', 'protractor-server'], function(done) {
|
||||
snapshot(done);
|
||||
});
|
||||
|
||||
gulp.task('snapshot-quick', ['e2e', 'protractor-server'], function(done) {
|
||||
snapshot(done, true);
|
||||
});
|
||||
|
||||
gulp.task('e2e-publish', function(done) {
|
||||
var testId = generateTestId();
|
||||
e2ePublish(testId, true);
|
||||
});
|
||||
|
||||
function snapshot(done, quickMode) {
|
||||
|
||||
if (!snapshotConfig.accessKey || !snapshotConfig.accessKey.length) {
|
||||
console.error('Missing IONIC_SNAPSHOT_KEY environment variable');
|
||||
return done();
|
||||
}
|
||||
|
||||
var testId = generateTestId();
|
||||
|
||||
var protractorConfigFile = path.resolve(projectRoot, 'scripts/snapshot/protractor.config.js');
|
||||
|
||||
snapshotValues.params.test_id = testId;
|
||||
snapshotValues.params.upload = !quickMode;
|
||||
|
||||
var protractorArgs = [
|
||||
'--browser ' + snapshotValues.browser,
|
||||
'--platform ' + snapshotValues.platform,
|
||||
'--params.platform_id=' + snapshotValues.params.platform_id,
|
||||
'--params.platform_index=' + snapshotValues.params.platform_index,
|
||||
'--params.platform_count=' + snapshotValues.params.platform_count,
|
||||
'--params.width=' + snapshotValues.params.width,
|
||||
'--params.height=' + snapshotValues.params.height,
|
||||
'--params.test_id=' + snapshotValues.params.test_id,
|
||||
'--params.upload=' + snapshotValues.params.upload
|
||||
];
|
||||
|
||||
e2ePublish(testId, false);
|
||||
|
||||
return protractor(done, [protractorConfigFile].concat(protractorArgs));
|
||||
}
|
||||
|
||||
function protractor(done, args) {
|
||||
var errored = false;
|
||||
var child = cp.spawn('protractor', args, {
|
||||
stdio: [process.stdin, process.stdout, 'pipe']
|
||||
});
|
||||
|
||||
child.stderr.on('data', function(data) {
|
||||
protractorHttpServer.close();
|
||||
console.error(data.toString());
|
||||
if (!errored) {
|
||||
errored = true;
|
||||
done('Protractor tests failed.');
|
||||
}
|
||||
});
|
||||
|
||||
child.on('exit', function() {
|
||||
protractorHttpServer.close();
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
function e2ePublish(testId, verbose) {
|
||||
console.log('e2ePublish: ' + testId);
|
||||
snapshotConfig.testId = testId;
|
||||
snapshotConfig.verbose = verbose;
|
||||
require('../e2e/e2e-publish')(snapshotConfig);
|
||||
}
|
||||
|
||||
function generateTestId() {
|
||||
var chars = 'abcdefghijkmnpqrstuvwxyz';
|
||||
var 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;
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user