Skip to content

test: Migrate Analytics spec to REST; add TS spec runner and REST helpers - #10483

Open
dblythy wants to merge 9 commits into
parse-community:alphafrom
dblythy:chore/spec-ts-register
Open

test: Migrate Analytics spec to REST; add TS spec runner and REST helpers#10483
dblythy wants to merge 9 commits into
parse-community:alphafrom
dblythy:chore/spec-ts-register

Conversation

@dblythy

@dblythy dblythy commented May 29, 2026

Copy link
Copy Markdown
Member

Towards #8787.

First slice of the REST-first spec migration:

  • TS spec runner — adds a narrow @babel/register hook (spec/support/tsRegister.js) loaded by Jasmine before helper.js so .ts specs/helpers run at require time. Glob widened to discover .ts specs. Existing .js specs are unaffected — the hook only intercepts .ts under spec/.
  • REST test helpersspec/helpers/*.ts is a small typed fetch wrapper plus an object CRUD/query client and Parse-header builders. No Parse JS SDK, no parse-server internals — true black-box REST.
  • Analytics pilot migrationspec/Analytics.spec.jsspec/server/analytics.spec.ts. No SDK import, no done(), async/await throughout.
  • Planspec/spec_migration.md describes the per-file checklist and phasing used by the upcoming PRs.

Next: GeoPoint migration in a follow-up PR using the same helpers.

Summary by CodeRabbit

  • New Features

    • Added TypeScript support for Jasmine specifications and helpers.
    • Added reusable REST API test utilities for requests, authentication, CRUD operations, queries, analytics, and error assertions.
    • Added centralized local test configuration and TypeScript type declarations.
  • Tests

    • Added server-side analytics coverage.
    • Expanded Jasmine discovery to include JavaScript and TypeScript specs.
    • Removed the obsolete analytics test suite.
  • Chores

    • Added Babel registration tooling for TypeScript tests.
    • Updated local migration tracking exclusions.

Adds a narrow @babel/register hook (spec/support/tsRegister.js) loaded by Jasmine before helper.js so .ts spec/helper files are transpiled at require time. spec_files glob widened to discover .ts specs. Existing .js specs are unaffected — the hook only intercepts .ts under spec/.
@parse-github-assistant

parse-github-assistant Bot commented May 29, 2026

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Babel-based TypeScript support to Jasmine, introduces typed REST, client, analytics, configuration, error, and global helpers, and adds TypeScript analytics controller tests. Lockfiles record @babel/register and its transitive packages.

Changes

TypeScript test infrastructure

Layer / File(s) Summary
Babel dependency and lockfile metadata
package.json, package-lock.json
Adds @babel/register 7.27.1 and records its direct and transitive lockfile entries.
Jasmine TypeScript execution
spec/support/jasmine.json, spec/support/tsRegister.js
Jasmine discovers .ts specs and loads a scoped Babel registration helper before existing helpers.
REST request foundation
spec/helpers/config.ts, spec/helpers/headers.ts, spec/helpers/request.ts, spec/helpers/errors.ts, spec/helpers/globals.d.ts
Adds test-server configuration, authentication headers, fetch-based REST requests, Parse error assertions, error codes, and ambient Jasmine declarations.
Client convenience helpers
spec/helpers/client.ts
Adds typed create, batch create, get, update, find, and count operations using REST requests.
Analytics helpers and coverage
spec/helpers/analytics.ts, spec/server/analytics.spec.ts
Adds REST analytics helpers and TypeScript tests for event and app-opened adapter calls.
Local spec tracking ignore rule
.gitignore
Ignores spec/spec_migration.md.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: mtrezza

Sequence Diagram(s)

sequenceDiagram
  participant AnalyticsSpec
  participant analyticsHelper
  participant restRequest
  participant ParseServer
  participant analyticsAdapter
  AnalyticsSpec->>analyticsHelper: Call track or appOpened
  analyticsHelper->>restRequest: POST analytics event
  restRequest->>ParseServer: Send event request
  ParseServer->>analyticsAdapter: Invoke adapter method
  analyticsAdapter-->>ParseServer: Return adapter result
  ParseServer-->>restRequest: Return response
Loading

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Engage In Review Feedback ❌ Error The flagged client helpers still cast res.data directly at lines 38/65/81, so the missing-body review feedback wasn’t implemented or countered. Add body validation for create/get/update before returning typed results, then respond in the review thread or get the reviewer to retract the comment.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the required test: prefix and accurately summarizes the REST spec migration and TS helper additions.
Description check ✅ Passed The description covers the issue, approach, and migration plan, though it does not use the template headings or task checklist explicitly.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.
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.
Security Check ✅ Passed No security issues found: the Babel hook is spec-only, helpers stay under spec/, and npm audit reported no vulns in touched packages.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

dblythy added 2 commits May 29, 2026 23:15
Introduces spec/helpers/*.ts — a typed REST client over fetch (request, client, headers, config, errors, globals) so specs can talk to Parse Server through its public HTTP API without going through the Parse JS SDK. Also lands spec/spec_migration.md, the plan that drives the upcoming REST-first migration of the spec suite (towards parse-community#8787).
Replaces spec/Analytics.spec.js (Parse SDK + done() callbacks) with spec/server/analytics.spec.ts (REST client + async/await), plus spec/helpers/analytics.ts. No SDK import, no done(), no setTimeout. First spec to land under the new REST-first layout.
@dblythy dblythy changed the title chore: Allow TypeScript spec files via @babel/register test: Migrate Analytics spec to REST; add TS spec runner and REST helpers May 29, 2026
…sn't break them

CI runs Node 24, which natively strips TypeScript and loads .ts as ESM, bypassing the @babel/register CJS hook. ESM needs explicit extensions, so extensionless relative imports failed. Force Jasmine's require loader (engages the hook on Node 20), add explicit .ts extensions, and mark type-only imports with 'import type' so the suite loads identically on Node 20/22/24.
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.66%. Comparing base (cce91e5) to head (84a38a6).
⚠️ Report is 52 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha   #10483   +/-   ##
=======================================
  Coverage   92.66%   92.66%           
=======================================
  Files         193      193           
  Lines       16981    16981           
  Branches      248      248           
=======================================
  Hits        15736    15736           
  Misses       1224     1224           
  Partials       21       21           

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
spec/helpers/request.ts (2)

96-97: 💤 Low value

Unsafe type assertion for error body.

Line 97 assigns e?.data ?? e to body: ParseErrorBody without runtime validation. If the caught error is not a ParseRequestError or lacks the expected shape, accessing body.code or body.error may fail. Since this is a test helper, the test will fail regardless, but a clearer error message would improve debugging.

♻️ Add a type guard for clarity
  } catch (e: any) {
-    const body: ParseErrorBody = e && e.data ? e.data : e;
+    const raw = e?.data ?? e;
+    const body: ParseErrorBody = (raw && typeof raw === 'object' && 'code' in raw && 'error' in raw)
+      ? raw
+      : { code: 0, error: String(raw) };
    if (code !== undefined) {
🤖 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 `@spec/helpers/request.ts` around lines 96 - 97, The catch block in the helper
assigns e?.data ?? e to a ParseErrorBody without validation; add a runtime type
guard that verifies the caught value is an object and that either e.data exists
and has expected keys (e.g., 'code' or 'error') or that e itself has those keys
before treating it as ParseErrorBody in the catch of the request helper; if the
shape doesn't match, produce a clear error/throw that includes JSON.stringify(e)
so tests fail with a helpful message. Locate the catch handling in
spec/helpers/request.ts (the catch around the ParseRequestError handling) and
replace the unsafe assertion with a guard that narrows to ParseErrorBody or
logs/throws a descriptive error when the shape is unexpected.

78-78: ⚡ Quick win

Type assertion may not match actual error response shape.

Line 78 casts data to ParseErrorBody | undefined without validating the shape. If the server returns a non-2xx response with plain text, HTML, or a malformed error body, error.data will not actually conform to ParseErrorBody, causing tests that access error.data.code or error.data.error to fail with undefined property errors rather than clear assertion failures.

🛡️ Add runtime validation or narrow the cast
-    error.data = data as ParseErrorBody | undefined;
+    error.data = (data && typeof data === 'object' && 'code' in data && 'error' in data)
+      ? data as ParseErrorBody
+      : undefined;
🤖 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 `@spec/helpers/request.ts` at line 78, The test helper currently casts response
bodies to ParseErrorBody without validation (error.data = data as ParseErrorBody
| undefined), which can break when the server returns text/HTML or malformed
JSON; add a runtime type guard (e.g., isParseErrorBody) and only assign
error.data when the guard passes, otherwise set error.data = undefined or a safe
fallback (or attempt safe JSON parsing first), referencing the existing symbol
ParseErrorBody and the local error variable so callers accessing error.data.code
or error.data.error won’t hit undefined property errors.
🤖 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.

Inline comments:
In `@spec/helpers/client.ts`:
- Line 114: The current return casts and accesses (res.data as { count: number
}).count which will throw if res.data is undefined; update the code in the
function that uses res to first check that res.data exists and that
res.data.count is a number, then return it, otherwise throw a clear error
(include the actual response payload by serializing res.data) so tests fail with
a descriptive message; reference the same res variable and the count property
when making the check and error.
- Line 99: The return expression currently does an unchecked cast: "return
(res.data as { results: T[] }).results;" which will throw if res.data is
undefined; update the handler in spec/helpers/client.ts to guard res.data (e.g.,
check res.data !== undefined) and either throw a clear Error with context
(include res.status or the raw response) or return a safe fallback like an empty
array; locate and modify the function containing that return and the call site
that relies on restRequest (see the current return line and the restRequest
behavior around lines 60-63) so the code uses res.data?.results or an explicit
null check and provides a descriptive error/fallback instead of letting a
TypeError bubble up.

In `@spec/server/analytics.spec.ts`:
- Line 23: Update the test description string in the it(...) call inside
analytics.spec.ts: change "should track a app opened event" to "should track an
app opened event" so the grammar is correct; locate the it(...) invocation in
the spec where the test name is defined and edit the string accordingly.

---

Nitpick comments:
In `@spec/helpers/request.ts`:
- Around line 96-97: The catch block in the helper assigns e?.data ?? e to a
ParseErrorBody without validation; add a runtime type guard that verifies the
caught value is an object and that either e.data exists and has expected keys
(e.g., 'code' or 'error') or that e itself has those keys before treating it as
ParseErrorBody in the catch of the request helper; if the shape doesn't match,
produce a clear error/throw that includes JSON.stringify(e) so tests fail with a
helpful message. Locate the catch handling in spec/helpers/request.ts (the catch
around the ParseRequestError handling) and replace the unsafe assertion with a
guard that narrows to ParseErrorBody or logs/throws a descriptive error when the
shape is unexpected.
- Line 78: The test helper currently casts response bodies to ParseErrorBody
without validation (error.data = data as ParseErrorBody | undefined), which can
break when the server returns text/HTML or malformed JSON; add a runtime type
guard (e.g., isParseErrorBody) and only assign error.data when the guard passes,
otherwise set error.data = undefined or a safe fallback (or attempt safe JSON
parsing first), referencing the existing symbol ParseErrorBody and the local
error variable so callers accessing error.data.code or error.data.error won’t
hit undefined property errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1bf93649-5af9-4f45-b194-baa4c599d15e

📥 Commits

Reviewing files that changed from the base of the PR and between f1c14aa and 748d5d1.

📒 Files selected for processing (11)
  • spec/Analytics.spec.js
  • spec/helpers/analytics.ts
  • spec/helpers/client.ts
  • spec/helpers/config.ts
  • spec/helpers/errors.ts
  • spec/helpers/globals.d.ts
  • spec/helpers/headers.ts
  • spec/helpers/request.ts
  • spec/server/analytics.spec.ts
  • spec/spec_migration.md
  • spec/support/jasmine.json
💤 Files with no reviewable changes (1)
  • spec/Analytics.spec.js
✅ Files skipped from review due to trivial changes (6)
  • spec/helpers/errors.ts
  • spec/helpers/config.ts
  • spec/helpers/globals.d.ts
  • spec/helpers/analytics.ts
  • spec/support/jasmine.json
  • spec/spec_migration.md

Comment thread spec/helpers/client.ts Outdated
Comment thread spec/helpers/client.ts Outdated
Comment thread spec/server/analytics.spec.ts Outdated
Guard undefined response data in find/count helpers and fix grammar in
the analytics spec description.
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 29, 2026
Use a dedicated maintenance-key value in buildHeaders, assert the Parse-error
shape in expectParseError, drop the redundant local reconfigureServer decl
(it lives in globals.d.ts), and fix the REST-client description in the plan.
Internal-server-error bodies use { code, message } rather than { code, error },
so a numeric code is the reliable signal that a rejection is a Parse error.
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 29, 2026
@dblythy

dblythy commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@spec/helpers/client.ts`:
- Line 38: Update the helper methods returning CreateResult or the other typed
results around the affected return statements to validate res.data before
casting or returning it. When the response body is missing, throw a descriptive
helper-level error; preserve the existing typed return behavior for present
response data across all three methods.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 625c51a1-91bf-4c86-8177-3531d5ee1908

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9d53a and 84a38a6.

📒 Files selected for processing (14)
  • .gitignore
  • package-lock.json
  • package.json
  • spec/Analytics.spec.js
  • spec/helpers/analytics.ts
  • spec/helpers/client.ts
  • spec/helpers/config.ts
  • spec/helpers/errors.ts
  • spec/helpers/globals.d.ts
  • spec/helpers/headers.ts
  • spec/helpers/request.ts
  • spec/server/analytics.spec.ts
  • spec/support/jasmine.json
  • spec/support/tsRegister.js
💤 Files with no reviewable changes (1)
  • spec/Analytics.spec.js

Comment thread spec/helpers/client.ts
body: data,
auth,
});
return res.data as CreateResult;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject missing response bodies before returning typed results.

Lines 38, 65, and 81 cast undefined into required result types, even though restRequest() explicitly permits empty/non-JSON success bodies. Validate res.data and throw a descriptive helper-level error instead of letting an invalid value escape to downstream specs.

Also applies to: 65-65, 81-81

🤖 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 `@spec/helpers/client.ts` at line 38, Update the helper methods returning
CreateResult or the other typed results around the affected return statements to
validate res.data before casting or returning it. When the response body is
missing, throw a descriptive helper-level error; preserve the existing typed
return behavior for present response data across all three methods.

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