Skip to content

Commit 8fea035

Browse files
authored
Try to fix CI tests (#597)
* Try to fix CI tests * Fix screenshot tests on CI
1 parent 2ec9603 commit 8fea035

File tree

11 files changed

+146
-34
lines changed

11 files changed

+146
-34
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ jobs:
5959
# Validate the common package, only for Mercury
6060
- name: validate (common package)
6161
if: ${{ inputs.tests == true }}
62-
run: yarn test
63-
working-directory: "packages/common"
62+
run: yarn test.common.ci
6463

6564
- name: validate
6665
run: yarn validate.ci

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
"build.mer": "cd packages/mercury && yarn && yarn build-no-svg",
1010
"test.common": "cd packages/common && yarn && yarn test",
1111
"test.common.watch": "cd packages/common && yarn && yarn test.watch",
12+
"test.common.ci": "yarn build.mer.common && cd packages/common && yarn && yarn test.ci",
1213
"test.mer": "cd packages/mercury && yarn && yarn test",
1314
"test.mer.watch": "cd packages/mercury && yarn && yarn test.watch",
1415
"build.mer.watch": "cd packages/mercury && yarn && yarn build.scss.watch",
16+
"build.mer.common": "cd packages/mercury && yarn build.scss.test-common",
1517
"build.un": "cd packages/unanimo && yarn && yarn build",
1618
"build.un.watch": "cd packages/unanimo && yarn && yarn build",
1719
"start": "yarn build.common && cd packages/showcase && yarn && yarn start",

packages/common/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ VITE_UPDATE_SCREENSHOT_ON_MISMATCH = false
88
VITE_KEEP_PNG_FILE = true
99

1010
# true to only generate PNGs for failed tests
11-
NODE_ONLY_GENERATE_FAILED = true
11+
NODE_ONLY_GENERATE_FAILED = true
12+
13+
# true if the tests are running on the CI
14+
VITE_CI = false

packages/common/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
"type": "module",
1515
"scripts": {
1616
"build": "tsc --project tsconfig-build.json",
17-
"build.scss": "mercury -i=/assets/icons/ -f=/assets/fonts/ --outDir=./public/mercury/css/",
17+
"build.scss": "yarn mercury -i=/assets/icons/ -f=/assets/fonts/ --outDir=./public/mercury/css/",
1818
"test": "yarn build.scss && yarn playwright install && vitest",
19+
"test.ci": "yarn playwright install && vitest",
1920
"test.watch": "yarn build.scss && yarn playwright install && vitest watch",
2021
"test.watch.ui": "yarn test.watch --ui"
2122
},
2223
"license": "Apache-2.0",
24+
"dependencies": {
25+
"@genexus/chameleon-controls-library": "~6.15.0"
26+
},
2327
"devDependencies": {
2428
"@eslint/js": "~9.26.0",
25-
"@genexus/chameleon-controls-library": "~6.7.0",
2629
"@jackolope/ts-lit-plugin": "^3.1.4",
2730
"@types/node": "~22.15.17",
2831
"@typescript-eslint/parser": "~8.32.0",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import pixelmatch from "pixelmatch";
66
// to minor pixel differences
77
const SENSIBILITY = 0.007;
88

9+
const RUNNING_ON_CI = import.meta.env.VITE_CI !== "true";
10+
911
const getImageDataFromBase64 = (base64String: string) =>
1012
new Promise<ImageData>((resolve, reject) => {
1113
const img = new Image();
@@ -82,7 +84,7 @@ export const compareImages = async (
8284
reader.onerror = reject;
8385
});
8486

85-
if (mismatchedPixels !== 0 && !process.env.CI) {
87+
if (mismatchedPixels !== 0 && !RUNNING_ON_CI) {
8688
await server.commands.writeFile(diffFileName, base64String, {
8789
encoding: "base64"
8890
});

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const shouldAddNewScreenshots =
2828
import.meta.env.VITE_ADD_NEW_SCREENSHOTS === "true";
2929
const shouldKeepPngFile = import.meta.env.VITE_KEEP_PNG_FILE === "true";
3030

31+
const RUNNING_ON_CI = import.meta.env.VITE_CI !== "true";
32+
3133
setBundleMapping(bundleToHashMappings);
3234
registerMercury();
3335
defineCustomElements(window);
@@ -234,7 +236,7 @@ export const runScreenshotTest = (
234236
if (shouldUpdateScreenshotOnMismatch) {
235237
return Promise.allSettled([
236238
// Replace the expected base64
237-
!process.env.CI &&
239+
!RUNNING_ON_CI &&
238240
server.commands.writeFile(
239241
screenshotPaths.base64,
240242
currentScreenshot.base64,
@@ -247,7 +249,7 @@ export const runScreenshotTest = (
247249

248250
// Store the .newBase64 to properly update the expected value
249251
// if necessary
250-
if (!process.env.CI) {
252+
if (!RUNNING_ON_CI) {
251253
await server.commands.writeFile(
252254
screenshotPaths.newBase64,
253255
currentScreenshot.base64,
@@ -271,7 +273,7 @@ export const runScreenshotTest = (
271273
if (shouldAddNewScreenshots) {
272274
// Replace the expected base64
273275
return (
274-
!process.env.CI &&
276+
!RUNNING_ON_CI &&
275277
server.commands.writeFile(
276278
screenshotPaths.base64,
277279
currentScreenshot.base64,

packages/mercury/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@
4646
"./package.json": "./package.json"
4747
},
4848
"scripts": {
49-
"build": "yarn build.js && yarn icons-svg && yarn icons-sass && yarn build.scss && yarn copy-tasks && yarn showcase.scss",
49+
"build": "yarn build.js && yarn icons-svg && yarn icons-sass && yarn build.scss && yarn copy-tasks",
5050
"build.js": "tsc && esbuild dist/*.js --allow-overwrite --minify --outdir=dist --log-level=silent && esbuild dist/assets/*.js --allow-overwrite --minify --outdir=dist/assets --log-level=silent",
5151
"build-no-svg": "yarn build.js && yarn build.scss && yarn copy-tasks",
5252
"build.scss": "yarn build.scss.base && yarn build.scss.bundles",
5353
"build.scss.base": "scss-bundle -e ./src/icons/_generated/categories.scss -o src/icons/_generated/categories-bundled.scss --logLevel=silent",
5454
"build.scss.bundles": "node dist/cli/bundle.js",
5555
"build.scss.watch": "tsc && yarn build.scss.base && yarn copy-tasks && yarn build.scss.bundles --watch -i=/assets/icons/ -f=/assets/fonts/ --outDir=../showcase/.mercury/ --avoid-hash=base/base",
56-
"start": "vite --port 5200 --open showcase/button.html",
56+
"build.scss.test-common": "tsc && yarn build.scss.base && yarn copy-tasks && yarn build.scss.bundles --ci -i=/assets/icons/ -f=/assets/fonts/ --outDir=../common/public/mercury/css/",
5757
"build.scss.helpers": "scss-bundle -e ./src/assets/scss/_helpers.scss -o ./src/assets/scss/helpers-bundled.scss --logLevel=info",
58-
"validate.ci": "yarn build-no-svg && yarn test",
59-
"icons-svg": "ssg-svg --srcDir=src/icons/svg-source --outDir=src/assets/icons/_generated/ --configFilePath=src/icons/svg-source/.config/color-states.json --showcaseDir=showcase/icons/ --showcaseBaseHref=../assets/icons/ --logDir=./log --objectFilePath=src/assets/MERCURY_ASSETS.ts --defaultColorType=on-surface",
58+
"start": "vite --port 5200 --open showcase/button.html",
6059
"process-icons": "ssg --configPath=./src/config/icons.js",
60+
"icons-svg": "ssg-svg --srcDir=src/icons/svg-source --outDir=src/assets/icons/_generated/ --configFilePath=src/icons/svg-source/.config/color-states.json --showcaseDir=showcase/icons/ --showcaseBaseHref=../assets/icons/ --logDir=./log --objectFilePath=src/assets/MERCURY_ASSETS.ts --defaultColorType=on-surface",
6161
"icons-sass": "ssg-sass --srcDir=src/assets/icons/ --outDir=src/icons/_generated/ --configFilePath=src/icons/svg-source/.config/color-states.json --vendorPrefix=",
6262
"watch.scss": "chokidar src/**/*.scss ../common/**/*.scss -c \"npm run build.scss\"",
6363
"watch.scss.mac": "chokidar 'src/**/*.scss' '../common/**/*.scss' -c \"npm run build.scss\"",
6464
"copy-tasks": "node copy-tasks.js",
65-
"showcase.scss": "sass showcase/scss/showcase-sass.scss showcase/css/showcase-sass.css",
6665
"coverage": "yarn playwright install && vitest watch run --coverage",
66+
"validate.ci": "yarn build-no-svg && yarn test",
6767
"test": "yarn playwright install && vitest",
6868
"test.watch": "yarn playwright install && vitest watch"
6969
},

packages/mercury/src/cli/bundle.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import fs from "node:fs/promises";
3-
import path from "node:path";
43
import os from "node:os";
4+
import path from "node:path";
55
import { fileURLToPath } from "node:url";
66
import { Worker, isMainThread, parentPort } from "worker_threads";
77

@@ -12,30 +12,30 @@ import type {
1212
MercuryBundleReset
1313
} from "../types";
1414

15-
import {
16-
ensureDirectoryExistsAndItsClear,
17-
getFilesInDir,
18-
refreshAngularBrowser
19-
// copyDirectories
20-
} from "./internal/file-management.js";
2115
import {
2216
BASE_BUNDLES_OUT_DIR,
2317
CSS_BUNDLES_OUT_DIR,
2418
SCSS_BUNDLES_INPUT_DIR
2519
// SCSS_BUNDLES_OUT_DIR
2620
} from "./internal/constants.js";
21+
import {
22+
ensureDirectoryExistsAndItsClear,
23+
getFilesInDir,
24+
refreshAngularBrowser
25+
// copyDirectories
26+
} from "./internal/file-management.js";
2727
import { transpileCssBundleWithPlaceholder } from "./internal/transpile-bundle-and-create-mappings.js";
2828
import { measureTime } from "./internal/utils.js";
2929

30-
import type { CLIArguments, FileMetadata } from "./internal/types";
30+
import { createBundlesWithCustomPaths } from "./internal/create-bundles-with-custom-paths.js";
3131
import { printBundleWasTranspiled } from "./internal/print-utils.js";
32+
import type { CLIArguments, FileMetadata } from "./internal/types";
33+
import { getArguments } from "./internal/validate-args.js";
3234
import {
3335
printRebuilding,
3436
stopRebuildingStdout,
3537
watchFileSystemChanges
3638
} from "./internal/watch-fs.js";
37-
import { getArguments } from "./internal/validate-args.js";
38-
import { createBundlesWithCustomPaths } from "./internal/create-bundles-with-custom-paths.js";
3939

4040
type BundleToAvoidRebuild =
4141
| MercuryBundleBase
@@ -52,10 +52,11 @@ const MESSAGE_TYPE = {
5252
if (isMainThread) {
5353
const [, , ...args] = process.argv;
5454
const watchMode = args.find(arg => arg === "--watch");
55+
const ciMode = args.find(arg => arg === "--ci");
5556
let cliArgs: CLIArguments | undefined;
5657

5758
// Check if the bundles processing is running in watch mode
58-
if (watchMode) {
59+
if (watchMode || ciMode) {
5960
cliArgs = getArguments();
6061

6162
if (!cliArgs) {
@@ -191,7 +192,7 @@ if (isMainThread) {
191192
return;
192193
}
193194

194-
if (!watchMode) {
195+
if (!watchMode && !ciMode) {
195196
printBundleWasTranspiled(fileMetadata.filePath);
196197
}
197198

@@ -261,6 +262,9 @@ if (isMainThread) {
261262
measureTime(compileAndCreateBundles).finally(() =>
262263
watchFileSystemChanges(compileAndCreateBundles)
263264
);
265+
} else if (ciMode) {
266+
await compileAndCreateBundles();
267+
process.exit();
264268
}
265269
// There is no need to wait for any changes, since the watch mode is not enabled
266270
else {

packages/mercury/src/cli/internal/validate-args.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { CLIArguments } from "./types";
21
import {
32
DEFAULT_FONT_FACE_PATH,
43
DEFAULT_ICONS_PATH,
@@ -13,6 +12,7 @@ import {
1312
printMissingIconsPathArgumentWarning,
1413
printMissingOutDirPathArgumentWarning
1514
} from "./print-utils.js";
15+
import type { CLIArguments } from "./types";
1616
import { sanitizeBundleName } from "./utils.js";
1717

1818
const ARGUMENT_VALUE_AND_NAME_SEPARATOR_REGEX = /\s*=\s*/g;
@@ -76,7 +76,8 @@ const checkArgument = (argument: string): boolean => {
7676
);
7777

7878
if (argNameWithValue.length !== 2) {
79-
if (argNameWithValue[0] === "--watch") {
79+
// Special arguments that don't throw error
80+
if (argNameWithValue[0] === "--watch" || argNameWithValue[0] === "--ci") {
8081
return SUCCESS_CHECK;
8182
}
8283

packages/showcase/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@genexus/unanimo": "latest",
3030
"@open-wc/lit-helpers": "^0.7.0",
3131
"express": "^4.21.2",
32-
"lit": "^3.3.0",
32+
"lit": "~3.3.0",
3333
"tslib": "~2.8.1"
3434
},
3535
"devDependencies": {

0 commit comments

Comments
 (0)