nuxt / nuxt/test-utils

useAsyncData in combination with --coverage (istanbul) causes syntax error

Open
#558 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

vitest-environment
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

Error: SyntaxError: Expecting Unicode escape sequence \uXXXX (1:1)

Happens when using the @vitest/coverage-istanbul coverage provider. V8 Does work (but i have never been able to create accurate coverage reports with that)

Even when using useLazyAsyncData or // useAsyncData

reproduction: https://stackblitz.com/edit/nuxt-starter-1ens2b

run pnpm run test

I hope I did this correctly, but for me it seems with latest version & latest nuxt you can reproduce this anywhere if you just add // useAsyncData I guess that is because of the auto imports.

Stacktrace example:

FAIL  app.test.ts [ app.test.ts ]
SyntaxError: Expecting Unicode escape sequence \uXXXX (1:1)
 ❯ pp$4.raise node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:25027:13
 ❯ pp.invalidStringToken node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:27176:10
 ❯ pp.readWord1 node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:27340:16
 ❯ pp.readWord node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:27359:19
 ❯ pp.readToken node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:26647:19
 ❯ pp.nextToken node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:26640:15
 ❯ Parser.parse node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:22063:8
 ❯ Function.parse node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:22114:35
 ❯ TransformContext.parse node_modules/.pnpm/vite@4.4.9_@types+node@20.5.7/node_modules/vite/dist/node/chunks/dep-df561101.js:43962:27
 ❯ TransformContext.transform node_modules/.pnpm/@nuxt+vite-builder@3.7.0_vue@3.3.4/node_modules/@nuxt/vite-builder/dist/shared/vite-builder.d6a45f81.mjs:947:24

Contributor guide

Open the contributing guide

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.

Research direction

Start with the StackBlitz reproduction and run pnpm run test using the Istanbul coverage provider, then compare the result with V8 coverage. Inspect the transformation path shown in the Vite and Nuxt Vite Builder stack trace, including the useAsyncData and useLazyAsyncData cases. Done means tests run without the Unicode escape syntax error when coverage is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript, vite
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.