Zone async lowering breaks `vi.mock` async factories in `environment: 'node'`

Open
#42 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript, vite
Domain
build-system

Research direction

Start by reading the vite-plugin-ngp:zone-async transform and how it detects the configured environment and zone.js polyfills. Reproduce the failure with an async vi.mock factory in a Node environment, then check the existing behavior for Node projects. Done when the factory no longer throws in the reported setup and the transform is skipped when Node projects do not load zone.js, or the helper is made safe to hoist.

Written by the indexing model from the issue text.

Description

bug

Part of #27.

Problem

With zone.js in the polyfills, ngp lowers async/await. In a project whose environment is node, Vitest hoists a vi.mock(…, async () => …) factory above the __async helper the lowering adds, and the factory throws. Those projects load no zone.js, so they don't need the lowering.

Proposed change

Skip the vite-plugin-ngp:zone-async transform when the environment is node and zone.js isn't loaded, or hoist-safe the helper. We skip it in node-environment projects today.

Setup: ngp 0.3.0, @angular/compiler/compiler-cli 22.3.0-next.4, Vite 8, Vitest 5.1.0 (pool: 'forks'), a Nx monorepo with 1,035 Angular projects, one Vitest config each, specs written for TestBed under JIT (Analog).

Dominant language
TypeScript
Stars
7
Forks
1
Avg merge
12h 24m
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from push-based/vite-plugin-ngp

All issues in push-based/vite-plugin-ngp

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.