Skip to content

Commit

Permalink
Change directory to constant, and use variable to store name
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao committed Jan 7, 2017
1 parent a48c356 commit 1670ee4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions e2e/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import * as gulp from 'gulp';
import * as path from 'path';
import {browser} from 'protractor';

const OUTPUT_DIR = '/tmp/angular-material2-build/screenshots/';

let currentJasmineSpecName = '';

function initializeEnvironment(jasmine: any) {
var reporter = new jasmine.JsApiReporter({});
reporter.specStarted = function(result: any) {
jasmine.getEnv().currentSpec = result.fullName;
currentJasmineSpecName = result.fullName;
};
jasmine.getEnv().addReporter(reporter);
}
Expand All @@ -16,7 +19,6 @@ initializeEnvironment(jasmine);

export class Screenshot {
id: string;
dir: string = '/tmp/angular-material2-build/screenshots/';

/** The filename used to store the screenshot. */
get filename(): string {
Expand All @@ -29,21 +31,21 @@ export class Screenshot {

/** The full path to the screenshot */
get fullPath(): string {
return path.resolve(this.dir, this.filename);
return path.resolve(OUTPUT_DIR, this.filename);
}

constructor(id: string) {
this.id = `${jasmine.getEnv().currentSpec} ${id}`;
this.id = `${currentJasmineSpecName} ${id}`;
browser.takeScreenshot().then(png => this.storeScreenshot(png));
}

/** Replaces the existing screenshot with the newly generated one. */
storeScreenshot(png: any) {
if (!fs.existsSync(this.dir)) {
fs.mkdirSync(this.dir, '744');
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR, '744');
}

if (fs.existsSync(this.dir)) {
if (fs.existsSync(OUTPUT_DIR)) {
fs.writeFileSync(this.fullPath, png, {encoding: 'base64' });
}
}
Expand Down

0 comments on commit 1670ee4

Please sign in to comment.