Skip to content

Commit 005d360

Browse files
authored
experiment: enable using base styles in dev pages and visual tests (#9164)
1 parent a4481ff commit 005d360

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

dev/common-base.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import '@vaadin/component-base/src/style-props.js';
2+
import { css } from 'lit';
3+
import { addGlobalThemeStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js';
4+
5+
addGlobalThemeStyles(
6+
'dev-common',
7+
css`
8+
body {
9+
font-family: system-ui, sans-serif;
10+
line-height: 1.25;
11+
color: var(--_vaadin-color);
12+
background: var(--_vaadin-background);
13+
margin: 2rem;
14+
}
15+
16+
h1,
17+
h2,
18+
h3,
19+
h4,
20+
h5,
21+
h6 {
22+
color: var(--_vaadin-color-strong);
23+
font-weight: 600;
24+
font-size: calc(18 / 16 * 1rem);
25+
line-height: calc(20 / 16 * 1rem);
26+
margin: 2em 0 1.25em;
27+
text-box: cap alphabetic;
28+
}
29+
`,
30+
);

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
"prepare": "husky",
2020
"serve:dist": "web-dev-server --app-index dist/index.html --open",
2121
"start": "web-dev-server --node-resolve --open /dev",
22+
"start:base": "web-dev-server --node-resolve --open /dev --base",
2223
"check-releases": "node ./scripts/check-releases.js && web-dev-server --node-resolve --open /scripts/check-releases.html",
2324
"test": "node scripts/generateLitTests.js && web-test-runner",
25+
"test:base": "yarn test --config web-test-runner-base.config.js",
2426
"test:firefox": "yarn test --config web-test-runner-firefox.config.js",
2527
"test:it": "yarn test --config web-test-runner-it.config.js",
2628
"test:lumo": "yarn test --config web-test-runner-lumo.config.js",
2729
"test:local:lumo": "yarn test --config web-test-runner-lumo.config.js --local",
2830
"test:material": "yarn test --config web-test-runner-material.config.js",
2931
"test:snapshots": "yarn test --config web-test-runner-snapshots.config.js",
3032
"test:webkit": "yarn test --config web-test-runner-webkit.config.js",
33+
"update:base": "TEST_ENV=update yarn test --config web-test-runner-base.config.js",
3134
"update:local:lumo": "TEST_ENV=update yarn test --config web-test-runner-lumo.config.js --local",
3235
"update:lumo": "TEST_ENV=update yarn test --config web-test-runner-lumo.config.js",
3336
"update:material": "TEST_ENV=update yarn test --config web-test-runner-material.config.js",

web-dev-server.config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { esbuildPlugin } from '@web/dev-server-esbuild';
33
import fs from 'node:fs';
44
import path from 'node:path';
55

6+
const hasBaseParam = process.argv.includes('--base');
7+
68
/** @return {import('@web/test-runner').TestRunnerPlugin} */
79
function generatedLitTestsPlugin() {
810
return {
@@ -26,6 +28,23 @@ function generatedLitTestsPlugin() {
2628
};
2729
}
2830

31+
/** @return {import('@web/test-runner').TestRunnerPlugin} */
32+
export function enforceBaseStylesPlugin() {
33+
return {
34+
name: 'enforce-base-styles',
35+
transform(context) {
36+
if (context.response.is('html')) {
37+
return { body: context.body.replace('./common.js', './common-base.js') };
38+
}
39+
},
40+
transformImport({ source }) {
41+
source = source.replace('/theme/lumo/', '/src/');
42+
source = source.replace(/(.+)-core-styles\.js/u, '$1-base-styles.js');
43+
return source;
44+
},
45+
};
46+
}
47+
2948
const preventFouc = `
3049
<style>
3150
body:not(.resolved) {
@@ -73,7 +92,9 @@ export default {
7392
}
7493
},
7594
},
95+
// When passing --base flag to `yarn start` command, load base styles and not Lumo
96+
hasBaseParam && enforceBaseStylesPlugin(),
7697
esbuildPlugin({ ts: true }),
7798
generatedLitTestsPlugin(),
78-
],
99+
].filter(Boolean),
79100
};

wtr-utils.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import minimist from 'minimist';
99
import { execSync } from 'node:child_process';
1010
import fs from 'node:fs';
1111
import path from 'node:path';
12+
import { enforceBaseStylesPlugin } from './web-dev-server.config.js';
1213

1314
dotenv.config();
1415

@@ -98,6 +99,15 @@ const getAllVisualPackages = () => {
9899
.filter((dir) => fs.statSync(`packages/${dir}`).isDirectory() && fs.existsSync(`packages/${dir}/test/visual`));
99100
};
100101

102+
/**
103+
* Get all available packages with visual tests for base styles.
104+
*/
105+
const getAllBasePackages = () => {
106+
return fs
107+
.readdirSync('packages')
108+
.filter((dir) => fs.statSync(`packages/${dir}`).isDirectory() && fs.existsSync(`packages/${dir}/test/visual/base`));
109+
};
110+
101111
/**
102112
* Get packages for running tests.
103113
*/
@@ -163,7 +173,9 @@ const getUnitTestGroups = (packages) => {
163173
const getVisualTestGroups = (packages, theme) => {
164174
return packages
165175
.filter((pkg) => {
166-
return !pkg.includes(theme === 'lumo' ? 'material' : 'lumo');
176+
return theme === 'base'
177+
? !pkg.includes('lumo') && !pkg.includes('material')
178+
: !pkg.includes(theme === 'lumo' ? 'material' : 'lumo');
167179
})
168180
.map((pkg) => {
169181
return {
@@ -218,7 +230,7 @@ const getScreenshotFileName = ({ name, testFile }, type, diff) => {
218230
folder = 'icons/test/visual/screenshots';
219231
} else {
220232
const match = testFile.match(/\/packages\/(.+)\.test\.(js|ts)/u);
221-
folder = match[1].replace(/(lumo|material)/u, '$1/screenshots');
233+
folder = match[1].replace(/(base|lumo|material)/u, '$1/screenshots');
222234
}
223235
return path.join(folder, type, diff ? `${name}-diff` : name);
224236
};
@@ -263,7 +275,7 @@ const createUnitTestsConfig = (config) => {
263275
};
264276

265277
const createVisualTestsConfig = (theme, browserVersion) => {
266-
const visualPackages = getAllVisualPackages();
278+
const visualPackages = theme === 'base' ? getAllBasePackages() : getAllVisualPackages();
267279
const packages = getTestPackages(visualPackages);
268280
const groups = getVisualTestGroups(packages, theme);
269281

@@ -321,7 +333,8 @@ const createVisualTestsConfig = (theme, browserVersion) => {
321333
failureThresholdType: 'percent',
322334
update: process.env.TEST_ENV === 'update',
323335
}),
324-
],
336+
theme === 'base' && enforceBaseStylesPlugin(),
337+
].filter(Boolean),
325338
groups,
326339
testRunnerHtml: getTestRunnerHtml(theme),
327340
filterBrowserLogs,

0 commit comments

Comments
 (0)