Skip to content

A platform for community discussion. Free, open, simple.

DEV: Document bin/qunit regex filters (#41916)

David Taylor9981e29915b2
diff --git a/.skills/discourse-writing-js-tests/SKILL.md b/.skills/discourse-writing-js-tests/SKILL.md
index b22f04c8873..49e73ef56d5 100644
--- a/.skills/discourse-writing-js-tests/SKILL.md
+++ b/.skills/discourse-writing-js-tests/SKILL.md
@@ -213,10 +213,16 @@ Beyond [qunit-dom](https://github.com/mainmatter/qunit-dom/blob/master/API.md)'s
bin/qunit --help # full options
bin/qunit path/to/some-test.gjs # one file
bin/qunit path/to/integration/components # a directory
-bin/qunit -f "BookmarkIcon" # filter by module/test name
+bin/qunit --filter "BookmarkIcon" # case-insensitive substring of "module: test name"
+bin/qunit --filter "/Foo|Bar/i" # slash-wrapped value is a regex; use for alternation
bin/qunit --target chat # a specific plugin
```
+`--filter` is forwarded to QUnit: a plain value matches as a case-insensitive substring,
+and a slash-wrapped value like `/foo/i` matches as a regular expression. Include the `i`
+flag for case-insensitive regex matching, and use the regex form when you need alternation
+or other patterns.
+
Requires a running Rails server (or pass `--standalone` to spin up an isolated one).
## Before committing
diff --git a/AI-AGENTS.md b/AI-AGENTS.md
index dd448063050..69109690492 100644
--- a/AI-AGENTS.md
+++ b/AI-AGENTS.md
@@ -26,8 +26,8 @@ Discourse is large with long history. Understand context before changes.
- In the frontend, typescript is typically used for platform-level code, javascript for business-logic
- Platform-level frontend code should include accurate types & tsdoc descriptions for public APIs
- Simple JSDoc/TSDoc comments can be used in other code for editor intellisense, but this is not essential
-- In core, never name plugin features or specific libraries in comments/docs — describe by mechanism
-
+- In core, never name plugin features or specific libraries in comments/docs — describe by mechanism
+
## Testing
- Use the skill at `.skills/discourse-writing-rspec-tests` when writing RSpec tests
@@ -38,6 +38,8 @@ Discourse is large with long history. Understand context before changes.
bin/qunit --help # detailed help
bin/qunit path/to/test-file.js # Run all tests in file
bin/qunit path/to/tests/directory # Run all tests in directory
+bin/qunit --filter "Some text" # Case-insensitive substring match on "module: test name"
+bin/qunit --filter "/Foo|Bar/i" # Slash-wrapped value is a regex (include the "i" flag); use for alternation
# Linting
bin/lint --fix path/to/file path/to/another/file
diff --git a/bin/qunit b/bin/qunit
index 376cf5ab03d..8c1bba68c76 100755
--- a/bin/qunit
+++ b/bin/qunit
@@ -56,9 +56,11 @@ class QunitRunner
opts.separator ""
opts.separator "Options:"
- opts.on("-f", "--filter FILTER", "Run tests matching this filter") do |filter|
- @filter = filter
- end
+ opts.on(
+ "-f",
+ "--filter FILTER",
+ "Run tests matching this filter against \"module: test name\" (case-insensitive substring, or a slash-wrapped regex like /foo/i)",
+ ) { |filter| @filter = filter }
opts.on("--dry-run", "Show what would run without executing") { @dry_run = true }
@@ -127,6 +129,7 @@ class QunitRunner
bin/qunit --standalone --target chat # Run single plugin tests
bin/qunit --standalone plugins/chat/test/javascripts/unit/lib/chat-audio-test.js
bin/qunit --standalone --filter "Acceptance: Emoji"
+ bin/qunit --standalone --filter "/DButton|DIconGridPicker/i"
NOTES
end
diff --git a/docs/developer-guides/docs/03-code-internals/04-run-test-suites.md b/docs/developer-guides/docs/03-code-internals/04-run-test-suites.md
index cb613628b62..41b88a6ff4a 100644
--- a/docs/developer-guides/docs/03-code-internals/04-run-test-suites.md
+++ b/docs/developer-guides/docs/03-code-internals/04-run-test-suites.md
@@ -20,23 +20,30 @@ In general, when working on core tests you should enable "Skip Plugins", and whe
### Core
-Navigate to the root of the Ember application (`app/assets/javascripts/discourse`) in the Discourse repository and make sure you have run `pnpm install` since you last pulled in upstream changes.
-
-From there, you can use standard Ember-CLI tooling to run the tests - check out the ["How to Run Tests" section of the Ember Guides](https://guides.emberjs.com/release/testing/#toc_how-to-run-tests). We also have [Ember Exam](https://ember-cli.github.io/ember-exam/) installed which provides some very useful randomization and parallelisation flags.
+From the root directory of Discourse, use `bin/qunit` (make sure you have run `pnpm install` since you last pulled in upstream changes). It wraps [Ember Exam](https://ember-cli.github.io/ember-exam/) for randomization and parallelisation, and by default runs against the running Rails server and existing JS assets. Run `bin/qunit --help` for the full list of options.
Here are some useful examples:
```sh
-# Run entire core test suite across 5 'headless' instances of Chrome in parallel:
-pnpm ember exam --parallel 5 --load-balance
+# Run a single test file, or every test in a directory:
+bin/qunit frontend/discourse/tests/integration/components/bookmark-test.gjs
+bin/qunit frontend/discourse/tests/integration/components
+
+# Run the entire core suite across 5 headless Chrome instances in parallel:
+bin/qunit --parallel 5
-# Run all tests which contain a certain string in their module/test name:
-pnpm ember exam --filter "Integration | Component | bookmark"
+# Run all tests whose "module: test name" contains a substring (case-insensitive):
+bin/qunit --filter "Integration | Component | bookmark"
-# Run in "server" mode, which gives you a URL to load in a browser for easier debugging:
-pnpm ember exam --filter "somefilter" --server
+# Slash-wrap the value to match with a regular expression, e.g. for alternation:
+bin/qunit --filter "/bookmark|reaction/i"
+
+# Spin up an isolated server and run in a visible browser for easier debugging:
+bin/qunit --standalone --no-headless
```
+> :information_source: `--filter` is forwarded to QUnit: a plain value matches as a case-insensitive substring, while a slash-wrapped value like `/foo/i` matches as a regular expression. Include the `i` flag for case-insensitive regex matching.
+
### Plugins
From the root directory of Discourse: