Skip to content

Commit

Permalink
Merge pull request #77 from oddbird/wpt-build
Browse files Browse the repository at this point in the history
Add WPT-specific build.
  • Loading branch information
jerivas committed Jan 25, 2023
2 parents 5710e79 + 9359d02 commit 3e8b599
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-wpt.yml
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Build polyfill
run: |
yarn install --immutable
yarn build
yarn build:wpt
- name: Setup WPT
run: |
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions 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();
}
4 changes: 0 additions & 4 deletions 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', () => {
Expand Down
13 changes: 11 additions & 2 deletions vite.config.ts
Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 3e8b599

Please sign in to comment.