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?
__tests__is a convention: "You are not required to keep this folder. It's a convention[...]"vitest tests should live inside the root dir in a vitest dirorvitest tests should live right next to the codeorvitest tests live inside a __test__ directory in each directoryvitestworks as intended", then the answer is: "Nothing needs to be done. You can place your tests inside the components folder directly.vitestwill run them"__tests__folder incomponents, but not inviews. Because the person who made that template was not consistent. Most likely, they made the folder incomponentsto avoid clutter (because that folder typically gets a lot of files).viewsrarely has more than 10 files (typically 2-5), so the need to unclutter it is smaller. But I can't definitively answer your question, because I don't know who put that there and what they were thinking. I suggest you ask it on Vue's discord channel, although I doubt you'll get a definitive answer.