@@ -3,11 +3,15 @@ import * as gulp from 'gulp';
33import * as path from 'path' ;
44import { browser } from 'protractor' ;
55
6+ const OUTPUT_DIR = '/tmp/angular-material2-build/screenshots/' ;
67
8+ let currentJasmineSpecName = '' ;
9+
10+ /** Adds a custom jasmine reporter that simply keeps track of the current test name. */
711function initializeEnvironment ( jasmine : any ) {
8- var reporter = new jasmine . JsApiReporter ( { } ) ;
12+ let reporter = new jasmine . JsApiReporter ( { } ) ;
913 reporter . specStarted = function ( result : any ) {
10- jasmine . getEnv ( ) . currentSpec = result . fullName ;
14+ currentJasmineSpecName = result . fullName ;
1115 } ;
1216 jasmine . getEnv ( ) . addReporter ( reporter ) ;
1317}
@@ -16,7 +20,6 @@ initializeEnvironment(jasmine);
1620
1721export class Screenshot {
1822 id : string ;
19- dir : string = '/tmp/angular-material2-build/screenshots/' ;
2023
2124 /** The filename used to store the screenshot. */
2225 get filename ( ) : string {
@@ -29,21 +32,21 @@ export class Screenshot {
2932
3033 /** The full path to the screenshot */
3134 get fullPath ( ) : string {
32- return path . resolve ( this . dir , this . filename ) ;
35+ return path . resolve ( OUTPUT_DIR , this . filename ) ;
3336 }
3437
3538 constructor ( id : string ) {
36- this . id = `${ jasmine . getEnv ( ) . currentSpec } ${ id } ` ;
39+ this . id = `${ currentJasmineSpecName } ${ id } ` ;
3740 browser . takeScreenshot ( ) . then ( png => this . storeScreenshot ( png ) ) ;
3841 }
3942
4043 /** Replaces the existing screenshot with the newly generated one. */
4144 storeScreenshot ( png : any ) {
42- if ( ! fs . existsSync ( this . dir ) ) {
43- fs . mkdirSync ( this . dir , '744' ) ;
45+ if ( ! fs . existsSync ( OUTPUT_DIR ) ) {
46+ fs . mkdirSync ( OUTPUT_DIR , '744' ) ;
4447 }
4548
46- if ( fs . existsSync ( this . dir ) ) {
49+ if ( fs . existsSync ( OUTPUT_DIR ) ) {
4750 fs . writeFileSync ( this . fullPath , png , { encoding : 'base64' } ) ;
4851 }
4952 }
0 commit comments