stylelint-plugin-mozilla test results name the test file as undefined
Categories
(Developer Infrastructure :: Lint and Formatting, task)
Tracking
(Not tracked)
People
(Reporter: dao, Unassigned, Mentored)
References
Details
(Keywords: good-first-bug, Whiteboard: [lang=js])
Filing as a good first bug to learn workflows.
The stylelint-plugin-mozilla test suite prints its results through its own reporter, and every line names the test file as "undefined":
TEST-PASS | undefined | Selectors without :has() are valid.
The reporter maps rule name to test file while the files are enqueued, then looks the path up by rule name when a suite starts. The lookup always misses, and it can't be fixed by matching names: several test files (e.g. use-design-tokens.space.tests.mjs and use-design-tokens.color.tests.mjs) test the same rule. The top-level "test:start" event already names the running test file in data.entryFile, so the reporter should take the path from there and drop the "test:enqueue" handler and the rule-name map.
Link to the code:
https://searchfox.org/firefox-main/source/tools/lint/stylelint/stylelint-plugin-mozilla/reporters/mozilla-format.mjs#38-70
To verify the fix:
./mach npm ci --prefix tools/lint/stylelint/stylelint-plugin-mozilla
./mach npm test --prefix tools/lint/stylelint/stylelint-plugin-mozilla
Every line should name a file under the plugin's tests/ directory, and the run should still end with "INFO | Failed: 0".
Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html
Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.
Comment 1•23 days ago
|
||
Hi!
I tried the suggested fix, and it works for files like media-query-no-invalid.tests.mjs. The problem is that some rules have multiple test files. For example, use-design-tokens has files like use-design-tokens.background-color.tests.mjs, use-design-tokens.space.tests.mjs, etc., but when the tests run, data.name is just stylelint-plugin-mozilla/use-design-tokens. So even if I strip .tests.mjs, the filename still doesn’t match the rule name, and the lookup fails.
While debugging, I noticed the test:start event already has an entryFile value with the exact test file that’s running. Would it make sense to use that instead of matching the rule name back to the filename?
| Reporter | ||
Comment 2•14 days ago
|
||
Good catch, you're right: stripping ".tests.mjs" doesn't help rules with several test files. Using entryFile from the top-level "test:start" event is the better fix. It also means the reporter no longer needs the "test:enqueue" handler or the rule-name-to-path map, so please remove both, along with the comment explaining that workaround. Keep making the path relative to PROJECT_ROOT so the output stays short.
I've updated comment 0 to describe this fix, to avoid confusion for anyone else reading the bug.
| Reporter | ||
Updated•14 days ago
|
Description
•