Add Vitest unit tests for JS parsing, formatting, and utility logic - #564
Merged
Conversation
Closed
🔍 WordPress Plugin Check Report
📊 Report
❌ Errors (8)📁 hello.php (7 errors)
📁 readme.txt (1 error)
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
72 |
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | Functions declared in the global namespace by a theme/plugin should start with the theme/plugin prefix. Found: "dolly_css". |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
…-formatter Agent-Logs-Url: https://github.com/WordPress/plugin-check-action/sessions/e19d4318-ead8-44d7-9eb6-163dfa71e2eb Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add tests for JS parsing functionality
Add Vitest unit tests for JS parsing, formatting, and utility logic
May 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Vitest unit test suite around the action’s TypeScript utility/formatting/parsing logic by extracting the results parsing into a standalone module and wiring unit tests + CI to run them.
Changes:
- Extracts plugin-check results parsing from
main.tsintosrc/parse-results.ts. - Introduces Vitest configuration and 3 new unit test files plus fixtures for results parsing.
- Adds a new GitHub Actions workflow job to run
npm testin CI.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
vitest.config.ts |
Adds Vitest config to run src/**/*.test.ts tests. |
tsconfig.json |
Excludes test files and Vitest config from TypeScript compilation. |
package.json |
Adds vitest and npm test script. |
eslint.config.mjs |
Ignores vitest.config.ts in ESLint. |
.github/workflows/test.yml |
Adds unit-tests job to execute unit tests in CI. |
src/parse-results.ts |
New standalone results-file parser used by main.ts. |
src/main.ts |
Delegates results parsing to parseResultsFile. |
src/utils.test.ts |
Adds unit tests for HTML entity decoding. |
src/parse-results.test.ts |
Adds unit tests for parsing the results file using fixtures. |
src/pr-comment-formatter.test.ts |
Adds unit tests for PR comment formatting output. |
tests/fixtures/results-with-errors.txt |
Fixture representing plugin-check output with errors/warnings. |
tests/fixtures/results-with-warnings.txt |
Fixture representing plugin-check output with warnings. |
tests/fixtures/results-empty.txt |
Fixture representing plugin-check output with no issues. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The TypeScript modules (
utils.ts,pr-comment-formatter.ts, and the file-parsing logic inmain.ts) had no automated unit tests.Changes
Extract parsing logic — Moved the results-file parser out of
main.tsintosrc/parse-results.ts(parseResultsFile(content: string): Map<string, CheckResult[]>) so it can be tested in isolation.main.tsnow delegates to this function.Test suite (27 tests across 3 files):
src/utils.test.ts—decodeHtmlEntities: named, decimal, hex, unknown entitiessrc/parse-results.test.ts—parseResultsFile: empty input, noFILE:lines, errors, warnings, empty result arrayssrc/pr-comment-formatter.test.ts—PRCommentFormatter: summary counts, success/error/warning comment output, HTML entity decoding in rendered outputTest fixtures —
tests/fixtures/results-with-errors.txt,results-with-warnings.txt,results-empty.txtrepresenting real plugin-check output format.Vitest setup — Added
vitestdev dependency,vitest.config.ts, and"test": "vitest run"script. Excluded the config fromtsccompilation and ESLint.CI — New
unit-testsjob intest.ymlrunsnpm teston every PR/push ahead of the integration test job.