test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

Doesn't load `vitest.config.ts` automatically.

Open jinyongp opened this issue 1 year ago • 2 comments

Environment


  • Operating System: Darwin
  • Node Version: v20.12.0
  • Nuxt Version: 3.12.2
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools, modules
  • Runtime Modules: @nuxt/test-utils/[email protected]
  • Build Modules: -

Reproduction

Reproduction on CodeSandbox

Describe the bug

After adding @nuxt/test-utils/module to nuxt.config.ts, the vitest.config.ts file in the root directory is not automatically loaded. Even when explicitly specifying vitestConfig.config in the testUtils property, the vitest.config.ts is not being applied.

Here is the configuration:

// nuxt.config.ts
export default defineNuxtConfig({
  devtools: { enabled: true },

  modules: [
    '@nuxt/test-utils/module'
  ],

  testUtils: {
    startOnBoot: true,
	logToConsole: true,
    vitestConfig: {
      // config: path.join(__dirname, 'vitest.config.ts') // not working
    }
  }
})
// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'

export default defineVitestConfig({
  test: {
    globals: true,
    silent: true,
    environment: 'nuxt',

    include: [
      'server/**/*.test.ts',
    ],

    exclude: [
      '**/-*.*',
    ],
  }
})

I have observed a difference in the results when running tests directly with vitest and running them via nuxt dev.

$ vitest run

 ✓ server/tests/included-test.test.ts (1)
   ✓ included-test (1)
     ✓ should work

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  03:26:12
   Duration  374ms (transform 94ms, setup 118ms, collect 3ms, tests 1ms, environment 68ms, prepare 99ms)
$ nuxt dev


      UI started at http://localhost:15555/__vitest__/

ℹ Vite server warmed up in 661ms                                                                                                                                   5:19:46 AM
 ❯ server/tests/-ignored-test.test.ts (1)
   ❯ ignored-test (1)
     × this test should be ignored
 ✓ server/tests/included-test.test.ts (1)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  server/tests/-ignored-test.test.ts > ignored-test > this test should be ignored
AssertionError: expected true to be false // Object.is equality

- Expected
+ Received

- false
+ true

 ❯ server/tests/-ignored-test.test.ts:5:18
      3| describe("ignored-test", () => {
      4|   it("this test should be ignored", () => {
      5|     expect(true).toBe(false);
       |                  ^
      6|   });
      7| });

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed | 1 passed (2)
      Tests  1 failed | 1 passed (2)
   Start at  05:19:46
   Duration  433ms (transform 443ms, setup 73ms, collect 438ms, tests 6ms, environment 0ms, prepare 115ms)

Additional context

No response

Logs

No response

jinyongp avatar Jun 25 '24 20:06 jinyongp