Skip to content

Converted Koenig test utils to TypeScript#28426

Merged
EvanHahn merged 1 commit into
mainfrom
convert-koenig-test-utils-to-typescript
Jun 8, 2026
Merged

Converted Koenig test utils to TypeScript#28426
EvanHahn merged 1 commit into
mainfrom
convert-koenig-test-utils-to-typescript

Conversation

@EvanHahn

@EvanHahn EvanHahn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

no ref

This test-only change should have no user impact. Koenig's test utilites now use TypeScript.

no ref

This test-only change should have no user impact. Koenig's test utilites
now use TypeScript.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR converts test utilities in the koenig module from CommonJS to ES modules with TypeScript types. Configuration files are updated to support TypeScript test files and include the @types/html-minifier package. Individual assertion helpers, HTML formatting utilities, and the call renderer are migrated to ES syntax with explicit type annotations. The visibility utility is replaced with a TypeScript version. A new index.ts consolidates all exports and manages a shared JSDOM instance for the test suite.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately summarizes the main change: converting Koenig test utilities from CommonJS/JavaScript to TypeScript with ES modules.
Description check ✅ Passed The pull request description is related to the changeset, clearly stating it is a test-only TypeScript conversion of Koenig test utilities with no user impact.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch convert-koenig-test-utils-to-typescript

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ghost/core/test/unit/server/services/koenig/test-utils/assert-prettified-includes.test.ts (1)

44-52: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Assert the throw path explicitly to prevent false-positive pass.

In Line 44-Line 52, this test succeeds if assertPrettifiedIncludes does not throw, because no assertion runs outside catch.

Suggested fix
-        try {
-            assertPrettifiedIncludes(actual, expected);
-        } catch (error) {
-            assert(error instanceof Error);
-            assert.ok(error.message.includes('Received:'));
-            assert.ok(error.message.includes('Expected:'));
-            assert.ok(error.message.includes(actual));
-            assert.ok(error.message.includes(expected));
-        }
+        assert.throws(() => {
+            assertPrettifiedIncludes(actual, expected);
+        }, (error: unknown) => {
+            assert(error instanceof Error);
+            assert.ok(error.message.includes('Received:'));
+            assert.ok(error.message.includes('Expected:'));
+            assert.ok(error.message.includes(actual));
+            assert.ok(error.message.includes(expected));
+            return true;
+        });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@ghost/core/test/unit/server/services/koenig/test-utils/assert-prettified-includes.test.ts`
around lines 44 - 52, The test currently masks a false-positive because if
assertPrettifiedIncludes(actual, expected) does not throw the catch block never
runs; change the test to explicitly assert the throw (either use
assert.throws(() => assertPrettifiedIncludes(actual, expected), Error,
/Received:/) and additional regex checks for 'Expected:' and the actual/expected
strings, or call assert.fail() immediately after assertPrettifiedIncludes to
ensure the test fails when no error is thrown). Update the test around the
assertPrettifiedIncludes invocation so the throw path is explicitly asserted
while keeping the existing message-content assertions on the caught error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@ghost/core/test/unit/server/services/koenig/test-utils/assert-prettified-includes.test.ts`:
- Around line 44-52: The test currently masks a false-positive because if
assertPrettifiedIncludes(actual, expected) does not throw the catch block never
runs; change the test to explicitly assert the throw (either use
assert.throws(() => assertPrettifiedIncludes(actual, expected), Error,
/Received:/) and additional regex checks for 'Expected:' and the actual/expected
strings, or call assert.fail() immediately after assertPrettifiedIncludes to
ensure the test fails when no error is thrown). Update the test around the
assertPrettifiedIncludes invocation so the throw path is explicitly asserted
while keeping the existing message-content assertions on the caught error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1a5a3973-10b0-4ec3-b6b6-00785922b690

📥 Commits

Reviewing files that changed from the base of the PR and between 739789f and 2e31421.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (13)
  • ghost/core/jsconfig.json
  • ghost/core/package.json
  • ghost/core/test/unit/server/services/koenig/test-utils/assert-prettified-includes.test.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/assert-prettified-includes.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/assert-prettifies-to.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/build-call-renderer.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/html.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/index.js
  • ghost/core/test/unit/server/services/koenig/test-utils/index.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/prettify-html.ts
  • ghost/core/test/unit/server/services/koenig/test-utils/visibility.js
  • ghost/core/test/unit/server/services/koenig/test-utils/visibility.ts
  • pnpm-workspace.yaml
💤 Files with no reviewable changes (2)
  • ghost/core/test/unit/server/services/koenig/test-utils/index.js
  • ghost/core/test/unit/server/services/koenig/test-utils/visibility.js

@EvanHahn EvanHahn enabled auto-merge (squash) June 8, 2026 20:55
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.76%. Comparing base (9007836) to head (2e31421).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #28426    +/-   ##
========================================
  Coverage   73.76%   73.76%            
========================================
  Files        1539     1540     +1     
  Lines      131190   131982   +792     
  Branches    15719    15780    +61     
========================================
+ Hits        96768    97354   +586     
- Misses      33456    33661   +205     
- Partials      966      967     +1     
Flag Coverage Δ
admin-tests 54.67% <ø> (ø)
e2e-tests 73.76% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EvanHahn

EvanHahn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Fixed @CodeRabbit's comment in #28427.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check PR `#28427` details and CodeRabbit comments
gh pr view 28427 --repo TryGhost/Ghost --json title,body,url,state

# List comments on PR `#28426` by coderabbitai to find what was flagged
gh api repos/TryGhost/Ghost/pulls/28426/comments --jq '.[] | select(.user.login == "coderabbitai") | {id: .id, path: .path, body: .body[:300], url: .html_url}'

Length of output: 814



@EvanHahn Thanks for the heads-up! The fix in #28427 — switching to assert.throws() to prevent the false-positive scenario — looks like a clean solution to the concern raised. Appreciate you following up on that!


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@EvanHahn EvanHahn merged commit 798d373 into main Jun 8, 2026
55 checks passed
@EvanHahn EvanHahn deleted the convert-koenig-test-utils-to-typescript branch June 8, 2026 21:09
EvanHahn added a commit that referenced this pull request Jun 9, 2026
ref #28426 (review)

This is a test-only change.

`assertPrettifiedIncludes()` had a test that ran some assertions if a
function threw, but not if it didn't. This fixes that by using
`assert.throws()`.
EvanHahn added a commit that referenced this pull request Jun 9, 2026
ref #28426 (review)

This is a test-only change.

`assertPrettifiedIncludes()` had a test that ran some assertions if a
function threw, but not if it didn't. This fixes that by using
`assert.throws()`.
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.

1 participant