Skip to content

refactor: port remaining karma tests#7489

Merged
jasonsaayman merged 40 commits intov1.xfrom
refactor/port-karma-tests
Mar 12, 2026
Merged

refactor: port remaining karma tests#7489
jasonsaayman merged 40 commits intov1.xfrom
refactor/port-karma-tests

Conversation

@jasonsaayman
Copy link
Copy Markdown
Member

@jasonsaayman jasonsaayman commented Mar 8, 2026


Summary by cubic

Ports remaining Karma tests to vitest with playwright headless (Chromium/Firefox/WebKit), adds ESM (vitest) and CJS (mocha@9) smoke suites to validate dist exports and ESM/CJS parity, and stabilizes CI on Node 24. No runtime changes.

Description

  • Summary of changes
    • Added browser-headless project in vitest.config.js and test:vitest:browser:headless script; ported Karma specs to tests/browser/**/*.browser.test.js; removed legacy smoke.browser.test.js and unused enhanceError.spec.js.
    • Expanded unit tests across adapters/core/helpers/utils/static API; fixed port collisions with per‑suite fixed ports; removed shared LOCAL_SERVER_URL.
    • Added ESM smoke suite at tests/smoke/esm (vitest) and CJS smoke suite at tests/smoke/cjs (mocha@9) to verify dist exports and ESM/CJS behavior parity.
    • CI: pin Node 24.x, install playwright with system deps, run vitest unit + browser headless; refined steps/commands for stability.
    • Housekeeping: ignore docs/ in .gitignore.
  • Reasoning
    • Faster, less flaky cross‑browser tests with vitest + playwright.
    • Enforce dist export correctness and ESM/CJS parity; reduce CI variance with dedicated ports and a single Node target.
  • Additional context
    • Guards for Node ≤16 where features like AbortController/fetch are missing.

Docs

  • Test commands: npm run test:vitest:unit, npm run test:vitest:browser, npm run test:vitest:browser:headless.
  • Smoke tests:
    • ESM: cd tests/smoke/esm && npm i && npm run test:smoke:esm:vitest
    • CJS: cd tests/smoke/cjs && npm i && npm run test:smoke:cjs:mocha
  • .gitignore now ignores docs/.

Testing

  • Added comprehensive browser tests (requests, headers, interceptors, XSRF, progress, defaults, transforms, FormData, auth, cancel).
  • Expanded unit coverage for adapters (fetch/http), core, helpers, utils, and static API; stabilized with per‑suite fixed ports; added Node ≤16 skip guards and fetch gating.
  • Added ESM/CJS smoke suites to validate dist exports and module format parity.

Written for commit 91937d7. Summary will update on new commits.

@jasonsaayman jasonsaayman requested a review from Copilot March 8, 2026 14:28
@jasonsaayman jasonsaayman self-assigned this Mar 8, 2026
@jasonsaayman jasonsaayman added priority::medium A medium priority commit::refactor The PR is related to refactoring labels Mar 8, 2026
@jasonsaayman jasonsaayman changed the title Refactor/port karma tests refactor: port remaining karma tests Mar 8, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

5 issues found across 53 files

Confidence score: 4/5

  • This PR is likely safe to merge, with issues concentrated in tests rather than production code and severities staying in the low range (3–4/10).
  • The most important gap is in tests/unit/utils/endsWith.test.js: it appears to duplicate kindOf coverage, leaving utils.endsWith behavior unverified and reducing confidence against regressions.
  • Several test assertions/mocks could mask real failures (negative throw usage in tests/unit/helpers/validator.test.js, ignored headers in tests/browser/transform.browser.test.js, and baseURL composition not actually exercised in tests/unit/adapters/fetch.test.js).
  • Pay close attention to tests/unit/utils/endsWith.test.js, tests/unit/helpers/validator.test.js, tests/browser/transform.browser.test.js, tests/unit/adapters/fetch.test.js, tests/unit/utils/toArray.test.js - tighten test intent and assertions so coverage matches the behaviors being validated.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/unit/helpers/validator.test.js">

<violation number="1" location="tests/unit/helpers/validator.test.js:34">
P2: Use `.not.toThrow()` here; passing a specific `Error` to a negative throw assertion can let other thrown errors slip through and falsely pass the test.</violation>
</file>

<file name="tests/unit/utils/endsWith.test.js">

<violation number="1" location="tests/unit/utils/endsWith.test.js:4">
P2: `endsWith.test.js` duplicates `kindOf` tests, so it adds redundant coverage and leaves `utils.endsWith` untested.</violation>
</file>

<file name="tests/unit/utils/toArray.test.js">

<violation number="1" location="tests/unit/utils/toArray.test.js:6">
P3: Test names reference `kindOf`/object tags, but this file tests `toArray`; rename the suite/case to reflect actual behavior.</violation>
</file>

<file name="tests/browser/transform.browser.test.js">

<violation number="1" location="tests/browser/transform.browser.test.js:257">
P2: `respondWith` is called with `headers`, but the mock only consumes `responseHeaders`, so this header block is ignored.</violation>
</file>

<file name="tests/unit/adapters/fetch.test.js">

<violation number="1" location="tests/unit/adapters/fetch.test.js:466">
P2: This test no longer verifies baseURL/url combination because it uses an absolute request URL. Use a client whose `baseURL` points to the started server and request with a relative path.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

8 issues found across 37 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/cjs/tests/files.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/files.smoke.test.js:3">
P1: `expect` is imported from Mocha but used with Jest/Vitest matchers (`toBe`, `toEqual`, `toContain`), which will break these smoke tests at runtime.</violation>
</file>

<file name="tests/smoke/cjs/tests/http2.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/http2.smoke.test.js:2">
P2: `expect` is being imported from `mocha`, but Mocha doesn’t export an `expect` helper. These assertions will throw at runtime. Import `expect` from an assertion library (e.g., `chai`) instead.</violation>
</file>

<file name="tests/smoke/cjs/tests/instance.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/instance.smoke.test.js:4">
P2: `expect` isn’t exported by Mocha, so these tests will crash at runtime. Import `expect` from the assertion library (e.g., chai) instead.</violation>
</file>

<file name="tests/smoke/cjs/tests/timeout.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/timeout.smoke.test.js:4">
P2: `mocha` doesn’t export an `expect` assertion helper. This import leaves `expect` undefined, so the test will throw when it reaches the first `expect(...)` call. Import an assertion library (e.g., `expect` or `chai`) separately and only get `describe/it` from Mocha.</violation>
</file>

<file name="tests/smoke/cjs/tests/urlencode.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/urlencode.smoke.test.js:4">
P2: `expect` is not exported by mocha, so this import leaves `expect` undefined and the assertions will fail. Import `expect` from the assertion library used in the repo (e.g., chai).</violation>
</file>

<file name="tests/smoke/esm/vitest.config.js">

<violation number="1" location="tests/smoke/esm/vitest.config.js:11">
P1: Vitest configuration includes path pattern that doesn't match actual test file locations</violation>
</file>

<file name="tests/smoke/cjs/tests/headers.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/headers.smoke.test.js:4">
P2: Mocha does not export `expect`, so destructuring it from `require('mocha')` leaves `expect` undefined and the assertions will throw. Import `expect` from your assertion library (e.g., chai/expect) and ensure it’s configured instead of pulling it from Mocha.</violation>
</file>

<file name="tests/smoke/cjs/tests/progress.smoke.test.js">

<violation number="1" location="tests/smoke/cjs/tests/progress.smoke.test.js:3">
P1: `expect` is imported from `mocha`, but Mocha does not export an assertion `expect`; these test assertions will fail at runtime.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/cjs/package.json">

<violation number="1" location="tests/smoke/cjs/package.json:7">
P1: 12 orphaned JavaScript test files in tests/smoke/cjs/tests/ are no longer executed after package.json pattern change</violation>

<violation number="2" location="tests/smoke/cjs/package.json:13">
P1: `file:` dependency points to a single JS file instead of a package path/tarball, which can break `npm install` for the CJS smoke tests.</violation>
</file>

<file name="tests/smoke/cjs/tests/cancel.smoke.test.cjs">

<violation number="1" location="tests/smoke/cjs/tests/cancel.smoke.test.cjs:39">
P2: These cancellation tests can pass without proving the request rejected. Add an explicit failure on the success path (or assert rejection directly) so regressions in AbortController cancellation are caught.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".github/workflows/run-ci.yml">

<violation number="1" location=".github/workflows/run-ci.yml:73">
P2: Use `npm ci` here to keep CJS smoke test installs reproducible and aligned with the lockfile in CI.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/cjs/package.json">

<violation number="1" location="tests/smoke/cjs/package.json:13">
P1: Dead CJS smoke test files (.js extension) never executed by mocha runner</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/cjs/tests/cancel.smoke.test.cjs">

<violation number="1" location="tests/smoke/cjs/tests/cancel.smoke.test.cjs:37">
P2: Node version gating uses lexicographic string comparison; parse the major version numerically to avoid incorrect skip behavior.</violation>

<violation number="2" location="tests/smoke/cjs/tests/cancel.smoke.test.cjs:38">
P2: `this.skip()` is used inside arrow-function tests, so the skip path throws instead of skipping on unsupported runtimes.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/cjs/tests/cancel.smoke.test.cjs">

<violation number="1" location="tests/smoke/cjs/tests/cancel.smoke.test.cjs:38">
P2: `return` here causes a false-positive pass on Node <16 instead of a skipped test. Use Mocha skip semantics so unsupported-runtime cases are reported as pending.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 13 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/cjs/tests/formData.smoke.test.cjs">

<violation number="1" location="tests/smoke/cjs/tests/formData.smoke.test.cjs:61">
P1: `this.skip()` is called inside an arrow-function `describe` callback, so the suite cannot be skipped and will error on Node < 18.</violation>
</file>

<file name="tests/smoke/cjs/tests/fetch.smoke.test.cjs">

<violation number="1" location="tests/smoke/cjs/tests/fetch.smoke.test.cjs:29">
P2: `this.skip()` is used inside an arrow-function `describe` callback, so the Node<18 guard throws instead of skipping the suite.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

6 issues found across 21 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/smoke/esm/tests/cancel.smoke.test.js">

<violation number="1" location="tests/smoke/esm/tests/cancel.smoke.test.js:39">
P2: The new `try/catch` pattern weakens the test: it does not fail when cancellation does not reject as expected. Keep an explicit `.rejects` assertion (or fail explicitly after `await request`) so these tests cannot pass on unexpected success paths.</violation>
</file>

<file name="tests/smoke/esm/tests/interceptors.smoke.test.js">

<violation number="1" location="tests/smoke/esm/tests/interceptors.smoke.test.js:29">
P2: Using `||` here changes defaulting semantics and treats intentionally empty payloads as missing. Use a default parameter (or `??`) to preserve the previous behavior.</violation>
</file>

<file name=".github/workflows/run-ci.yml">

<violation number="1" location=".github/workflows/run-ci.yml:112">
P1: The ESM smoke-test workflow calls a non-existent npm script (`test:smoke:esm:mocha`), so the new CI job will fail immediately.</violation>
</file>

<file name="tests/smoke/esm/tests/instance.smoke.test.js">

<violation number="1" location="tests/smoke/esm/tests/instance.smoke.test.js:29">
P2: Use nullish fallback instead of truthiness fallback so valid falsy response bodies (like empty string) are preserved.</violation>
</file>

<file name="tests/smoke/esm/tests/error.smoke.test.js">

<violation number="1" location="tests/smoke/esm/tests/error.smoke.test.js:49">
P2: Use an undefined/null check for `body` instead of a truthy check; current logic masks explicit empty bodies.</violation>
</file>

<file name="tests/smoke/esm/tests/timeout.smoke.test.js">

<violation number="1" location="tests/smoke/esm/tests/timeout.smoke.test.js:40">
P2: Using `||` for `body` fallback incorrectly overrides explicit falsy payloads (e.g. empty string). Preserve only the `undefined` defaulting behavior here.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@jasonsaayman jasonsaayman merged commit d905b75 into v1.x Mar 12, 2026
13 checks passed
@jasonsaayman jasonsaayman deleted the refactor/port-karma-tests branch March 12, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::refactor The PR is related to refactoring priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants