From 5a3909d006e2bfa6bceb8b3da9d66305eddba317 Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Sun, 10 Nov 2024 11:08:01 +0100 Subject: [PATCH] chore: cleanup wtr config, add pkg script for running w/o polyfill --- .changeset/empty-students-grow.md | 5 +++ package.json | 1 + web-test-runner.config.mjs | 52 ++++++++++--------------------- 3 files changed, 23 insertions(+), 35 deletions(-) create mode 100644 .changeset/empty-students-grow.md diff --git a/.changeset/empty-students-grow.md b/.changeset/empty-students-grow.md new file mode 100644 index 0000000000..4e20dd2321 --- /dev/null +++ b/.changeset/empty-students-grow.md @@ -0,0 +1,5 @@ +--- +'@lion/ui': patch +--- + +no registration of same class twice w/o scoped-registries polyfill diff --git a/package.json b/package.json index fedf7ccf65..e8e07a504c 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "custom-elements-manifest": "npm run custom-elements-manifest --workspaces --if-present && node ./scripts/create-api-tables.mjs", "debug": "web-test-runner --watch --config web-test-runner-chrome.config.mjs", "debug:firefox": "web-test-runner --watch --config web-test-runner-firefox.config.mjs", + "debug:no-scoped-registries-polyfill": "npm run debug -- --no-scoped-registries-polyfill", "debug:webkit": "web-test-runner --watch --config web-test-runner-webkit.config.mjs", "format": "npm run format:eslint && npm run format:prettier", "format:eslint": "eslint --ext .js,.html . --fix", diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 79b37f85a0..a37974224c 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -1,30 +1,22 @@ -import fs from 'fs'; -import { playwrightLauncher } from '@web/test-runner-playwright'; import { litSsrPlugin } from '@lit-labs/testing/web-test-runner-ssr-plugin.js'; +import { playwrightLauncher } from '@web/test-runner-playwright'; +import { optimisedGlob } from 'providence-analytics/utils.js'; -const devMode = process.argv.includes('--dev-mode'); +const config = { + shouldLoadPolyfill: !process.argv.includes('--no-scoped-registries-polyfill'), + shouldRunDevMode: process.argv.includes('--dev-mode'), +}; -const packages = fs - .readdirSync('packages') - .filter( - dir => fs.statSync(`packages/${dir}`).isDirectory() && fs.existsSync(`packages/${dir}/test`), - ) - .map(dir => ({ name: dir, path: `packages/${dir}/test` })) - .concat( - fs - .readdirSync('packages/ui/components') - .filter( - dir => - fs.statSync(`packages/ui/components/${dir}`).isDirectory() && - fs.existsSync(`packages/ui/components/${dir}/test`), - ) - .map(dir => ({ name: dir, path: `packages/ui/components/${dir}/test` })), - ); +const groups = ( + await optimisedGlob(['packages/*/test', 'packages/ui/components/**/test'], { + onlyDirectories: true, + }) +).map(dir => ({ name: dir.split('/').at(-2), files: `${dir}/**/*.test.js` })); /** * @type {import('@web/test-runner').TestRunnerConfig['testRunnerHtml']} */ -const testRunnerHtml = testRunnerImport => +const testRunnerHtmlWithPolyfill = testRunnerImport => ` @@ -35,31 +27,21 @@ const testRunnerHtml = testRunnerImport => `; export default { - nodeResolve: { exportConditions: [devMode && 'development'] }, + nodeResolve: config.shouldRunDevMode ? { exportConditions: ['development'] } : true, coverageConfig: { report: true, reportDir: 'coverage', - threshold: { - statements: 95, - functions: 95, - branches: 95, - lines: 95, - }, + threshold: { statements: 95, functions: 95, branches: 95, lines: 95 }, }, testFramework: { - config: { - timeout: '5000', - }, + config: { timeout: '5000' }, }, - testRunnerHtml, + testRunnerHtml: config.shouldLoadPolyfill ? testRunnerHtmlWithPolyfill : undefined, browsers: [ playwrightLauncher({ product: 'firefox', concurrency: 1 }), playwrightLauncher({ product: 'chromium' }), playwrightLauncher({ product: 'webkit' }), ], - groups: packages.map(pkg => ({ - name: pkg.name, - files: `${pkg.path}/**/*.test.js`, - })), + groups, plugins: [litSsrPlugin()], };