Skip to content

Commit d711cac

Browse files
committed
fix: add missing awaits, fix Cypress config
1 parent bdafe75 commit d711cac

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

index.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const ecstatic = require('ecstatic');
44
const fs = require('fs-extra');
55
const glob = require('glob');
66

7+
const APPLITOOLS_CONFIG = 'applitools.config.js';
8+
const VISUAL_DIFF = 'visual-diff';
9+
710
module.exports = {
811
onPreBuild: async ({ utils }) => {
912
// bail immediately if this isn’t a production build
@@ -20,37 +23,35 @@ module.exports = {
2023
'No Applitools API key found! Set APPLITOOLS_API_KEY with your API key from https://eyes.applitools.com',
2124
);
2225
}
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');
2926

3027
const port = 9919;
3128
const server = http
3229
.createServer(ecstatic({ root: `${PUBLISH_DIR}` }))
3330
.listen(port);
3431

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+
};
3935

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+
]);
4444

4545
const cypress = require('cypress');
4646
const builtPages = glob
4747
.sync(`${PUBLISH_DIR}/**/*.html`)
4848
.map((p) => path.dirname(p.replace(PUBLISH_DIR, '')));
4949

5050
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 },
5353
env: {
54+
SITE_NAME: process.env.SITE_NAME || 'localhost-test',
5455
APPLITOOLS_BROWSERS: JSON.stringify(inputs.browser),
5556
APPLITOOLS_FAIL_BUILD_ON_DIFF: inputs.failBuildOnDiff,
5657
APPLITOOLS_SERVER_URL: inputs.serverUrl,
@@ -61,7 +62,7 @@ module.exports = {
6162
: [],
6263
APPLITOOLS_CONCURRENCY: inputs.concurrency,
6364
PAGES_TO_CHECK: builtPages,
64-
CYPRESS_CACHE_FOLDER: path.resolve(PUBLISH_DIR, '..', 'node_modules'),
65+
CYPRESS_CACHE_FOLDER: 'node_modules',
6566
},
6667
record: false,
6768
});
@@ -100,4 +101,12 @@ module.exports = {
100101
);
101102
}
102103
},
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+
},
103112
};

template/visual-diff.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

template/visual-diff/integration/visualdiff.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
describe('check the site for visual regressions', () => {
22
beforeEach(() => {
33
cy.eyesOpen({
4-
appName: process.env.SITE_NAME || 'localhost-test',
5-
batchName: process.env.SITE_NAME || 'localhost-test',
4+
appName: Cypress.env('SITE_NAME'),
5+
batchName: Cypress.env('SITE_NAME'),
66
browser: JSON.parse(Cypress.env('APPLITOOLS_BROWSERS')),
77
failBuildOnDiff: Boolean(Cypress.env('APPLITOOLS_FAIL_BUILD_ON_DIFF')),
88
serverUrl: Cypress.env('APPLITOOLS_SERVER_URL'),

template/visual-diff/visual-diff.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrationFolder": "visual-diff/integration",
3+
"pluginsFile": "visual-diff/plugins",
4+
"supportFile": "visual-diff/support"
5+
}

0 commit comments

Comments
 (0)