Skip to content

Add Vitest unit tests for JS parsing, formatting, and utility logic - #564

Merged
swissspidy merged 2 commits into
mainfrom
copilot/add-js-parsing-tests
May 13, 2026
Merged

Add Vitest unit tests for JS parsing, formatting, and utility logic#564
swissspidy merged 2 commits into
mainfrom
copilot/add-js-parsing-tests

Conversation

Copilot AI commented May 8, 2026

Copy link
Copy Markdown
Contributor

The TypeScript modules (utils.ts, pr-comment-formatter.ts, and the file-parsing logic in main.ts) had no automated unit tests.

Changes

  • Extract parsing logic — Moved the results-file parser out of main.ts into src/parse-results.ts (parseResultsFile(content: string): Map<string, CheckResult[]>) so it can be tested in isolation. main.ts now delegates to this function.

  • Test suite (27 tests across 3 files):

    • src/utils.test.tsdecodeHtmlEntities: named, decimal, hex, unknown entities
    • src/parse-results.test.tsparseResultsFile: empty input, no FILE: lines, errors, warnings, empty result arrays
    • src/pr-comment-formatter.test.tsPRCommentFormatter: summary counts, success/error/warning comment output, HTML entity decoding in rendered output
  • Test fixturestests/fixtures/results-with-errors.txt, results-with-warnings.txt, results-empty.txt representing real plugin-check output format.

  • Vitest setup — Added vitest dev dependency, vitest.config.ts, and "test": "vitest run" script. Excluded the config from tsc compilation and ESLint.

  • CI — New unit-tests job in test.yml runs npm test on every PR/push ahead of the integration test job.

Copilot AI linked an issue May 8, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

❌ Status: Failed

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
9 8 1

❌ Errors (8)

📁 hello.php (7 errors)
📍 Line 🔖 Check 💬 Message
0 plugin_header_no_license Missing "License" in Plugin Header. Please update your Plugin Header with a valid GPLv2 (or later) compatible license.
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
49 WordPress.WP.AlternativeFunctions.rand_mt_rand mt_rand() is discouraged. Use the far less predictable wp_rand() instead.
62 WordPress.Security.EscapeOutput.OutputNotEscaped All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'.
62 WordPress.WP.I18n.TextDomainMismatch Mismatched text domain. Expected 'hello-dolly-copy' but got 'hello-dolly'.
63 WordPress.Security.EscapeOutput.OutputNotEscaped All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$lang'.
64 WordPress.Security.EscapeOutput.OutputNotEscaped All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$chosen'.
📁 readme.txt (1 error)
📍 Line 🔖 Check 💬 Message
0 no_plugin_readme The plugin readme.txt does not exist.

⚠️ Warnings (1)

📁 hello.php (1 warning)
📍 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

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
Copilot AI requested a review from swissspidy May 8, 2026 06:42
@swissspidy
swissspidy requested a review from Copilot May 8, 2026 07:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts into src/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 test in 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.

Comment thread src/parse-results.test.ts
Comment thread .github/workflows/test.yml
@swissspidy
swissspidy marked this pull request as ready for review May 10, 2026 21:11
@swissspidy
swissspidy merged commit 4b3a37a into main May 13, 2026
7 checks passed
@swissspidy
swissspidy deleted the copilot/add-js-parsing-tests branch May 13, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for the JS part

3 participants