Skip to content

Commit 2ec9603

Browse files
authored
Try to run screenshot tests in CI (#596)
* Try to run screenshot tests in CI * Fix script * Try to fix script again * Try to fix script again 2 * Try to fix script again 3
1 parent 786ee43 commit 2ec9603

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

.github/workflows/install-and-deploy.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ on:
1919
description: "Use cache node modules"
2020
required: false
2121
type: boolean
22+
tests:
23+
description: "Screenshot tests for the design system"
24+
required: false
25+
type: boolean
2226

2327
jobs:
2428
install:
@@ -52,6 +56,12 @@ jobs:
5256
run: yarn
5357
working-directory: ${{ inputs.package }}
5458

59+
# Validate the common package, only for Mercury
60+
- name: validate (common package)
61+
if: ${{ inputs.tests == true }}
62+
run: yarn test
63+
working-directory: "packages/common"
64+
5565
- name: validate
5666
run: yarn validate.ci
5767
working-directory: ${{ inputs.package }}

.github/workflows/node.js.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
with:
1313
node-version: "20.x"
1414
cache: true
15+
tests: false
1516
publish: false
1617
package: "packages/unanimo"
1718

@@ -20,6 +21,7 @@ jobs:
2021
with:
2122
node-version: "20.x"
2223
cache: true
24+
tests: true
2325
publish: false
2426
package: "packages/mercury"
2527

@@ -28,5 +30,6 @@ jobs:
2830
with:
2931
node-version: "20.x"
3032
cache: true
33+
tests: false
3134
publish: false
3235
package: "packages/svg-sass-generator"

.github/workflows/npmpublish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
with:
8787
node-version: "20.x"
8888
cache: false
89+
tests: false
8990
publish: true
9091
package: "packages/unanimo"
9192
secrets: inherit
@@ -97,6 +98,7 @@ jobs:
9798
with:
9899
node-version: "20.x"
99100
cache: false
101+
tests: true
100102
publish: true
101103
package: "packages/mercury"
102104
secrets: inherit
@@ -108,6 +110,7 @@ jobs:
108110
with:
109111
node-version: "20.x"
110112
cache: false
113+
tests: false
111114
publish: true
112115
package: "packages/svg-sass-generator"
113116
secrets: inherit

packages/common/src/tests/screenshot/compare-images.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const compareImages = async (
8282
reader.onerror = reject;
8383
});
8484

85-
if (mismatchedPixels !== 0) {
85+
if (mismatchedPixels !== 0 && !process.env.CI) {
8686
await server.commands.writeFile(diffFileName, base64String, {
8787
encoding: "base64"
8888
});

packages/common/src/tests/screenshot/screenshot.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,26 @@ export const runScreenshotTest = (
234234
if (shouldUpdateScreenshotOnMismatch) {
235235
return Promise.allSettled([
236236
// Replace the expected base64
237-
server.commands.writeFile(
238-
screenshotPaths.base64,
239-
currentScreenshot.base64,
240-
{ encoding: "utf-8" }
241-
),
237+
!process.env.CI &&
238+
server.commands.writeFile(
239+
screenshotPaths.base64,
240+
currentScreenshot.base64,
241+
{ encoding: "utf-8" }
242+
),
242243

243244
cleanupScreenshots()
244245
]);
245246
}
246247

247248
// Store the .newBase64 to properly update the expected value
248249
// if necessary
249-
await server.commands.writeFile(
250-
screenshotPaths.newBase64,
251-
currentScreenshot.base64,
252-
{ encoding: "utf-8" }
253-
);
250+
if (!process.env.CI) {
251+
await server.commands.writeFile(
252+
screenshotPaths.newBase64,
253+
currentScreenshot.base64,
254+
{ encoding: "utf-8" }
255+
);
256+
}
254257

255258
// Throw the error, otherwise
256259
assert.fail(
@@ -267,10 +270,13 @@ export const runScreenshotTest = (
267270

268271
if (shouldAddNewScreenshots) {
269272
// Replace the expected base64
270-
return server.commands.writeFile(
271-
screenshotPaths.base64,
272-
currentScreenshot.base64,
273-
{ encoding: "utf-8" }
273+
return (
274+
!process.env.CI &&
275+
server.commands.writeFile(
276+
screenshotPaths.base64,
277+
currentScreenshot.base64,
278+
{ encoding: "utf-8" }
279+
)
274280
);
275281
}
276282

0 commit comments

Comments
 (0)