@@ -3,11 +3,14 @@ import * as gulp from 'gulp';
3
3
import * as path from 'path' ;
4
4
import { browser } from 'protractor' ;
5
5
6
+ const OUTPUT_DIR = '/tmp/angular-material2-build/screenshots/' ;
7
+
8
+ let currentJasmineSpecName = '' ;
6
9
7
10
function initializeEnvironment ( jasmine : any ) {
8
11
var reporter = new jasmine . JsApiReporter ( { } ) ;
9
12
reporter . specStarted = function ( result : any ) {
10
- jasmine . getEnv ( ) . currentSpec = result . fullName ;
13
+ currentJasmineSpecName = result . fullName ;
11
14
} ;
12
15
jasmine . getEnv ( ) . addReporter ( reporter ) ;
13
16
}
@@ -16,7 +19,6 @@ initializeEnvironment(jasmine);
16
19
17
20
export class Screenshot {
18
21
id : string ;
19
- dir : string = '/tmp/angular-material2-build/screenshots/' ;
20
22
21
23
/** The filename used to store the screenshot. */
22
24
get filename ( ) : string {
@@ -29,21 +31,21 @@ export class Screenshot {
29
31
30
32
/** The full path to the screenshot */
31
33
get fullPath ( ) : string {
32
- return path . resolve ( this . dir , this . filename ) ;
34
+ return path . resolve ( OUTPUT_DIR , this . filename ) ;
33
35
}
34
36
35
37
constructor ( id : string ) {
36
- this . id = `${ jasmine . getEnv ( ) . currentSpec } ${ id } ` ;
38
+ this . id = `${ currentJasmineSpecName } ${ id } ` ;
37
39
browser . takeScreenshot ( ) . then ( png => this . storeScreenshot ( png ) ) ;
38
40
}
39
41
40
42
/** Replaces the existing screenshot with the newly generated one. */
41
43
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' ) ;
44
46
}
45
47
46
- if ( fs . existsSync ( this . dir ) ) {
48
+ if ( fs . existsSync ( OUTPUT_DIR ) ) {
47
49
fs . writeFileSync ( this . fullPath , png , { encoding : 'base64' } ) ;
48
50
}
49
51
}
0 commit comments