Replaced calls to should() function with assert#26426
Conversation
WalkthroughThis pull request migrates numerous test files from the Should.js assertion style to Node's built-in assert API. It replaces should-based assertions with assert.equal / assert.notEqual / assert.deepEqual / assert.rejects and updates imports accordingly. The test utilities module was extended: Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.40.5)ghost/core/test/e2e-api/admin/members.test.jsghost/core/test/e2e-api/members-comments/comments.test.jsghost/core/test/e2e-api/members/webhooks.test.jsThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@ghost/core/test/legacy/api/admin/update-user-last-seen.test.js`:
- Line 90: Change the bogus Date comparison using assert.notEqual to a
value-based comparison: replace the assertion that references
assert.notEqual(ownerAfter.get('last_seen'), lastSeen) with a deep/value
comparison (for example use assert.notDeepEqual(ownerAfter.get('last_seen'),
lastSeen) or compare timestamps via ownerAfter.get('last_seen').getTime() !==
lastSeen.getTime()) so the test actually verifies the last_seen timestamp
changed.
In `@ghost/core/test/utils/assertions.js`:
- Around line 49-57: The recursion guard in assertObjectMatches only checks
isPlainObject(obj[key]) and may recurse when the corresponding value is
null/primitive/array, causing Object.entries(value) to throw; update the
condition in assertObjectMatches so it only recurses when both
isPlainObject(obj[key]) and isPlainObject(value) are true, and otherwise fall
back to the existing assert.deepEqual(obj[key], value, message || `Property
mismatch for key "${key}"`); reference assertObjectMatches, isPlainObject,
obj[key], value, and assert.deepEqual to locate and change the check.
🧹 Nitpick comments (2)
ghost/core/test/legacy/api/admin/update-user-last-seen.test.js (1)
1-1: Minor: Usenode:assert/strictfor consistency with the rest of the codebase.Other test files (e.g.,
link-click-tracking-service.test.js,members.test.js, andtest/utils/assertions.js) all userequire('node:assert/strict').Suggested fix
-const assert = require('assert/strict'); +const assert = require('node:assert/strict');ghost/core/test/e2e-api/members-comments/comments.test.js (1)
480-481: Missedshould.notEqualcalls on lines 480–481.These still use
should.notEqual(...), while the analogous assertion on line 438 was already converted toassert.notEqual(...). Consider converting for consistency — these are functionally identical patterns and theshouldimport (line 4) could potentially be removed if all such calls are migrated.Proposed fix
data2.body.comments.forEach((comment) => { - should.notEqual(comment.html, 'This is a hidden comment'); - should.notEqual(comment.html, 'This is a deleted comment'); + assert.notEqual(comment.html, 'This is a hidden comment'); + assert.notEqual(comment.html, 'This is a deleted comment'); });Note: Lines 263, 266, 297, and 300 (
testCanCommentOnPostandtestCanReplyhelpers) also still useshould.notEqual. Converting all of them would allow removing theshouldimport on line 4.
This test-only change should have no user impact.
We had various calls like `should(actual).eql(expected)` and similar.
This replaces all of them with calls to `node:assert`, or wrappers
around that.
`git grep -F 'should('` returns no results after this change.
1071cbe to
76b1726
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/test/e2e-api/members/webhooks.test.js (1)
42-45: Move the length assertion before the loop for clearer failure diagnostics.If
eventsis shorter thanasserts,events[i]will beundefinedandassertObjectMatcheswill throw a confusing error before the descriptive length-check message on line 45 is reached. Swapping the order gives a meaningful message first.Suggested reorder
async function assertMemberEvents({eventType, memberId, asserts}) { const events = (await models[eventType].where('member_id', memberId).fetchAll()).toJSON(); + assert.equal(events.length, asserts.length, `Only ${asserts.length} ${eventType} should have been added.`); for (let i = 0; i < asserts.length; i++) { assertObjectMatches(events[i], asserts[i]); } - assert.equal(events.length, asserts.length, `Only ${asserts.length} ${eventType} should have been added.`); }
This test-only change should have no user impact.
We had various calls like
should(actual).eql(expected)and similar. This replaces all of them with calls tonode:assert, or wrappers around that.git grep -F 'should('returns no results after this change.