upload e2e tests

This commit is contained in:
Adam Bradley
2015-03-26 16:31:05 -05:00
parent 7b24610d0c
commit d33c70ae63
2 changed files with 91 additions and 0 deletions

View File

@ -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, '');
};