Skip to content

Commit b0cdbf5

Browse files
dbkrt3chguy
andauthored
Make shared component build work in isolation (#31066)
* Make shared component build work in isolation * Add deps that were missing because they were getting picked up from element-web main but shared-components needs itself * Exclude test files from dts generation * Bump version * Change all the shared-component import to be the built artifact * Don't randomly inhale eslint configs in parent dirs please * maybe we don't need this anymore? * maybe fix build * Maybe fix docker build * More build faff * build:res on the parent as part of shared component prepare * link shared component repo inn docker build * 💅 * 💅x2 * Try converting the translation keys to a .d.ts file manually so it gets bundled rather than left as a relative import to the json file * add the script * Add this back for 2nd time now I think * Shouldn't need this anymore * patch-package on prepare because we're patching a dev dependency so it won't be there if we're installed as a dependency * Unused import * Prettier compliance * Only use counterpart from shared components as per comment * Import shared components CSS * Prettier * Call the one from shared components rather than recurse infinitely * Hopefully make tests work * wake up, comment goes before import * Fix lint errors * Fix dupe TranslationKey export * Update compound-web to fix type error An update to @types.react adds the 'hint' value to the enum of the 'popover' attribute and this version of compound-web uses the maching verson of @types/react so they don't conflict. * Maybe, hopefully, get the types working? Please? * Add copyright header to i18nkeys as eslint complains otherwise since it's now in src * prettier * stop running shared-component tests in EW * update snapshots because flex is now from an external stylesheet I guess * More snapshots * Manual class update * Avoid bundling compound bits Because a) it's silly and b) it means we end up bundling a copy of floating-ui too which causes absolute madness with its useDelayGroup contexts. * ignore test util files for coverage * Add !important because the styles are being applied in a different order now * Another !important because css order has changed * Try adding it here to make the test files ignored * More !important * commit yarn lock change * Add shared components coverage file * Update snapshots Because the line height was being overridden to 22.5px somehow by something I can't find, and now isn't: surely the normal 1.5rem is more sensible. * Update snapshots, attempt 2 * Another !important * More snapshot updates * Add test for i18n wrappers & add test script * lint * Prettier * Hopefully run shared component tests * don't need this bit for non-matrix * install ew deps * rigfht coverage location * Rename job here too * Try different coverage filename * Fix copyrights & comment * Typo Co-authored-by: Michael Telatynski <[email protected]> --------- Co-authored-by: Michael Telatynski <[email protected]>
1 parent 486d4d5 commit b0cdbf5

File tree

133 files changed

+1708
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1708
-319
lines changed

.github/workflows/shared-component-visual-tests.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ jobs:
3434
- name: Install element web dependencies
3535
run: yarn install --frozen-lockfile
3636

37-
- name: Build Element Web resources
38-
# Needed to prepare language files
39-
run: "yarn build:res"
40-
4137
- name: Install dependencies
4238
working-directory: packages/shared-components
4339
run: yarn install --frozen-lockfile

.github/workflows/static_analysis.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ jobs:
3535
- name: Typecheck
3636
run: "yarn run lint:types"
3737

38-
- name: Build Element Web resources
39-
# Needed to prepare language files for shared components
40-
run: "yarn build:res"
41-
4238
- name: Install Shared Component Dependencies
4339
run: "yarn --cwd packages/shared-components install"
4440

@@ -91,10 +87,6 @@ jobs:
9187
- name: Run Linter
9288
run: "yarn run lint:js"
9389

94-
- name: Build Element Web resources
95-
# Needed to prepare language files for shared components
96-
run: "yarn build:res"
97-
9890
- name: Install Shared Component Deps
9991
run: "yarn --cwd packages/shared-components install --frozen-lockfile"
10092

.github/workflows/tests.yml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ env:
2929
permissions: {}
3030

3131
jobs:
32-
jest:
33-
name: Jest
32+
jest_ew:
33+
name: Jest (Element Web)
3434
runs-on: ubuntu-24.04
3535
strategy:
3636
fail-fast: false
@@ -93,13 +93,13 @@ jobs:
9393
9494
complete:
9595
name: jest-tests
96-
needs: jest
96+
needs: jest_ew
9797
if: always()
9898
runs-on: ubuntu-24.04
9999
permissions:
100100
statuses: write
101101
steps:
102-
- if: needs.jest.result != 'skipped' && needs.jest.result != 'success'
102+
- if: needs.jest_ew.result != 'skipped' && needs.jest_ew.result != 'success'
103103
run: exit 1
104104

105105
- name: Skip SonarCloud in merge queue
@@ -112,3 +112,56 @@ jobs:
112112
context: SonarCloud Code Analysis
113113
sha: ${{ github.sha }}
114114
target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
115+
116+
jest_sc:
117+
name: Jest (Shared Components)
118+
runs-on: ubuntu-24.04
119+
steps:
120+
- name: Checkout code
121+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
122+
with:
123+
repository: ${{ inputs.matrix-js-sdk-sha && 'element-hq/element-web' || github.repository }}
124+
125+
- name: Yarn cache
126+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
127+
with:
128+
node-version: "lts/*"
129+
cache: "yarn"
130+
131+
- name: Install EW Deps
132+
run: "yarn install"
133+
134+
- name: Install Shared Component Deps
135+
working-directory: "packages/shared-components"
136+
run: "yarn install"
137+
138+
- name: Jest Cache
139+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
140+
with:
141+
path: /tmp/jest_cache
142+
key: ${{ hashFiles('**/yarn.lock') }}
143+
144+
- name: Get number of CPU cores
145+
id: cpu-cores
146+
uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2
147+
148+
- name: Run tests
149+
working-directory: "packages/shared-components"
150+
run: |
151+
yarn test \
152+
--coverage=${{ env.ENABLE_COVERAGE }} \
153+
--ci \
154+
--max-workers ${{ steps.cpu-cores.outputs.count }} \
155+
--cacheDirectory /tmp/jest_cache
156+
env:
157+
# tell jest to use coloured output
158+
FORCE_COLOR: true
159+
160+
- name: Upload Artifact
161+
if: env.ENABLE_COVERAGE == 'true'
162+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
163+
with:
164+
name: coverage-sharedcomponents
165+
path: |
166+
packages/shared-components/coverage
167+
!packages/shared-components/coverage/lcov-report

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ storybook-static
3636

3737
/packages/shared-components/node_modules
3838
/packages/shared-components/dist
39+
/packages/shared-components/src/i18nKeys.d.ts

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config: Config = {
1717
// This is needed to be able to load dual CJS/ESM WASM packages e.g. rust crypto & matrix-wywiwyg
1818
customExportConditions: ["browser", "node"],
1919
},
20-
testMatch: ["<rootDir>/test/**/*-test.[tj]s?(x)", "<rootDir>/packages/*/src/**/*.test.[t]s?(x)"],
20+
testMatch: ["<rootDir>/test/**/*-test.[tj]s?(x)"],
2121
globalSetup: "<rootDir>/test/globalSetup.ts",
2222
setupFiles: ["jest-canvas-mock", "web-streams-polyfill/polyfill"],
2323
setupFilesAfterEnv: ["<rootDir>/test/setupTests.ts"],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"dependencies": {
8484
"@babel/runtime": "^7.12.5",
8585
"@element-hq/element-web-module-api": "1.4.1",
86+
"@element-hq/web-shared-components": "file:packages/shared-components",
8687
"@fontsource/inconsolata": "^5",
8788
"@fontsource/inter": "^5",
8889
"@formatjs/intl-segmenter": "^11.5.7",
@@ -104,7 +105,6 @@
104105
"browserslist": "^4.23.2",
105106
"classnames": "^2.2.6",
106107
"commonmark": "^0.31.0",
107-
"counterpart": "^0.18.6",
108108
"css-tree": "^3.0.0",
109109
"diff-dom": "^5.0.0",
110110
"diff-match-patch": "^1.0.5",

packages/shared-components/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
root: true,
23
plugins: ["matrix-org", "eslint-plugin-react-compiler"],
34
extends: [
45
"plugin:matrix-org/babel",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/
2+
i18n/i18nKeys.d.ts
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
sourceMaps: true,
3+
presets: [
4+
[
5+
"@babel/preset-env",
6+
{
7+
include: ["@babel/plugin-transform-class-properties"],
8+
},
9+
],
10+
["@babel/preset-typescript", { allowDeclareFields: true }],
11+
"@babel/preset-react",
12+
],
13+
plugins: [
14+
"@babel/plugin-proposal-export-default-from",
15+
"@babel/plugin-transform-numeric-separator",
16+
"@babel/plugin-transform-object-rest-spread",
17+
"@babel/plugin-transform-optional-chaining",
18+
"@babel/plugin-transform-nullish-coalescing-operator",
19+
"@babel/plugin-transform-runtime",
20+
],
21+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2025 Element Creations Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import { env } from "process";
9+
10+
import type { Config } from "jest";
11+
12+
const config: Config = {
13+
testEnvironment: "jsdom",
14+
testEnvironmentOptions: {
15+
url: "http://localhost/",
16+
},
17+
testMatch: ["<rootDir>/src/**/*.test.[tj]s?(x)"],
18+
setupFilesAfterEnv: ["<rootDir>/src/test/setupTests.ts"],
19+
moduleNameMapper: {
20+
// Support CSS module
21+
"\\.(module.css)$": "identity-obj-proxy",
22+
"\\.(css|scss|pcss)$": "<rootDir>/__mocks__/cssMock.js",
23+
"\\.(gif|png|ttf|woff2)$": "<rootDir>/__mocks__/imageMock.js",
24+
"\\.svg$": "<rootDir>/__mocks__/svg.js",
25+
"\\$webapp/i18n/languages.json": "<rootDir>/../../__mocks__/languages.json",
26+
"^react$": "<rootDir>/node_modules/react",
27+
"^react-dom$": "<rootDir>/node_modules/react-dom",
28+
"waveWorker\\.min\\.js": "<rootDir>/__mocks__/empty.js",
29+
"context-filter-polyfill": "<rootDir>/__mocks__/empty.js",
30+
"workers/(.+)Factory": "<rootDir>/__mocks__/workerFactoryMock.js",
31+
},
32+
transformIgnorePatterns: [
33+
"/node_modules/(?!(mime|matrix-js-sdk|uuid|p-retry|is-network-error|react-merge-refs)).+$",
34+
],
35+
collectCoverageFrom: [
36+
"<rootDir>/src/**/*.{js,ts,tsx}",
37+
"<rootDir>/packages/**/*.{js,ts,tsx}",
38+
// Coverage chokes on type definition files
39+
"!<rootDir>/src/**/*.d.ts",
40+
],
41+
coverageReporters: ["text-summary", "lcov"],
42+
testResultsProcessor: "@casualbot/jest-sonar-reporter",
43+
prettierPath: null,
44+
moduleDirectories: ["node_modules", "./src/test/utils"],
45+
};
46+
47+
// if we're running under GHA, enable the GHA reporter
48+
if (env["GITHUB_ACTIONS"] !== undefined) {
49+
const reporters: Config["reporters"] = [["github-actions", { silent: false }], "summary"];
50+
51+
// if we're running against the develop branch, also enable the slow test reporter
52+
if (env["GITHUB_REF"] == "refs/heads/develop") {
53+
reporters.push("<rootDir>/test/slowReporter.cjs");
54+
}
55+
config.reporters = reporters;
56+
}
57+
58+
export default config;

0 commit comments

Comments
 (0)