@@ -4,6 +4,9 @@ const ecstatic = require('ecstatic');
4
4
const fs = require ( 'fs-extra' ) ;
5
5
const glob = require ( 'glob' ) ;
6
6
7
+ const APPLITOOLS_CONFIG = 'applitools.config.js' ;
8
+ const VISUAL_DIFF = 'visual-diff' ;
9
+
7
10
module . exports = {
8
11
onPreBuild : async ( { utils } ) => {
9
12
// bail immediately if this isn’t a production build
@@ -20,37 +23,35 @@ module.exports = {
20
23
'No Applitools API key found! Set APPLITOOLS_API_KEY with your API key from https://eyes.applitools.com' ,
21
24
) ;
22
25
}
23
-
24
- const applitoolsConfig = {
25
- showLogs : true
26
- }
27
-
28
- fs . writeFile ( path . resolve ( PUBLISH_DIR , '..' , 'applitools.config.js' ) , `module.exports = ${ JSON . stringify ( applitoolsConfig ) } ` , 'utf8' ) ;
29
26
30
27
const port = 9919 ;
31
28
const server = http
32
29
. createServer ( ecstatic ( { root : `${ PUBLISH_DIR } ` } ) )
33
30
. listen ( port ) ;
34
31
35
- fs . copy (
36
- path . resolve ( __dirname , 'template/visual-diff.json' ) ,
37
- path . resolve ( PUBLISH_DIR , '..' , 'visual-diff.json' ) ,
38
- ) ;
32
+ const applitoolsConfig = {
33
+ showLogs : true ,
34
+ } ;
39
35
40
- fs . copy (
41
- path . resolve ( __dirname , 'template/visual-diff' ) ,
42
- path . resolve ( PUBLISH_DIR , '..' , 'visual-diff' ) ,
43
- ) ;
36
+ await Promise . all ( [
37
+ fs . writeFile (
38
+ APPLITOOLS_CONFIG ,
39
+ `module.exports = ${ JSON . stringify ( applitoolsConfig ) } ` ,
40
+ 'utf8' ,
41
+ ) ,
42
+ fs . copy ( `${ __dirname } /template/${ VISUAL_DIFF } ` , VISUAL_DIFF ) ,
43
+ ] ) ;
44
44
45
45
const cypress = require ( 'cypress' ) ;
46
46
const builtPages = glob
47
47
. sync ( `${ PUBLISH_DIR } /**/*.html` )
48
48
. map ( ( p ) => path . dirname ( p . replace ( PUBLISH_DIR , '' ) ) ) ;
49
49
50
50
const results = await cypress . run ( {
51
- configFile : ' visual-diff.json' ,
52
- config : { baseUrl : `http://localhost:${ port } ` } ,
51
+ configFile : ` ${ VISUAL_DIFF } / visual-diff.json` ,
52
+ config : { baseUrl : `http://localhost:${ port } ` , video : false } ,
53
53
env : {
54
+ SITE_NAME : process . env . SITE_NAME || 'localhost-test' ,
54
55
APPLITOOLS_BROWSERS : JSON . stringify ( inputs . browser ) ,
55
56
APPLITOOLS_FAIL_BUILD_ON_DIFF : inputs . failBuildOnDiff ,
56
57
APPLITOOLS_SERVER_URL : inputs . serverUrl ,
@@ -61,7 +62,7 @@ module.exports = {
61
62
: [ ] ,
62
63
APPLITOOLS_CONCURRENCY : inputs . concurrency ,
63
64
PAGES_TO_CHECK : builtPages ,
64
- CYPRESS_CACHE_FOLDER : path . resolve ( PUBLISH_DIR , '..' , ' node_modules') ,
65
+ CYPRESS_CACHE_FOLDER : ' node_modules',
65
66
} ,
66
67
record : false ,
67
68
} ) ;
@@ -100,4 +101,12 @@ module.exports = {
100
101
) ;
101
102
}
102
103
} ,
104
+ onEnd : async ( ) => {
105
+ // cleanup transient files
106
+ await Promise . all ( [
107
+ fs . remove ( APPLITOOLS_CONFIG ) ,
108
+ fs . remove ( VISUAL_DIFF ) ,
109
+ fs . remove ( 'cypress' ) ,
110
+ ] ) ;
111
+ } ,
103
112
} ;
0 commit comments