diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c5f53f..a6faa90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,3 +19,17 @@ jobs: - name: Run tests run: npm run ci + test-move-before: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + cache: 'npm' + - name: Install dependencies + run: npm install + - name: Run tests + run: npm run test-move-before + diff --git a/.gitignore b/.gitignore index 54c6c41..debe6a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules/ /coverage +/test/chrome-profile .idea diff --git a/TESTING.md b/TESTING.md index b6d2b00..18cc99f 100644 --- a/TESTING.md +++ b/TESTING.md @@ -25,6 +25,12 @@ npm run ci ``` This will run the tests using Playwright’s headless browser setup across Chrome, Firefox, and WebKit (Safari-adjacent). This is ultimately what gets run in Github Actions to verify PRs. +To run all tests against Chrome with experimental `moveBefore` support added, execute: +```bash +npm run test-move-before +``` +This will start headless Chrome in a new profile with the `atomic-move` experimental flag set. This runs in a separate job in CI. + ## Running Individual Tests ### Headless Mode diff --git a/package.json b/package.json index 5b4f9d8..6ae5edb 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "scripts": { "test": "web-test-runner", "debug": "web-test-runner --manual --open", + "test-move-before": "USE_MOVE_BEFORE=1 web-test-runner", "ci": "web-test-runner --playwright --browsers chromium firefox webkit", "amd": "(echo \"define(() => {\n\" && cat src/idiomorph.js && echo \"\nreturn Idiomorph});\") > dist/idiomorph.amd.js", "cjs": "(cat src/idiomorph.js && echo \"\nmodule.exports = Idiomorph;\") > dist/idiomorph.cjs.js", diff --git a/src/idiomorph.js b/src/idiomorph.js index 94abbdb..54c36bb 100644 --- a/src/idiomorph.js +++ b/src/idiomorph.js @@ -1101,9 +1101,9 @@ var Idiomorph = (function () { // @ts-ignore - use proposed moveBefore feature if (ctx.pantry.moveBefore) { // @ts-ignore - use proposed moveBefore feature - ctx.pantry.moveBefore(node) + ctx.pantry.moveBefore(node); } else { - ctx.pantry.appendChild(node); + ctx.pantry.insertBefore(node, null); } } diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 48e8f63..89dd5d3 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -1,7 +1,7 @@ -export default { - nodeResolve: true, - coverage: true, - files: "test/*.js", +import { chromeLauncher } from "@web/test-runner"; +import { exec } from "child_process"; + +let config = { testRunnerHtml: (testFramework) => ` @@ -29,5 +29,22 @@ export default { `, + + nodeResolve: true, + coverage: true, + files: "test/*.js", }; +if (process.env.USE_MOVE_BEFORE) { + // configure chrome to use a custom profile directory we control + config.browsers = [ + chromeLauncher({ launchOptions: { args: ['--user-data-dir=test/chrome-profile'] } }) + ] + exec([ + 'rm -rf test/chrome-profile', // clear profile out from last run + 'mkdir -p test/chrome-profile', // create from scratch + `echo '{"browser":{"enabled_labs_experiments":["atomic-move@1"]}}' > test/chrome-profile/Local\\ State`, // enable experiment + ].join(" && ")); +} + +export default config;