Skip to content

Commit a676453

Browse files
authored
[test] Add font loader for pigment visual regression tests (#43789)
1 parent 735d2d0 commit a676453

File tree

6 files changed

+44
-57
lines changed

6 files changed

+44
-57
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ docs/public/static/blog/feed/*
4242
.github/styles/
4343
.nx/cache
4444
.nx/workspace-data
45+
screenshots

apps/pigment-css-vite-app/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,34 @@
99
"build": "vite build"
1010
},
1111
"dependencies": {
12-
"@mui/material-pigment-css": "workspace:^",
13-
"@mui/utils": "workspace:^",
1412
"@mui/base": "workspace:^",
1513
"@mui/icons-material": "workspace:^",
1614
"@mui/lab": "workspace:^",
1715
"@mui/material": "workspace:^",
16+
"@mui/material-pigment-css": "workspace:^",
1817
"@mui/system": "workspace:^",
18+
"@mui/utils": "workspace:^",
1919
"clsx": "^2.1.1",
2020
"playwright": "^1.47.1",
2121
"react": "^18.3.1",
2222
"react-dom": "^18.3.1",
2323
"react-error-boundary": "^4.0.13",
24-
"react-router-dom": "^6.26.2"
24+
"react-router-dom": "^6.26.2",
25+
"webfontloader": "^1.6.28"
2526
},
2627
"devDependencies": {
2728
"@babel/preset-react": "^7.24.7",
2829
"@babel/preset-typescript": "^7.24.7",
2930
"@pigment-css/vite-plugin": "0.0.22",
3031
"@types/react": "^18.3.4",
3132
"@types/react-dom": "^18.3.0",
33+
"@types/webfontloader": "^1.6.38",
3234
"@vitejs/plugin-react": "^4.3.1",
3335
"postcss": "^8.4.47",
3436
"postcss-combine-media-query": "^1.0.1",
3537
"vite": "5.4.5",
36-
"vite-plugin-pages": "^0.32.3",
37-
"vite-plugin-node-polyfills": "0.22.0"
38+
"vite-plugin-node-polyfills": "0.22.0",
39+
"vite-plugin-pages": "^0.32.3"
3840
},
3941
"nx": {
4042
"targets": {

apps/pigment-css-vite-app/src/pages/fixtures/index.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { useLocation, matchRoutes, Link } from 'react-router-dom';
3+
import webfontloader from 'webfontloader';
34
import routes from '~react-pages';
45
import IndexLayout from '../../Layout';
56

@@ -24,9 +25,31 @@ export default function Layout() {
2425
(item) => !!item.path && !item.path.includes('react-pagination'),
2526
);
2627

28+
const [fontState, setFontState] = React.useState('pending');
29+
React.useEffect(() => {
30+
webfontloader.load({
31+
google: {
32+
families: ['Roboto:300,400,500,700', 'Inter:300,400,500,600,700,800,900', 'Material+Icons'],
33+
},
34+
custom: {
35+
families: ['Font Awesome 5 Free:n9'],
36+
urls: ['https://use.fontawesome.com/releases/v5.14.0/css/all.css'],
37+
},
38+
timeout: 20000,
39+
active: () => {
40+
setFontState('active');
41+
},
42+
inactive: () => {
43+
setFontState('inactive');
44+
},
45+
});
46+
}, []);
47+
48+
const fixturePrepared = fontState === 'active';
49+
2750
return (
2851
<IndexLayout>
29-
{demo && (
52+
{demo && fixturePrepared && (
3053
<div id="root-demo">
3154
{fixturesRoutes.find((item) => item.path === demo)?.element}
3255
{demosRoutes.find((item) => item.path === demo)?.element}

apps/pigment-css-vite-app/src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default function App() {
44
return (
55
<div>
66
<p>
7-
See Material UI components in <Link to="/material-ui">action</Link>!
7+
See Material UI components in <Link to="/fixtures">action</Link>!
88
</p>
99
</div>
1010
);

apps/pigment-css-vite-app/src/pages/material-ui/index.tsx

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

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)