From 26d17a9c672654158995c5b1e728256a8aff229d Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Tue, 17 Dec 2024 16:01:09 -0600 Subject: [PATCH 1/3] only record coverage for the src directory, not the test/lib directory. --- web-test-runner.config.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 48e8f63..32a27bf 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -1,6 +1,9 @@ export default { nodeResolve: true, coverage: true, + coverageConfig: { + include: ['src/**/*'], + }, files: "test/*.js", testRunnerHtml: (testFramework) => ` From 990e500c6da50fb26b40563bbb2e8a78c8667998 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Tue, 17 Dec 2024 16:02:50 -0600 Subject: [PATCH 2/3] extract duplicated boilerplate to test helper file. --- test/bootstrap.js | 6 +----- test/core.js | 6 +----- test/fidelity.js | 5 +---- test/head.js | 7 ++----- test/lib/utilities.js | 7 ++++++- test/perf.js | 6 +----- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/test/bootstrap.js b/test/bootstrap.js index 3923b42..9c9c25a 100644 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -1,10 +1,6 @@ describe("Bootstrap test", function(){ + setup(); - beforeEach(function() { - clearWorkArea(); - }); - - // bootstrap test it('can morph content to content', function() { let btn1 = make('') diff --git a/test/core.js b/test/core.js index c78d750..f478c95 100644 --- a/test/core.js +++ b/test/core.js @@ -1,8 +1,5 @@ describe("Core morphing tests", function(){ - - beforeEach(function() { - clearWorkArea(); - }); + setup(); it('morphs outerHTML as content properly when argument is null', function() { @@ -460,5 +457,4 @@ describe("Core morphing tests", function(){ } }); - }) diff --git a/test/fidelity.js b/test/fidelity.js index ecb746c..5043066 100644 --- a/test/fidelity.js +++ b/test/fidelity.js @@ -1,8 +1,5 @@ describe("Tests to ensure that idiomorph merges properly", function(){ - - beforeEach(function() { - clearWorkArea(); - }); + setup(); function expectFidelity(actual, expected) { if (actual.outerHTML !== expected) { diff --git a/test/head.js b/test/head.js index 8d7f57b..628561c 100644 --- a/test/head.js +++ b/test/head.js @@ -1,8 +1,5 @@ describe("Tests to ensure that the head tag merging works correctly", function() { - - beforeEach(function () { - clearWorkArea(); - }); + setup(); it('adds a new element correctly', function () { let parser = new DOMParser(); @@ -101,4 +98,4 @@ describe("Tests to ensure that the head tag merging works correctly", function() -}); \ No newline at end of file +}); diff --git a/test/lib/utilities.js b/test/lib/utilities.js index 2535348..2c85b0c 100644 --- a/test/lib/utilities.js +++ b/test/lib/utilities.js @@ -1,4 +1,9 @@ /* Test Utilities */ +function setup() { + beforeEach(function() { + clearWorkArea(); + }); +} function make(htmlStr) { let range = document.createRange(); @@ -47,4 +52,4 @@ function print(elt) { let text = document.createTextNode( elt.outerHTML + "\n\n" ); getWorkArea().appendChild(text); return elt; -} \ No newline at end of file +} diff --git a/test/perf.js b/test/perf.js index a7893e2..5b37771 100644 --- a/test/perf.js +++ b/test/perf.js @@ -1,9 +1,5 @@ describe("Tests to compare perf with morphdom", function(){ - - beforeEach(function() { - clearWorkArea(); - }); - + setup(); it('HTML5 Elements Sample Page', function(done) { From 4862b938ee831c30d7b5438588add7e8d1a9f625 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Fri, 13 Dec 2024 15:17:56 -0600 Subject: [PATCH 3/3] get something working with testing experimental moveBefore. --- .github/workflows/ci.yml | 14 ++++++++++++++ .gitignore | 1 + TESTING.md | 6 ++++++ package.json | 1 + test/htmx-integration.js | 1 - test/lib/utilities.js | 6 +++++- web-test-runner.config.mjs | 36 ++++++++++++++++++++++++++++-------- 7 files changed, 55 insertions(+), 10 deletions(-) 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/test/htmx-integration.js b/test/htmx-integration.js index 5118e24..3e656cf 100644 --- a/test/htmx-integration.js +++ b/test/htmx-integration.js @@ -1,5 +1,4 @@ describe("Tests for the htmx integration", function() { - function makeServer(){ var server = sinon.fakeServer.create(); htmx.config.defaultSettleDelay = 0; diff --git a/test/lib/utilities.js b/test/lib/utilities.js index 2c85b0c..ebd674f 100644 --- a/test/lib/utilities.js +++ b/test/lib/utilities.js @@ -1,6 +1,10 @@ /* Test Utilities */ + function setup() { - beforeEach(function() { + beforeEach(() => { + if (window.useMoveBefore && !Element.prototype.moveBefore) { + throw new Error('Element.prototype.moveBefore is not available.'); + } clearWorkArea(); }); } diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 32a27bf..07f9296 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -1,17 +1,17 @@ -export default { - nodeResolve: true, - coverage: true, - coverageConfig: { - include: ['src/**/*'], - }, - files: "test/*.js", +import { chromeLauncher } from "@web/test-runner"; +import { exec } from "child_process"; + +let config = { testRunnerHtml: (testFramework) => ` - + @@ -32,5 +32,25 @@ export default { `, + + nodeResolve: true, + coverage: true, + coverageConfig: { + include: ['src/**/*'], + }, + 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;