From 38cf0faae5be7637b689139e7ccfd19fd4e009aa Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 18 Dec 2024 11:00:47 -0600 Subject: [PATCH 1/3] add --fail-only option to fail the test suite when an it.only is detected. enable this option in the CI run. --- package.json | 2 +- test/lib/fail-only.mjs | 24 ++++++++++++++++++++++++ web-test-runner.config.mjs | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/lib/fail-only.mjs diff --git a/package.json b/package.json index 6ae5edb..a0787f3 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "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", + "ci": "web-test-runner --fail-only --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", "esm": "(cat src/idiomorph.js && echo \"\nexport {Idiomorph};\") > dist/idiomorph.esm.js", diff --git a/test/lib/fail-only.mjs b/test/lib/fail-only.mjs new file mode 100644 index 0000000..647f102 --- /dev/null +++ b/test/lib/fail-only.mjs @@ -0,0 +1,24 @@ +import { promises as fs } from 'fs'; +import path from 'path'; + +export default { + name: 'fail-only', + async transform(context) { + const filePath = context.path; + const failOnlyEnabled = process.argv.includes('--fail-only'); + if (failOnlyEnabled && filePath.match(/^\/test\/[^/]+\.js$/)) { + const fileContent = await fs.readFile(`.${filePath}`, 'utf-8'); + if (/\bit\.only\b/.test(fileContent)) { + abort(`--fail-only:\nFound 'it.only' in ${filePath}. Remove it to proceed.`); + } + } + }, +}; + +function abort(message) { + const RED = '\x1b[31m'; // Red color code + const RESET = '\x1b[0m'; // Reset color code + process.stderr.write(`${RED}${message}\n${RESET}`, () => { + process.exit(1); + }); +} diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 07f9296..6e3afa2 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -1,5 +1,6 @@ import { chromeLauncher } from "@web/test-runner"; import { exec } from "child_process"; +import failOnly from "./test/lib/fail-only.mjs"; let config = { testRunnerHtml: (testFramework) => ` @@ -39,6 +40,7 @@ let config = { include: ['src/**/*'], }, files: "test/*.js", + plugins: [failOnly], }; if (process.env.USE_MOVE_BEFORE) { From 32528b3a416c988863d2657d990c42541f9ceb05 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 18 Dec 2024 11:08:48 -0600 Subject: [PATCH 2/3] remove accidentally leftover it.only from test suite. --- test/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core.js b/test/core.js index 60a97fe..c0e01f3 100644 --- a/test/core.js +++ b/test/core.js @@ -320,7 +320,7 @@ describe("Core morphing tests", function(){ document.body.removeChild(parent); }); - it.only('can prevent element addition w/ the beforeNodeAdded callback', function() { + it('can prevent element addition w/ the beforeNodeAdded callback', function() { let parent = make("

1

2

"); document.body.append(parent); From 2a2cd667ba4ef2b8a5ad4c33dd18a87b6d9359e1 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 18 Dec 2024 11:10:46 -0600 Subject: [PATCH 3/3] document --fail-only argument for CI job in TESTING.md. --- TESTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TESTING.md b/TESTING.md index 18cc99f..ec8db16 100644 --- a/TESTING.md +++ b/TESTING.md @@ -23,7 +23,7 @@ To run all tests against all browsers in headless mode, execute: ```bash 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. +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. This build will fail if there is an `it.only` left in the codebase, thanks to a custom `--fail-only` command line argument. To run all tests against Chrome with experimental `moveBefore` support added, execute: ```bash