nuxt / test-utils

🧪 Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
304 stars 78 forks source link

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

Open rubennaatje opened 1 year ago

rubennaatje commented 1 year ago

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
rubennaatje commented 1 year ago

My workaround for now to get past the CI checks is to make a wrapper composable

import { AsyncDataOptions } from "nuxt/app";

export const useWrapperAsyncData = <T = any>(
  ...args: [string, () => Promise<T>, AsyncDataOptions<T>]
) => useAsyncData(...args);

Somehow this fixes my issue :/

Hope to find a real fix soon though!

yauheniv commented 2 months ago

This issue appears for me as well on Node.js 18.19.1 only on GitLab CI, the runner platform is amd64/linux. image