mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
upload e2e tests
This commit is contained in:
81
scripts/e2e/e2e-publish.js
Normal file
81
scripts/e2e/e2e-publish.js
Normal 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, '');
|
||||
};
|
||||
|
Reference in New Issue
Block a user