Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

742
Visualizações
How to keep tests outside from source directory in Vite projects?

Running npm init vue@latest with the following setup

enter image description here

generates a Vitest spec file inside the src directory. I'm wondering why Cypress e2e tests have a seperate directory and Vitest unit tests are right next to the source code. Are there any reasons?

I want to move those tests to the root directory (equal to cypress), created a vitest directory and moved to spec into it.

The test itself passes but I think I have to change sopme configuration to exclude the tests from the build etc.

Inside the file tsconfig.app.json I changed the line "exclude": ["src/**/__tests__/*"], to "exclude": ["vitest"],.

Is there something else I should do? Or are there any reasons to keep Vitest tests inside the source directory?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To get the test folder outside the source folder :

  1. create a vitest folder on root dir
  2. move ./src/components/__tests__ to ./vitest/__tests__
  3. On test *.spec file, you will import components with alias @
  • import HelloWorld from '@/components/HelloWorld.vue'
  1. in tsconfig.app.json
  • change "exclude": ["src/**/__tests__/*"], to "exclude": ["vitest/**/__tests__/*"],
  1. run npm run build && npm run test:unit

Would you mind explaining why you keep the tests directory inside the vitest directory?

You are not required to keep this folder. It's a convention, check below 👇

If you want to put the spec file in the tests folder without a subfolder then just add to the vite.config.ts :

test: {
    include: ['./vitest/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
  }

then also adjust tsconfig.app.json: "exclude": ["vitest/**/*"],

Result of yarn run test:unit

enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda