Skip to content

Tests failing when run the test first time after installation #2845

@kazupon

Description

@kazupon

Describe the bug

I've been using vitest to develop nuxt modules so far.
I have changed the code in this PR without changing the code around dependencies and imports. However, when I run the tests, the tests are now failing in CI with the following error code:

TypeError: generateJSON is not a function
 ❯ generateVueI18nOptions src/gen.ts:183:11
    181|       for (const [locale, localeMessages] of Object.entries(value)) {
    182|         genCode += `${JSON.stringify(locale)}:${
    183|           generateJSON(JSON.stringify(localeMessages), { type: 'bare', env: dev ? 'development' : 'production' }).code
       |           ^
    184|         },`
    185|       }
 ❯ src/gen.ts:90:37
 ❯ Module.generateLoaderOptions src/gen.ts:82:41
 ❯ test/gen.test.ts:91:16

It seems that the code I imported is undefined.

I noticed this issue in CI.

Additional info:

Reproduction

Unfortunately, I could not reproduce with minimal codes, but We can reproduce realworld code.

repo: https://github.com/nuxt-modules/i18n

reproduction step:

  1. git clone [email protected]:nuxt-modules/i18n.git
  2. git checkout fix/1834
  3. pnpm install
  4. pnpm test:unit

So, you can face issue.

By the way, if we do pnpm test:unit again, the test works correctly.

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 86.55 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
  Browsers:
    Chrome: 109.0.5414.119
    Firefox: 109.0
    Safari: 16.2
  npmPackages:
    vitest: ^0.26.2 => 0.26.2

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions