NuxtN
Nuxt2y ago
Zampa

Correct setup config for Test Utils

Reproduction: https://stackblitz.com/edit/github-gu1sj1?file=tests%2Fbasic.e2e.test.ts
Issue filed: https://github.com/nuxt/test-utils/issues/893

I can't seem to utilize the alternative nuxt.config location with @nuxt/test-utils. If I have my nuxt.config as ./.config/nuxt.ts, e2e tests will always fail with Error: Invalid nuxt app. (Please explicitly set 'options.rootDir' pointing to a valid nuxt app).

This is my test:
// ./tests/basic.e2e.test.ts
import { $fetch, setup } from '@nuxt/test-utils/e2e';
import { describe, expect, it } from 'vitest';

describe('basic', async () => {
  await setup({
    rootDir: './app',
    configFile: '/.config/nuxt.ts',
  });

  it('contains Welcome to Nuxt! string', async () => {
    const html = await $fetch('/');
    expect(html).toContain('Welcome to Nuxt!');
  });
});

and my nuxt.config:
// ./.config/nuxt.ts
export default defineNuxtConfig({
  compatibilityDate: '2024-04-03',
  devtools: { enabled: true },
  future: {
    compatibilityVersion: 4,
  },
  modules: ['@nuxt/test-utils/module'],
});

If I move and rename nuxt.config back to the root, it works.

I'm not sure if this is a limitation or expectation of test-utils, or the config file name/location that isn't being honored by the configFile setting, or what.
StackBlitzNathan Chase
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
GitHub
Environment Reproduction: https://stackblitz.com/edit/github-gu1sj1?file=tests%2Fbasic.e2e.test.ts I can't seem to utilize the alternative nuxt.config location with @nuxt/test-utils. If I have ...
Was this page helpful?