Skip to content

Commit

Permalink
chore: cleanup wtr config, add pkg script for running w/o polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
tlouisse committed Nov 12, 2024
1 parent bf2a22d commit 5a3909d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-students-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

no registration of same class twice w/o scoped-registries polyfill
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 17 additions & 35 deletions web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -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 =>
`
<html>
<head>
Expand All @@ -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()],
};

0 comments on commit 5a3909d

Please sign in to comment.