Skip to content

Commit 6cf1177

Browse files
committed
remove react-scripts and use vitejs in the example widget
Outline the vitest migration Add changesets Fix typos Fix missing dependencies Remove obsolete jest config Remove more old references to jest Use our own more simple vitest-axe extension Adjust the i18next-parser.config.js Ensure the coverage dependency is made a dependency and ensure we are not running in commonjs mode Use the correct axe import Fix vite config for the example widget and the dedup of it. Also fix the exports in the package jsons Ensure we run cleanup from @testing-library/react after each test to have a clean state Exclude the build and lib folders to prevent falsely detected tests Run check-api-report to update the testing library Ensure we don't mix act from different dependencies and just always use the one from react Fixup review items and update docs as needed Signed-off-by: MTRNord <[email protected]>
1 parent ecd8c11 commit 6cf1177

File tree

96 files changed

+2049
-8194
lines changed

Some content is hidden

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

96 files changed

+2049
-8194
lines changed

.changeset/eighty-taxis-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@matrix-widget-toolkit/testing': major
3+
---
4+
5+
Migrate to vitest for testing. We do not support jest any further

.changeset/honest-eyes-approve.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@matrix-widget-toolkit/react': patch
3+
'@matrix-widget-toolkit/api': patch
4+
'@matrix-widget-toolkit/mui': patch
5+
---
6+
7+
Migrate to vitejs and vitest

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ dist
140140
.yarn/unplugged
141141
.yarn/build-state.yml
142142
.yarn/install-state.gz
143-
.pnp.*
143+
.pnp.*
144+
145+
# Debug Helpers
146+
log.sh
147+
log.out

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This repository contains multiple [packages](./packages) that provide reusable c
1010
- [`@matrix-widget-toolkit/api`](./packages/api): A package that wraps [`matrix-widget-api`](https://github.com/matrix-org/matrix-widget-api) to provide a more convenient API.
1111
- [`@matrix-widget-toolkit/react`](./packages/react): A package that provides a Widget API integration for React apps.
1212
- [`@matrix-widget-toolkit/mui`](./packages/mui): A package that provides a matching Mui theme for Element.
13-
- [`@matrix-widget-toolkit/testing`](./packages/testing): Testing support for `@matrix-widget-toolkit/api`.
13+
- [`@matrix-widget-toolkit/testing`](./packages/testing): Vitest Testing support for `@matrix-widget-toolkit/api`.
1414
- [`@matrix-widget-toolkit/widget-server`](./containers/widget-server): A container to host a Matrix widget in a production environment.
1515
- More packages to follow…
1616

@@ -59,8 +59,10 @@ After checkout, run `yarn install` to download the required dependencies
5959
The following commands are available:
6060

6161
- `yarn dev:example`: Start the example app.
62-
- `yarn start:example`: Start the example app with a self-signed HTTPS certificate.
62+
- `yarn dev:example:https`: Start the example app with a self-signed HTTPS certificate.
6363
- `yarn build`: Build all packages and the example app.
64+
- `yarn preview`: Preview a built version of the example app. Requires `yarn build` to be run first.
65+
- `yarn preview:https`: Preview a built version of the example app with a self-signed HTTPS certificate. Requires `yarn build` to be run first.
6466
- `yarn test`: Watch all packages for changes and run tests.
6567
- `yarn tsc`: Check TypeScript types for errors in all packages.
6668
- `yarn lint`: Run eslint on all packages.

eslint.config.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import { fixupPluginRules } from '@eslint/compat';
1818
import js from '@eslint/js';
1919
import eslintConfigPrettier from 'eslint-config-prettier';
20-
import jest from 'eslint-plugin-jest';
2120
import notice from 'eslint-plugin-notice';
2221
import pluginPromise from 'eslint-plugin-promise';
2322
import react from 'eslint-plugin-react';
2423
import testingLibrary from 'eslint-plugin-testing-library';
24+
import vitest from 'eslint-plugin-vitest';
2525
import path from 'path';
2626
import ts from 'typescript-eslint';
2727
import { fileURLToPath } from 'url';
@@ -35,7 +35,6 @@ export default ts.config(
3535
'**/lib/**',
3636
'**/build/**',
3737
'**/craco.config.js',
38-
'**/jest.config.js',
3938
'**/i18next-parser.config.js',
4039
'scripts/prepack.js',
4140
'scripts/postpack.js',
@@ -55,10 +54,8 @@ export default ts.config(
5554
{
5655
plugins: {
5756
notice,
58-
jest,
5957
},
6058
rules: {
61-
...jest.configs['flat/recommended'].rules,
6259
'notice/notice': [
6360
'error',
6461
{
@@ -98,13 +95,15 @@ export default ts.config(
9895
{
9996
files: ['**/*.test.*'],
10097
plugins: {
98+
vitest,
10199
// See https://github.com/testing-library/eslint-plugin-testing-library/issues/899#issuecomment-2121272355 and
102100
// https://github.com/testing-library/eslint-plugin-testing-library/issues/924
103101
'testing-library': fixupPluginRules({
104102
rules: testingLibrary.rules,
105103
}),
106104
},
107105
rules: {
106+
...vitest.configs.recommended.rules,
108107
...testingLibrary.configs['flat/react'].rules,
109108
'react/display-name': 'off',
110109
// FIXME: Came in an update and should be fixed properly

example-widget-mui/craco.config.js

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

example-widget-mui/i18next-parser.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
module.exports = {
17+
const i18NextParserConfig = {
1818
locales: ['en', 'de'],
1919
output: 'public/locales/$LOCALE/$NAMESPACE.json',
2020
sort: true,
2121
resetDefaultValueLocale: 'en',
2222
};
23+
24+
export default i18NextParserConfig;

example-widget-mui/public/index.html renamed to example-widget-mui/index.html

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,44 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
5+
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
88
<meta
99
name="description"
1010
content="Web site created using create-react-app"
1111
/>
12-
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
12+
<link rel="apple-touch-icon" href="/logo192.png" />
1313
<!--
1414
manifest.json provides metadata used when your web app is installed on a
1515
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1616
-->
17-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18-
<!--
19-
Notice the use of %PUBLIC_URL% in the tags above.
20-
It will be replaced with the URL of the `public` folder during the build.
21-
Only files inside the `public` folder can be referenced from the HTML.
22-
23-
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24-
work correctly both with client-side routing and a non-root public URL.
25-
Learn how to configure a non-root public URL by running `npm run build`.
26-
-->
17+
<link rel="manifest" href="/manifest.json" />
2718
<title>Example Widget</title>
19+
2820
<!--#echo var="__INJECT_SCRIPT_TAG__" encoding="none"-->
21+
22+
<script nonce='<!--#echo var="cspNonce"-->'>
23+
__webpack_nonce__ = '<!--#echo var="cspNonce"-->';
24+
// Set global for compatibility reason.
25+
// globalThis ?? window is required as some things require global and others use window.
26+
// See also https://github.com/nordeck/matrix-widget-toolkit/pull/774#discussion_r1763252347
27+
global = globalThis ?? window;
28+
</script>
29+
30+
<script nonce='<!--#echo var="cspNonce"-->' type="module">
31+
// Copy environment variables to process.env for backward compatibility with CRA.
32+
window.process = window.process ?? {};
33+
window.process.env = import.meta.env;
34+
</script>
35+
36+
<style nonce='<!--#echo var="cspNonce"-->'>
37+
#root {
38+
width: 100%;
39+
}
40+
</style>
2941
</head>
42+
3043
<body>
3144
<noscript>You need to enable JavaScript to run this app.</noscript>
3245
<div id="root"></div>
@@ -40,5 +53,6 @@
4053
To begin the development, run `npm start` or `yarn start`.
4154
To create a production bundle, use `npm run build` or `yarn build`.
4255
-->
56+
<script type="module" src="/src/main.tsx"></script>
4357
</body>
4458
</html>

example-widget-mui/jest.config.js

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

example-widget-mui/package.json

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "Nordeck IT + Consulting GmbH",
66
"license": "Apache-2.0",
77
"private": true,
8+
"type": "module",
89
"dependencies": {
910
"@matrix-widget-toolkit/api": "3.4.0",
1011
"@matrix-widget-toolkit/mui": "2.0.4",
@@ -23,18 +24,19 @@
2324
"react-i18next": "^15.0.2",
2425
"react-redux": "^9.1.2",
2526
"react-router-dom": "^6.26.2",
26-
"react-scripts": "5.0.1",
2727
"react-use": "^17.5.1",
2828
"rxjs": "^7.8.1"
2929
},
3030
"scripts": {
31-
"dev": "cross-env BROWSER=none WDS_SOCKET_PORT=0 craco start",
32-
"start": "cross-env BROWSER=none WDS_SOCKET_PORT=0 HTTPS=true craco start",
31+
"dev": "vite",
32+
"dev:https": "VITE_DEV_SSL=true vite",
33+
"preview": "vite preview",
34+
"preview:https": "VITE_DEV_SSL=true vite preview",
3335
"lint": "eslint .",
3436
"tsc": "tsc",
35-
"build": "craco build",
36-
"test": "jest --watch",
37-
"depcheck": "depcheck --ignores=@types/node,@types/jest --ignore-dirs=build",
37+
"build": "tsc && vite build",
38+
"test": "echo \"Tests have to run from root project\"",
39+
"depcheck": "depcheck --ignores=@types/node,@vitest/coverage-v8 --ignore-dirs=build",
3840
"translate": "i18next src/**/*.{ts,tsx}",
3941
"check-api-report": "echo \"Nothing to report\"",
4042
"generate-api-report": "echo \"Nothing to report\""
@@ -52,20 +54,23 @@
5254
]
5355
},
5456
"devDependencies": {
55-
"@craco/craco": "^7.1.0",
5657
"@matrix-widget-toolkit/testing": "2.5.0",
58+
"@testing-library/dom": "^10.4.0",
5759
"@testing-library/jest-dom": "^6.5.0",
5860
"@testing-library/react": "^16.0.1",
59-
"@testing-library/dom": "^10.4.0",
6061
"@testing-library/user-event": "^14.5.2",
61-
"@types/jest": "^27.5.2",
62-
"@types/jest-axe": "^3.5.9",
6362
"@types/node": "^22.5.5",
6463
"@types/react": "^18.2.74",
6564
"@types/react-dom": "^18.2.24",
65+
"@vitejs/plugin-basic-ssl": "^1.1.0",
66+
"@vitejs/plugin-react-swc": "^3.7.0",
67+
"@vitest/coverage-v8": "^2.0.5",
68+
"axe-core": "^4.10.0",
69+
"happy-dom": "^15.7.3",
6670
"i18next-parser": "^9.0.2",
67-
"jest-axe": "^9.0.0",
6871
"msw": "^2.4.9",
69-
"typescript": "^5.6.2"
72+
"typescript": "^5.6.2",
73+
"vite": "^5.4.0",
74+
"vitest": "^2.0.5"
7075
}
7176
}

example-widget-mui/src/AllRoomsPage/AllRoomsPage.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import { WidgetApiMockProvider } from '@matrix-widget-toolkit/react';
1919
import { MockedWidgetApi, mockWidgetApi } from '@matrix-widget-toolkit/testing';
2020
import { render, screen, waitFor } from '@testing-library/react';
2121
import userEvent from '@testing-library/user-event';
22-
import { axe } from 'jest-axe';
22+
import axe from 'axe-core';
2323
import { EventDirection, WidgetEventCapability } from 'matrix-widget-api';
2424
import { ComponentType, PropsWithChildren } from 'react';
2525
import { MemoryRouter } from 'react-router-dom';
26+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2627
import { RoomNameEvent } from '../events';
2728
import { AllRoomsPage } from './AllRoomsPage';
2829

@@ -89,7 +90,7 @@ describe('<AllRoomsPage />', () => {
8990
).toBeEnabled();
9091
});
9192

92-
expect(await axe(container)).toHaveNoViolations();
93+
expect(await axe.run(container)).toHaveNoViolations();
9394
});
9495

9596
it('should request the capabilities', async () => {

example-widget-mui/src/App/App.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { WidgetApiImpl } from '@matrix-widget-toolkit/api';
1818
import { render, screen } from '@testing-library/react';
19+
import { expect, it } from 'vitest';
1920
import { App } from './App';
2021

2122
it('should render error message', async () => {

example-widget-mui/src/DicePage/DicePage.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import { WidgetApiMockProvider } from '@matrix-widget-toolkit/react';
1818
import { MockedWidgetApi, mockWidgetApi } from '@matrix-widget-toolkit/testing';
1919
import { render, screen } from '@testing-library/react';
2020
import userEvent from '@testing-library/user-event';
21-
import { axe } from 'jest-axe';
21+
import axe from 'axe-core';
2222
import { EventDirection, WidgetEventCapability } from 'matrix-widget-api';
2323
import { ComponentType, PropsWithChildren } from 'react';
2424
import { MemoryRouter } from 'react-router-dom';
25+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2526
import { DicePage } from './DicePage';
2627

2728
let widgetApi: MockedWidgetApi;
@@ -65,7 +66,7 @@ describe('<DicePage />', () => {
6566
screen.findByRole('heading', { name: /dice/i }),
6667
).resolves.toBeInTheDocument();
6768

68-
expect(await axe(container)).toHaveNoViolations();
69+
expect(await axe.run(container)).toHaveNoViolations();
6970
});
7071

7172
it('should request the capabilities', async () => {

example-widget-mui/src/IdentityPage/IdentityPage.test.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717
import { WidgetApiMockProvider } from '@matrix-widget-toolkit/react';
1818
import { MockedWidgetApi, mockWidgetApi } from '@matrix-widget-toolkit/testing';
1919
import { render, screen } from '@testing-library/react';
20-
import { axe } from 'jest-axe';
20+
import axe from 'axe-core';
2121
import { HttpResponse, http } from 'msw';
2222
import { setupServer } from 'msw/node';
2323
import { ComponentType, PropsWithChildren } from 'react';
2424
import { MemoryRouter } from 'react-router-dom';
25+
import {
26+
afterAll,
27+
afterEach,
28+
beforeAll,
29+
beforeEach,
30+
describe,
31+
expect,
32+
it,
33+
} from 'vitest';
2534
import { IdentityPage } from './IdentityPage';
2635

2736
let widgetApi: MockedWidgetApi;
@@ -67,7 +76,7 @@ describe('<IdentityPage />', () => {
6776
screen.findByRole('heading', { name: /Identity/i }),
6877
).resolves.toBeInTheDocument();
6978

70-
expect(await axe(container)).toHaveNoViolations();
79+
expect(await axe.run(container)).toHaveNoViolations();
7180
});
7281

7382
it('should show the user information', async () => {

0 commit comments

Comments
 (0)