feat(screenshot): Update screenshot golds for merged PR (#3365)

This commit is contained in:
tinayuangao
2017-03-01 15:55:18 -08:00
committed by Kara
parent 8aa9857e8e
commit 14912911e4
+12 -6
View File
@@ -21,11 +21,17 @@ task('screenshots', () => {
.then((files: any[]) => downloadAllGoldsAndCompare(files, database, prNumber))
.then((results: boolean) => updateResult(database, prNumber, results))
.then((result: boolean) => updateGithubStatus(result, prNumber))
.then(() => uploadScreenshots(prNumber, 'diff'))
.then(() => uploadScreenshots(prNumber, 'test'))
.then(() => uploadScreenshots('diff', prNumber))
.then(() => uploadScreenshots('test', prNumber))
.then(() => updateTravis(database, prNumber))
.then(() => setScreenFilenames(database, prNumber))
.then(() => database.goOffline(), () => database.goOffline());
} else if (process.env['TRAVIS']) {
// Only update golds and filenames for build
let database = openFirebaseScreenshotsDatabase();
uploadScreenshots('gold')
.then(() => setScreenFilenames(database))
.then(() => database.goOffline(), () => database.goOffline());
}
});
@@ -70,19 +76,19 @@ function getLocalScreenshotFiles(dir: string): string[] {
* Upload screenshots to google cloud storage.
* @param prNumber - The key used in firebase. Here it is the PR number.
* If there's no prNumber, we will upload images to 'golds/' folder
* @param mode - Can be 'test' or 'diff' or null.
* @param mode - Can be 'test' or 'diff' or 'gold'.
* If the images are the test results, mode should be 'test'.
* If the images are the diff images generated, mode should be 'diff'.
* For golds mode should be null.
* For golds mode should be 'gold'.
*/
function uploadScreenshots(prNumber?: string, mode?: 'test' | 'diff') {
function uploadScreenshots(mode?: 'test' | 'diff' | 'gold', prNumber?: string) {
let bucket = openScreenshotsBucket();
let promises: any[] = [];
let localDir = mode == 'diff' ? path.join(SCREENSHOT_DIR, 'diff') : SCREENSHOT_DIR;
getLocalScreenshotFiles(localDir).forEach((file: string) => {
let fileName = path.join(localDir, file);
let destination = (mode == null || !prNumber) ?
let destination = (mode == 'gold' || !prNumber) ?
`golds/${file}` : `screenshots/${prNumber}/${mode}/${file}`;
promises.push(bucket.upload(fileName, { destination: destination }));
});