Simplify API for storing html and json.

This commit is contained in:
Tobias Lidskog 2016-09-26 08:47:04 +02:00
parent 06e471b93e
commit 0b2a233edc
4 changed files with 18 additions and 32 deletions

View File

@ -30,7 +30,7 @@ module.exports = {
}
if (message.url) {
return this.storageManager.writeDataForUrl(message.url, fileName, jsonData);
return this.storageManager.writeDataForUrl(jsonData, fileName, message.url);
} else {
return this.storageManager.writeData(fileName, jsonData);
}

View File

@ -136,7 +136,7 @@ class HTMLBuilder {
h: helpers
}, locals);
return this.storageManager.writeHtmlForUrl(url, name + '.html', renderer.renderTemplate('url/' + name, locals));
return this.storageManager.writeHtmlForUrl(renderer.renderTemplate('url/' + name, locals), name + '.html', url);
}
_renderUrlRunPage(url, name, locals) {
@ -153,7 +153,7 @@ class HTMLBuilder {
h: helpers
}, locals);
return this.storageManager.writeHtmlForUrl(url, name + '.html', renderer.renderTemplate('url/run', locals));
return this.storageManager.writeHtmlForUrl(renderer.renderTemplate('url/run', locals), name + '.html', url);
}
_renderSummaryPage(name, locals) {

View File

@ -23,25 +23,19 @@ function storeFirefoxScreenshots(options, url, imagesAndName, storageManager) {
const width = Number(options.browsertime.viewPort.split('x')[0]);
const height = Number(options.browsertime.viewPort.split('x')[1]);
// Firfox screenshots take the full height of the browser window, so Lets crop
return storageManager.createDirForUrl(url, 'screenshots').
then((dirPath) => {
return Promise.map(imagesAndName, function(screenshot) {
return PNGCrop.cropAsync(screenshot.data, path.join(dirPath, screenshot.name), {
width,
height
});
})
})
// Firefox screenshots take the full height of the browser window, so let's crop
return storageManager.createDirForUrl(url, 'screenshots')
.then((dirPath) => Promise.map(imagesAndName, (screenshot) =>
PNGCrop.cropAsync(screenshot.data, path.join(dirPath, screenshot.name), {
width,
height
}
)))
}
function storeChromeScreenshots(url, imagesAndName, storageManager) {
return storageManager.createDirForUrl(url, 'screenshots').
then((dirPath) => {
return Promise.map(imagesAndName, function(screenshot) {
return storageManager.writeInDir(dirPath, screenshot.name, screenshot.data);
})
})
return Promise.map(imagesAndName, (screenshot) =>
storageManager.writeDataForUrl(screenshot.data, screenshot.name, url, 'screenshots'));
}
module.exports = {

View File

@ -95,21 +95,13 @@ class StorageManager {
.tap((dirPath) => mkdirp(dirPath));
}
createDataDirForUrl(url) {
return this.createDirForUrl(url, 'data');
writeDataForUrl(data, filename, url, subDir) {
const dirPath = ['data', subDir].filter(Boolean).join(path.delimiter);
return write(this.createDirForUrl(url, dirPath), filename, data);
}
writeDataForUrl(url, filename, data) {
return this.createDataDirForUrl(url)
.then((dirPath) => write(dirPath, filename, data));
}
writeInDir(dir, filename, data) {
return write(dir, filename, data);
}
writeHtmlForUrl(url, filename, data) {
return write(this.createDirForUrl(url), filename, data);
writeHtmlForUrl(html, filename, url) {
return write(this.createDirForUrl(url), filename, html);
}
}