From d33c70ae6337088aded93104d1120ed68b222f2c Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 26 Mar 2015 16:31:05 -0500 Subject: [PATCH] upload e2e tests --- scripts/e2e/e2e-publish.js | 81 +++++++++++++++++++++++++++++++ scripts/snapshot/snapshot.task.js | 10 ++++ 2 files changed, 91 insertions(+) create mode 100644 scripts/e2e/e2e-publish.js diff --git a/scripts/e2e/e2e-publish.js b/scripts/e2e/e2e-publish.js new file mode 100644 index 0000000000..9275c8db5f --- /dev/null +++ b/scripts/e2e/e2e-publish.js @@ -0,0 +1,81 @@ + +module.exports = function(options) { + + var fs = require('fs'); + var path = require('path'); + var request = require('request'); + var inputDir = path.join(__dirname, '../../dist'); + + + function uploadFiles(dir, urlPath) { + fs.readdir(dir, function(err, list) { + + list.forEach(function(file) { + var url = urlPath + '/' + file + + if (url.indexOf('/test/') > -1) return; + + fs.stat(dir + '/' + file, function(err, stat) { + if (stat && stat.isDirectory()) { + uploadFiles(dir + '/' + file, urlPath + '/' + file); + } else { + uploadFile(url, dir + '/' + file); + } + }); + + }); + + }); + } + + function uploadFile(archiveFileUrlPath, archiveFileLocalPath) { + var formData = { + url_path: archiveFileUrlPath, + group_id: options.groupId, + app_id: options.appId, + test_id: options.testId, + access_key: process.env.IONIC_SNAPSHOT_KEY + }; + + request.post({ + url: options.domain + '/e2e/upload-url', + formData: formData + }, + function(err, httpResponse, body) { + if (err) { + console.error('Get upload failed:', err); + } else { + if (httpResponse.statusCode == 200) { + uploadE2E(body, archiveFileUrlPath, archiveFileLocalPath); + } else { + console.error('Get upload error:', httpResponse.statusCode, body); + } + } + } + ); + } + + function uploadE2E(uploadUrl, archiveFileUrlPath, archiveFileLocalPath) { + var formData = { + file: fs.createReadStream(archiveFileLocalPath) + }; + + request.post({ + url: uploadUrl, + formData: formData + }, + function(err, httpResponse, body) { + if (err) { + console.error('Upload failed:', err); + } else { + if (httpResponse.statusCode != 200) { + console.error('Upload error:', httpResponse.statusCode, body); + } + } + } + ); + } + + uploadFiles(inputDir, ''); +}; + diff --git a/scripts/snapshot/snapshot.task.js b/scripts/snapshot/snapshot.task.js index 3bd85e51f4..9e48a1dfe2 100644 --- a/scripts/snapshot/snapshot.task.js +++ b/scripts/snapshot/snapshot.task.js @@ -23,6 +23,16 @@ module.exports = function(gulp, argv, buildConfig) { snapshot(done, configFile); }); + gulp.task('e2e-publish', function(done) { + var e2ePublish = require('../e2e/e2e-publish'); + e2ePublish({ + domain: 'http://ionic-snapshot-go.appspot.com', + groupId: 'ionic2', + appId: 'snapshot', + testId: uuid.v4() + }); + }); + var snapshotValues = _.merge({ browser: 'chrome', platform: 'linux',