From 9359d02ed9f064e93b70c8048f4aa6377a82fc32 Mon Sep 17 00:00:00 2001 From: Jonny Gerig Meyer Date: Wed, 25 Jan 2023 12:11:01 -0500 Subject: [PATCH] Add WPT-specific build. --- .github/workflows/test-wpt.yml | 4 ++-- package.json | 1 + src/index-wpt.ts | 14 ++++++++++++++ src/index.ts | 4 ---- vite.config.ts | 13 +++++++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/index-wpt.ts diff --git a/.github/workflows/test-wpt.yml b/.github/workflows/test-wpt.yml index 2cea125..2bb61fd 100644 --- a/.github/workflows/test-wpt.yml +++ b/.github/workflows/test-wpt.yml @@ -67,7 +67,7 @@ jobs: - name: Build polyfill run: | yarn install --immutable - yarn build + yarn build:wpt - name: Setup WPT run: | @@ -80,7 +80,7 @@ jobs: python3 -m http.server 9606 & cd ../wpt ./wpt manifest - ./wpt serve --inject-script=${{ github.workspace }}/dist/css-anchor-positioning.umd.cjs & + ./wpt serve --inject-script=${{ github.workspace }}/dist/css-anchor-positioning-wpt.umd.cjs & cd .. cp -r wpt-results/test-results . yarn test:wpt diff --git a/package.json b/package.json index 52c7271..e3e38c3 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "build": "run-s build:dist build:fn", "build:dist": "vite build", "build:fn": "cross-env BUILD_FN=1 vite build", + "build:wpt": "cross-env BUILD_WPT=1 vite build", "preview": "vite preview", "serve": "vite dev", "tsc": "tsc --noEmit", diff --git a/src/index-wpt.ts b/src/index-wpt.ts new file mode 100644 index 0000000..8c15971 --- /dev/null +++ b/src/index-wpt.ts @@ -0,0 +1,14 @@ +import { polyfill } from './polyfill.js'; + +// @ts-expect-error Used by the WPT test harness to delay test assertions +// and give the polyfill time to apply changes +window.CHECK_LAYOUT_DELAY_MS = 100; + +// apply polyfill +if (document.readyState !== 'complete') { + window.addEventListener('load', () => { + polyfill(); + }); +} else { + polyfill(); +} diff --git a/src/index.ts b/src/index.ts index 8c15971..575e326 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,5 @@ import { polyfill } from './polyfill.js'; -// @ts-expect-error Used by the WPT test harness to delay test assertions -// and give the polyfill time to apply changes -window.CHECK_LAYOUT_DELAY_MS = 100; - // apply polyfill if (document.readyState !== 'complete') { window.addEventListener('load', () => { diff --git a/vite.config.ts b/vite.config.ts index f015155..34b37c4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,7 +10,16 @@ export default defineConfig({ build: process.env.NETLIFY ? {} : { - lib: process.env.BUILD_FN + lib: process.env.BUILD_WPT + ? // build that adds a delay variable for WPT test-runner + { + entry: resolve(__dirname, 'src/index-wpt.ts'), + name: 'CssAnchorPositioning', + formats: ['umd'], + // the proper extensions will be added + fileName: 'css-anchor-positioning-wpt', + } + : process.env.BUILD_FN ? // build that exposes the polyfill as a fn { entry: resolve(__dirname, 'src/index-fn.ts'), @@ -45,7 +54,7 @@ export default defineConfig({ provider: 'istanbul', reporter: ['text-summary', 'html'], include: ['src/**/*.{js,ts}'], - exclude: ['src/index.ts', 'src/index-fn.ts'], + exclude: ['src/index.ts', 'src/index-fn.ts', 'src/index-wpt.ts'], skipFull: true, all: true, },