Skip to content

Commit 1670ee4

Browse files
committed
Change directory to constant, and use variable to store name
1 parent a48c356 commit 1670ee4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

e2e/screenshot.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import * as gulp from 'gulp';
33
import * as path from 'path';
44
import {browser} from 'protractor';
55

6+
const OUTPUT_DIR = '/tmp/angular-material2-build/screenshots/';
7+
8+
let currentJasmineSpecName = '';
69

710
function initializeEnvironment(jasmine: any) {
811
var reporter = new jasmine.JsApiReporter({});
912
reporter.specStarted = function(result: any) {
10-
jasmine.getEnv().currentSpec = result.fullName;
13+
currentJasmineSpecName = result.fullName;
1114
};
1215
jasmine.getEnv().addReporter(reporter);
1316
}
@@ -16,7 +19,6 @@ initializeEnvironment(jasmine);
1619

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

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

3032
/** The full path to the screenshot */
3133
get fullPath(): string {
32-
return path.resolve(this.dir, this.filename);
34+
return path.resolve(OUTPUT_DIR, this.filename);
3335
}
3436

3537
constructor(id: string) {
36-
this.id = `${jasmine.getEnv().currentSpec} ${id}`;
38+
this.id = `${currentJasmineSpecName} ${id}`;
3739
browser.takeScreenshot().then(png => this.storeScreenshot(png));
3840
}
3941

4042
/** Replaces the existing screenshot with the newly generated one. */
4143
storeScreenshot(png: any) {
42-
if (!fs.existsSync(this.dir)) {
43-
fs.mkdirSync(this.dir, '744');
44+
if (!fs.existsSync(OUTPUT_DIR)) {
45+
fs.mkdirSync(OUTPUT_DIR, '744');
4446
}
4547

46-
if (fs.existsSync(this.dir)) {
48+
if (fs.existsSync(OUTPUT_DIR)) {
4749
fs.writeFileSync(this.fullPath, png, {encoding: 'base64' });
4850
}
4951
}

0 commit comments

Comments
 (0)