Conversation
WalkthroughThis pull request establishes foundational testing infrastructure for the project. It adds Vitest as the test runner with npm scripts for testing and coverage reporting, configured via 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
| import { createFetchJsonResponse } from '../utils/mocks.js'; | ||
| import { readFixture } from '../utils/fixtures.js'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| mocks.readJsonSyncMock.mockReturnValue({ url: 'https://forum.example' }); | ||
| mocks.fetchMock.mockResolvedValue(createFetchJsonResponse(readFixture('discourse', 'categories.json'))); | ||
|
|
||
| const { default: getCategories } = await import('../../discourse/getCategories.js'); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| mocks.readJsonSyncMock.mockReturnValue({ url: 'https://forum.example' }); | ||
| mocks.fetchMock.mockResolvedValue(createFetchJsonResponse(readFixture('discourse', 'categories.json'))); | ||
|
|
||
| const { default: getCategories } = await import('../../discourse/getCategories.js'); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| mocks.fetchMock.mockResolvedValue(createFetchJsonResponse(readFixture('discourse', 'categories.json'))); | ||
|
|
||
| const { default: getCategories } = await import('../../discourse/getCategories.js'); | ||
| const categories = await getCategories(); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| import { createTelegramContext } from '../utils/mocks.js'; | ||
| import { readFixture } from '../utils/fixtures.js'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| reply: vi.fn() | ||
| }); | ||
|
|
||
| const { default: start } = await import('../../telegram/command/start.js'); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| reply: vi.fn() | ||
| }); | ||
|
|
||
| const { default: start } = await import('../../telegram/command/start.js'); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const utilsDir = path.dirname(fileURLToPath(import.meta.url)); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const utilsDir = path.dirname(fileURLToPath(import.meta.url)); | ||
| const fixturesDir = path.join(utilsDir, '..', 'fixtures'); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
| const fixturesDir = path.join(utilsDir, '..', 'fixtures'); | ||
|
|
||
| export function readFixture(...segments) { | ||
| const fixturePath = path.join(fixturesDir, ...segments); |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note test
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/utils/fixtures.js`:
- Around line 1-3: Imports are inconsistent: `fs` is imported with the node:
prefix while `path` and `fileURLToPath` are not; update the `import path from
'path'` and `import { fileURLToPath } from 'url'` statements to use the same
`node:` prefix (i.e., `node:path` and `node:url`) so all built-in modules in
this file use the `node:` scheme and remain consistent; locate these imports by
the symbols `path` and `fileURLToPath` in the top of the file and change their
module specifiers accordingly.
In `@test/utils/mocks.js`:
- Around line 7-25: The createTelegramContext helper uses a shallow spread of
overrides which will replace entire nested objects (e.g., passing { from: { id:
999 } } drops username/first_name); change it to perform a deep merge between
the default context object and overrides so partial nested overrides preserve
other properties (either by using a proven utility like lodash.merge/mergeWith
or a small recursive deepMerge helper) and update the createTelegramContext
signature to call that deep merge on the default object and overrides (keep
function name createTelegramContext and the overrides parameter), or
alternatively add a short comment/docstring above createTelegramContext
explaining the current shallow-merge behavior if you prefer not to change
implementation.
| import fs from 'node:fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Inconsistent Node.js built-in module import prefixes.
Line 1 uses node:fs, but lines 2-3 use path and url without the node: prefix. Consider using consistent prefixes for clarity.
Suggested consistency fix
import fs from 'node:fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/utils/fixtures.js` around lines 1 - 3, Imports are inconsistent: `fs` is
imported with the node: prefix while `path` and `fileURLToPath` are not; update
the `import path from 'path'` and `import { fileURLToPath } from 'url'`
statements to use the same `node:` prefix (i.e., `node:path` and `node:url`) so
all built-in modules in this file use the `node:` scheme and remain consistent;
locate these imports by the symbols `path` and `fileURLToPath` in the top of the
file and change their module specifiers accordingly.
| export function createTelegramContext(overrides = {}) { | ||
| return { | ||
| from: { | ||
| id: 1001, | ||
| username: 'smoke_user', | ||
| first_name: 'Smoke' | ||
| }, | ||
| chat: { | ||
| id: 1001, | ||
| username: 'smoke_user', | ||
| first_name: 'Smoke', | ||
| type: 'private' | ||
| }, | ||
| message: { | ||
| message_id: 42 | ||
| }, | ||
| ...overrides | ||
| }; | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Shallow merge may cause unexpected behavior when overriding nested properties.
The spread operator ...overrides only performs a shallow merge. If a test passes { from: { id: 999 } }, it will replace the entire from object, losing username and first_name. This may be intentional, but consider documenting this behavior or implementing deep merge if partial nested overrides are needed.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/utils/mocks.js` around lines 7 - 25, The createTelegramContext helper
uses a shallow spread of overrides which will replace entire nested objects
(e.g., passing { from: { id: 999 } } drops username/first_name); change it to
perform a deep merge between the default context object and overrides so partial
nested overrides preserve other properties (either by using a proven utility
like lodash.merge/mergeWith or a small recursive deepMerge helper) and update
the createTelegramContext signature to call that deep merge on the default
object and overrides (keep function name createTelegramContext and the overrides
parameter), or alternatively add a short comment/docstring above
createTelegramContext explaining the current shallow-merge behavior if you
prefer not to change implementation.
Summary
Validation
Closes #59