Skip to content

test: remove remaining coverage ignores and tighten cross-bundler runtime coverage#512

Merged
zh-lx merged 8 commits into
mainfrom
test/add-coverage-0331
Apr 2, 2026
Merged

test: remove remaining coverage ignores and tighten cross-bundler runtime coverage#512
zh-lx merged 8 commits into
mainfrom
test/add-coverage-0331

Conversation

@zh-lx
Copy link
Copy Markdown
Owner

@zh-lx zh-lx commented Apr 2, 2026

Summary

This PR removes several remaining /* v8 ignore */ branches by replacing them with executable
coverage and small runtime-safe refactors where needed.

What changed

  • Added coverage for Vue compiler interop in packages/core/src/server/transform/transform-
    vue.ts
    • Covers mixed export shapes where parse is top-level and transform is under default
    • Adds failure-path tests when required compiler exports are missing
  • Removed v8 ignores from packages/core/src/server/use-client.ts
    • Replaced ignored fallback with explicit tests for the port = 0 file-generation path
  • Removed v8 ignores from packages/core/src/server/transform/transform-vue-pug.ts
    • Added focused tests for defensive Pug branches such as missing nodes, missing blocks,
      conditional fallbacks, and undefined columns
  • Removed v8 ignores from packages/core/src/server/server.ts
    • Added tests for git-root success/fallback behavior and relative path handling
  • Removed import-coverage ignore from packages/code-inspector-plugin/src/index.ts
    • Added assertions that plugin output and resetFileRecord() use the same resolved path
  • Simplified resolver handling in packages/turbopack/src/index.ts
    • Reduced redundant helper layers
    • Kept ESM/CJS-compatible webpack entry resolution via import.meta.resolve and
      globalThis.require?.resolve
    • Added/updated tests to cover no-resolver, CJS, ESM-priority, loader config, and
      default record initialization paths

Validation

Executed targeted tests covering the updated areas:

pnpm vitest run test/core/server/transform/transform-vue.test.ts
pnpm vitest run test/core/server/transform/transform-vue-pug.test.ts
pnpm vitest run test/core/server/use-client/get-code-with-web-component.test.ts test/core/
server/use-client/nextjs-integration.test.ts test/core/server/use-client/get-injected-
code.test.ts
pnpm vitest run test/core/server/server/project-root.test.ts
pnpm vitest run test/code-inspector-plugin/index.test.ts
pnpm vitest run test/turbopack/index.test.ts
pnpm --filter @code-inspector/turbopack build

Notes

  • No behavioral change is intended for production paths beyond making module-resolution
    logic more explicit and testable.
  • The main goal of this PR is to replace ignore-based coverage with real executable
    assertions.

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Remove coverage ignores and add executable tests with native URL module

🧪 Tests ✨ Enhancement

Grey Divider

Walkthroughs

Description
• Removed v8 coverage ignores and replaced with executable tests
• Replaced custom fileURLToPath with native Node.js url module
• Simplified ESM/CJS compatibility logic across bundler packages
• Added comprehensive test coverage for previously ignored code paths
• Refactored resolver handling in turbopack and webpack packages
Diagram
flowchart LR
  A["v8 ignore comments"] -->|"Remove"| B["Executable test coverage"]
  C["Custom fileURLToPath"] -->|"Replace with"| D["Native url module"]
  E["Conditional __dirname logic"] -->|"Simplify to"| F["path.dirname + import.meta.url"]
  G["Webpack/Turbopack resolvers"] -->|"Refactor"| H["Unified resolveWebpackEntry"]
  B --> I["Test suite expansion"]
  D --> I
  F --> I
  H --> I
Loading

Grey Divider

File Changes

1. packages/code-inspector-plugin/src/index.ts ✨ Enhancement +5/-12

Replace custom fileURLToPath with native url module

packages/code-inspector-plugin/src/index.ts


2. packages/code-inspector-plugin/vite.config.ts ⚙️ Configuration changes +1/-0

Add url to external dependencies

packages/code-inspector-plugin/vite.config.ts


3. packages/core/src/server/server.ts 🐞 Bug fix +0/-3

Remove v8 ignores from git root and port error handling

packages/core/src/server/server.ts


View more (26)
4. packages/core/src/server/transform/transform-vue-pug.ts ✨ Enhancement +12/-18

Export functions and remove defensive v8 ignores

packages/core/src/server/transform/transform-vue-pug.ts


5. packages/core/src/server/use-client.ts ✨ Enhancement +10/-20

Simplify dirname logic and remove optional chaining ignores

packages/core/src/server/use-client.ts


6. packages/core/src/shared/utils.ts ✨ Enhancement +5/-19

Remove custom fileURLToPath implementation

packages/core/src/shared/utils.ts


7. packages/core/types/server/transform/transform-vue-pug.d.ts 📝 Documentation +15/-0

Export previously private functions in type definitions

packages/core/types/server/transform/transform-vue-pug.d.ts


8. packages/core/types/shared/utils.d.ts 📝 Documentation +0/-1

Remove fileURLToPath from exported declarations

packages/core/types/shared/utils.d.ts


9. packages/core/vite.config.ts ⚙️ Configuration changes +1/-0

Add url to external dependencies

packages/core/vite.config.ts


10. packages/mako/src/index.ts ✨ Enhancement +1/-2

Remove defensive v8 ignore for options fallback

packages/mako/src/index.ts


11. packages/turbopack/src/index.ts ✨ Enhancement +21/-12

Extract and export resolveWebpackEntry helper function

packages/turbopack/src/index.ts


12. packages/turbopack/types/index.d.ts 📝 Documentation +4/-0

Add resolveWebpackEntry function declaration

packages/turbopack/types/index.d.ts


13. packages/webpack/src/index.ts ✨ Enhancement +28/-29

Simplify dirname logic and add duplicate loader detection

packages/webpack/src/index.ts


14. packages/webpack/src/loader.ts ✨ Enhancement +2/-3

Remove defensive v8 ignore for options fallback

packages/webpack/src/loader.ts


15. packages/webpack/vite.config.ts ⚙️ Configuration changes +1/-1

Add url to external dependencies

packages/webpack/vite.config.ts


16. test/code-inspector-plugin/index.test.ts 🧪 Tests +8/-0

Add test for resetFileRecord path consistency

test/code-inspector-plugin/index.test.ts


17. test/core/server/server/create-server.test.ts 🧪 Tests +132/-95

Refactor mocks and add error handling test

test/core/server/server/create-server.test.ts


18. test/core/server/server/project-root.test.ts 🧪 Tests +53/-0

Add new tests for git root and relative path handling

test/core/server/server/project-root.test.ts


19. test/core/server/server/start-server.test.ts 🧪 Tests +165/-201

Refactor server mocking and simplify test structure

test/core/server/server/start-server.test.ts


20. test/core/server/transform/transform-vue-pug.test.ts 🧪 Tests +101/-0

Add new tests for Pug template transformation edge cases

test/core/server/transform/transform-vue-pug.test.ts


21. test/core/server/transform/transform-vue.test.ts 🧪 Tests +18/-0

Add tests for missing compiler export error handling

test/core/server/transform/transform-vue.test.ts


22. test/core/server/use-client/get-code-with-web-component.test.ts 🧪 Tests +27/-22

Mock startServer and add injectTo path assertions

test/core/server/use-client/get-code-with-web-component.test.ts


23. test/core/server/use-client/nextjs-integration.test.ts 🧪 Tests +12/-15

Mock startServer and add web component file assertions

test/core/server/use-client/nextjs-integration.test.ts


24. test/core/shared/utils/file-url-to-path.test.ts 🧪 Tests +0/-103

Remove fileURLToPath tests after function deletion

test/core/shared/utils/file-url-to-path.test.ts


25. test/core/src/index.test.ts 🧪 Tests +21/-6

Remove fileURLToPath from export assertions

test/core/src/index.test.ts


26. test/esbuild/index.test.ts 🧪 Tests +4/-2

Fix excluded file test assertion format

test/esbuild/index.test.ts


27. test/turbopack/index.test.ts 🧪 Tests +35/-3

Add tests for resolveWebpackEntry function

test/turbopack/index.test.ts


28. test/webpack/index.test.ts 🧪 Tests +55/-0

Add tests for duplicate loader detection and edge cases

test/webpack/index.test.ts


29. test/webpack/loader.test.ts 🧪 Tests +14/-0

Add test for undefined options handling

test/webpack/loader.test.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Apr 2, 2026

Code Review by Qodo

🐞 Bugs (5) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Null WebpackEntry crash 🐞 Bug ≡ Correctness
Description
TurbopackCodeInspectorPlugin passes a possibly-null WebpackEntry into path.resolve(), which can
throw and prevent the plugin from initializing. resolveWebpackEntry is explicitly able to return
null, and the test suite asserts that behavior.
Code

packages/turbopack/src/index.ts[R47-52]

+  const WebpackEntry = resolveWebpackEntry({
+    requireResolve: globalThis.require?.resolve,
+    importMetaResolve: import.meta.resolve,
+  });
  const WebpackDistDir = path.resolve(WebpackEntry, '..');
Evidence
The plugin unconditionally computes WebpackDistDir from WebpackEntry, but resolveWebpackEntry
returns null when neither resolver is available; tests confirm the null return is an expected
outcome, so this is a real runtime path.

packages/turbopack/src/index.ts[15-52]
test/turbopack/index.test.ts[138-141]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`TurbopackCodeInspectorPlugin` calls `path.resolve(WebpackEntry, '..')` even when `resolveWebpackEntry(...)` can return `null`, causing a runtime throw and preventing the plugin from loading.

### Issue Context
`resolveWebpackEntry({})` is expected to return `null` (covered by tests), so the plugin must either handle `null` (e.g., return `{}` / disable plugin) or throw a clear, actionable error before calling `path.resolve`.

### Fix Focus Areas
- packages/turbopack/src/index.ts[15-52]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Async resolver mishandled 🐞 Bug ≡ Correctness
Description
resolveWebpackEntry casts the result of importMetaResolve to a string and calls fileURLToPath on it,
but its own type allows Promise<string> and the function does not await or detect Promises. If a
Promise is returned, fileURLToPath will receive a non-string and can throw at runtime.
Code

packages/turbopack/src/index.ts[R15-24]

+export function resolveWebpackEntry(params: {
+  requireResolve?: (id: string) => string;
+  importMetaResolve?: (id: string) => string | Promise<string>;
+}) {
+  if (typeof params.importMetaResolve === 'function') {
+    const resolved = params.importMetaResolve(
+      '@code-inspector/webpack',
+    ) as unknown as string;
+    return fileURLToPath(resolved);
+  }
Evidence
The resolver helper explicitly types importMetaResolve as returning string | Promise<string>,
but immediately casts the return to string and passes it to fileURLToPath without
awaiting/branching.

packages/turbopack/src/index.ts[15-29]
packages/turbopack/types/index.d.ts[6-9]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`resolveWebpackEntry` accepts an `importMetaResolve` that may return a `Promise<string>`, but the implementation treats it as a synchronous string and calls `fileURLToPath` immediately.

### Issue Context
This can lead to runtime failures if a Promise is returned. Since plugin configuration is typically synchronous, you can either:
- Restrict the accepted type to synchronous `string` only (and update types accordingly), OR
- Detect Promise-like values and throw a clear error / fall back to `requireResolve`.

### Fix Focus Areas
- packages/turbopack/src/index.ts[15-29]
- packages/turbopack/types/index.d.ts[6-10]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Wrong resolver return typing 🐞 Bug ≡ Correctness
Description
packages/turbopack/types/index.d.ts declares resolveWebpackEntry returns string, but the
implementation (and tests) return null when no resolver is provided. This makes TS consumers believe
a string is always returned and can hide null-handling bugs.
Code

packages/turbopack/types/index.d.ts[R6-10]

+export declare function resolveWebpackEntry(params: {
+    requireResolve?: (id: string) => string;
+    importMetaResolve?: (id: string) => string | Promise<string>;
+}): string;
export declare function TurbopackCodeInspectorPlugin(options: Options): Record<string, any>;
Evidence
The implementation returns null in the no-resolver case, and the tests assert that
resolveWebpackEntry({}) is null, but the published declaration file says the return type is
string.

packages/turbopack/src/index.ts[15-29]
test/turbopack/index.test.ts[138-141]
packages/turbopack/types/index.d.ts[6-10]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The `resolveWebpackEntry` declaration file claims it returns `string`, but the implementation returns `string | null`.

### Issue Context
You should either:
- Update the declaration to `string | null`, and ensure call sites handle `null`, OR
- Change implementation to never return `null` (throw with message) so the `string` type is correct.

### Fix Focus Areas
- packages/turbopack/types/index.d.ts[6-10]
- packages/turbopack/src/index.ts[15-52]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. Removed core export symbol 🐞 Bug ⚙ Maintainability
Description
@code-inspector/core no longer exports fileURLToPath from its shared utils surface, so any
downstream code importing it from '@code-inspector/core' will fail (type-check and/or runtime). This
is a breaking API change outside the PR’s stated “no behavioral change” intent.
Code

packages/core/types/shared/utils.d.ts[3]

-export declare function fileURLToPath(fileURL: string): string;
Evidence
@code-inspector/core re-exports everything from ./shared, and ./shared re-exports everything
from ./utils. The current shared/utils.ts and types/shared/utils.d.ts no longer contain
fileURLToPath, so it is no longer part of the public API.

packages/core/src/index.ts[1-4]
packages/core/src/shared/index.ts[1-4]
packages/core/src/shared/utils.ts[1-80]
packages/core/types/shared/utils.d.ts[1-6]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
A previously exported `fileURLToPath` helper is no longer exported from `@code-inspector/core` because it was removed from `shared/utils` (and its .d.ts). This is a breaking API surface change.

### Issue Context
If you still want to migrate internal usage to Node's `url.fileURLToPath`, you can keep compatibility by reintroducing `export function fileURLToPath(...)` as a thin wrapper (or re-export) so existing imports keep working.

### Fix Focus Areas
- packages/core/src/shared/utils.ts[1-80]
- packages/core/types/shared/utils.d.ts[1-6]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Pug AstLocation column mismatch 🐞 Bug ⚙ Maintainability
Description
belongTemplate is now exported, but its AstLocation type requires column: number while the
implementation (and tests) explicitly treat column as possibly undefined. This creates an
inconsistent exported contract and can cause consumer-side type workarounds or incorrect
assumptions.
Code

packages/core/src/server/transform/transform-vue-pug.ts[R19-25]

+export function belongTemplate(
  target: AstLocation,
  start: AstLocation,
-  end: AstLocation
+  end: AstLocation,
) {
  return (
    (target.line > start.line && target.line < end.line) ||
Evidence
The implementation checks target.column === undefined, and tests pass column: undefined, but
both the source interface and the published .d.ts declare column: number (non-optional).

packages/core/src/server/transform/transform-vue-pug.ts[6-31]
packages/core/types/server/transform/transform-vue-pug.d.ts[5-17]
test/core/server/transform/transform-vue-pug.test.ts[16-36]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`belongTemplate` supports `column` being `undefined`, but `AstLocation.column` is typed as required `number` in both source and generated/published types.

### Issue Context
Because `belongTemplate` is now exported, the type contract should match runtime behavior.

### Fix Focus Areas
- packages/core/src/server/transform/transform-vue-pug.ts[6-31]
- packages/core/types/server/transform/transform-vue-pug.d.ts[5-17]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment on lines +47 to 52
const WebpackEntry = resolveWebpackEntry({
requireResolve: globalThis.require?.resolve,
importMetaResolve: import.meta.resolve,
});
const WebpackDistDir = path.resolve(WebpackEntry, '..');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Null webpackentry crash 🐞 Bug ≡ Correctness

TurbopackCodeInspectorPlugin passes a possibly-null WebpackEntry into path.resolve(), which can
throw and prevent the plugin from initializing. resolveWebpackEntry is explicitly able to return
null, and the test suite asserts that behavior.
Agent Prompt
### Issue description
`TurbopackCodeInspectorPlugin` calls `path.resolve(WebpackEntry, '..')` even when `resolveWebpackEntry(...)` can return `null`, causing a runtime throw and preventing the plugin from loading.

### Issue Context
`resolveWebpackEntry({})` is expected to return `null` (covered by tests), so the plugin must either handle `null` (e.g., return `{}` / disable plugin) or throw a clear, actionable error before calling `path.resolve`.

### Fix Focus Areas
- packages/turbopack/src/index.ts[15-52]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +15 to +24
export function resolveWebpackEntry(params: {
requireResolve?: (id: string) => string;
importMetaResolve?: (id: string) => string | Promise<string>;
}) {
if (typeof params.importMetaResolve === 'function') {
const resolved = params.importMetaResolve(
'@code-inspector/webpack',
) as unknown as string;
return fileURLToPath(resolved);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. Async resolver mishandled 🐞 Bug ≡ Correctness

resolveWebpackEntry casts the result of importMetaResolve to a string and calls fileURLToPath on it,
but its own type allows Promise<string> and the function does not await or detect Promises. If a
Promise is returned, fileURLToPath will receive a non-string and can throw at runtime.
Agent Prompt
### Issue description
`resolveWebpackEntry` accepts an `importMetaResolve` that may return a `Promise<string>`, but the implementation treats it as a synchronous string and calls `fileURLToPath` immediately.

### Issue Context
This can lead to runtime failures if a Promise is returned. Since plugin configuration is typically synchronous, you can either:
- Restrict the accepted type to synchronous `string` only (and update types accordingly), OR
- Detect Promise-like values and throw a clear error / fall back to `requireResolve`.

### Fix Focus Areas
- packages/turbopack/src/index.ts[15-29]
- packages/turbopack/types/index.d.ts[6-10]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +6 to 10
export declare function resolveWebpackEntry(params: {
requireResolve?: (id: string) => string;
importMetaResolve?: (id: string) => string | Promise<string>;
}): string;
export declare function TurbopackCodeInspectorPlugin(options: Options): Record<string, any>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

3. Wrong resolver return typing 🐞 Bug ≡ Correctness

packages/turbopack/types/index.d.ts declares resolveWebpackEntry returns string, but the
implementation (and tests) return null when no resolver is provided. This makes TS consumers believe
a string is always returned and can hide null-handling bugs.
Agent Prompt
### Issue description
The `resolveWebpackEntry` declaration file claims it returns `string`, but the implementation returns `string | null`.

### Issue Context
You should either:
- Update the declaration to `string | null`, and ensure call sites handle `null`, OR
- Change implementation to never return `null` (throw with message) so the `string` type is correct.

### Fix Focus Areas
- packages/turbopack/types/index.d.ts[6-10]
- packages/turbopack/src/index.ts[15-52]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (67cbcec) to head (129608d).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #512   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2751      2821   +70     
  Branches       692       695    +3     
=========================================
+ Hits          2751      2821   +70     

☔ View full report in Codecov by Sentry.
📢 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.

@zh-lx zh-lx merged commit 2ccbe94 into main Apr 2, 2026
4 checks passed
@zh-lx zh-lx deleted the test/add-coverage-0331 branch April 2, 2026 02:29
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