I created a new Vue project via npm init vue@latest
( with vitest ). Inside ./src/components
is a __test__
directory containing a component unit test.
Is it intended to create another __test__
directory for the ./src/views
directory if you want to test your view files?
So when using a folder by type structure ( you might also want to use a folder by feature structure ) the project might look like
src
├── components
│ ├── MyComponent.vue
│ └── __test__
│ └── MyComponent.spec.vue
└── views
├── MyView1.vue
├── MyView2.vue
└── __test__
├── MyView1.spec.vue
└── MyView2.spec.vue
Please don't get me wrong, this is not a question about personal preferences . I just would like to know how vitest wants me to do it.
Because when having a __test__
directory right next to my code, why wouldn't you put the spec files right next to the code and get rid of the directory?
E.g.
src
├── components
│ ├── MyComponent.vue
│ └── MyComponent.spec.vue
└── views
├── MyView1.vue
├── MyView1.spec.vue
├── MyView2.vue
└── MyView2.spec.vue
It would be nice if one could explain the "common" way of using vitest inside Vue projects because until now I added a test
directory right next to the src
directory and mirrored the structure but it seems vitest/Vue prefers a different approach.
This might also be related to How to keep tests outside from source directory in Vite projects? because to me it's not clear why someone would initialize a project with a __test__
directory in the components directory only ( why not for views too? ) and add the line "exclude": ["src/**/__tests__/*"],
to the tsconfig.app.json file. What would happen if you keep your tests without having a __test__
directory and have them outside the src directory or right next to your component/view/js/ts files?