nuxt / test-utils

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

Unable to use nuxt-vitest with @nuxtjs/i18n 8.0.0-rc.5 #608

Closed stephanepericat closed 10 months ago

stephanepericat commented 10 months ago

When I run a test in Nuxt environment, I get the following error:


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
SyntaxError: /Users/shortwavaudio/Workspace/thatcovidlife/.nuxt/i18n.options.mjs: Support for the experimental syntax 'importAttributes' isn't currently enabled (3:98):

  1 | // @ts-nocheck
  2 |
> 3 | import locale__Users_shortwavaudio_Workspace_thatcovidlife_locales_en_js from "../locales/en.js" assert { type: "js" };
    |                                                                                                  ^
  4 | import locale__Users_shortwavaudio_Workspace_thatcovidlife_locales_es_js from "../locales/es.js" assert { type: "js" };
  5 | import locale__Users_shortwavaudio_Workspace_thatcovidlife_locales_fr_js from "../locales/fr.js" assert { type: "js" };
  6 | import locale__Users_shortwavaudio_Workspace_thatcovidlife_locales_pt_js from "../locales/pt.js" assert { type: "js" };

Add @babel/plugin-syntax-import-attributes (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes) to the 'plugins' section of your Babel config to enable parsing.
 ❯ constructor node_modules/@babel/parser/lib/index.js:356:19
 ❯ Parser.raise node_modules/@babel/parser/lib/index.js:3223:19
 ❯ Parser.expectOnePlugin node_modules/@babel/parser/lib/index.js:3269:18
 ❯ Parser.maybeParseImportAttributes node_modules/@babel/parser/lib/index.js:14277:14
 ❯ Parser.parseImportSourceAndAttributes node_modules/@babel/parser/lib/index.js:14165:10
 ❯ Parser.parseImportSpecifiersAndAfter node_modules/@babel/parser/lib/index.js:14159:17
 ❯ Parser.parseImport node_modules/@babel/parser/lib/index.js:14150:17
 ❯ Parser.parseStatementContent node_modules/@babel/parser/lib/index.js:12715:27
 ❯ Parser.parseStatementLike node_modules/@babel/parser/lib/index.js:12593:17
 ❯ Parser.parseModuleItem node_modules/@babel/parser/lib/index.js:12570:17
 ❯ Parser.parseBlockOrModuleBlockBody node_modules/@babel/parser/lib/index.js:13194:36
 ❯ Parser.parseBlockBody node_modules/@babel/parser/lib/index.js:13187:10
 ❯ Parser.parseProgram node_modules/@babel/parser/lib/index.js:12469:10
 ❯ Parser.parseTopLevel node_modules/@babel/parser/lib/index.js:12459:25
 ❯ Parser.parse node_modules/@babel/parser/lib/index.js:14381:10
 ❯ parse node_modules/@babel/parser/lib/index.js:14422:38
 ❯ parser node_modules/@babel/core/lib/parser/index.js:41:34
 ❯ normalizeFile node_modules/@babel/core/lib/transformation/normalize-file.js:64:37
 ❯ run node_modules/@babel/core/lib/transformation/index.js:21:50
 ❯ transform node_modules/@babel/core/lib/transform.js:22:33
 ❯ evaluateSync node_modules/gensync/index.js:251:28
 ❯ sync node_modules/gensync/index.js:89:14
 ❯ stopHiding - secret - don't use this - v1 node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:47:12
 ❯ transformSync node_modules/@babel/core/lib/transform.js:43:76
 ❯ Instrumenter.instrumentSync node_modules/istanbul-lib-instrument/src/instrumenter.js:102:25
 ❯ IstanbulCoverageProvider.onFileTransform node_modules/@vitest/coverage-istanbul/dist/provider.js:164:36
 ❯ TransformContext.transform node_modules/vitest/dist/vendor-cli-api.bf4b62a8.js:12708:109
 ❯ Object.transform node_modules/vitest/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:44352:62
 ❯ loadAndTransform node_modules/vitest/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:55026:29
 ❯ ViteNodeServer._transformRequest node_modules/vite-node/dist/server.mjs:373:16
 ❯ ViteNodeServer._fetchModule node_modules/vite-node/dist/server.mjs:340:17
 ❯ MessagePort.<anonymous> node_modules/vitest/dist/vendor-index.cc463d9e.js:156:20

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Code can be found here: https://github.com/stephanepericat/covid-conscious/tree/feature/TCL-43

stephanepericat commented 10 months ago

Update:

it seems to work, if:

  1. I just use the env comment at the top of the spec file: // @vitest-environment nuxt
  2. I include .nuxt in the file name

it does not work if:

  1. I set the environment property to nuxt in vitest config