Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --fail-only option to fail the test suite in CI when an it.only is left in #76

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("<div><p>1</p><p>2</p></div>");
document.body.append(parent);

Expand Down
24 changes: 24 additions & 0 deletions test/lib/fail-only.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
}
2 changes: 2 additions & 0 deletions web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -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) => `
Expand Down Expand Up @@ -39,6 +40,7 @@ let config = {
include: ['src/**/*'],
},
files: "test/*.js",
plugins: [failOnly],
};

if (process.env.USE_MOVE_BEFORE) {
Expand Down
Loading