vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Add `vitest init` like `storybook init`

Open ShortArrow opened this issue 2 years ago • 3 comments

Clear and concise description of the problem

There are so many different ways to set it up that it can be confusing.

Suggested solution

Storybook has show one solution. This has auto generation feature of .storybook/* and src/stories/*. And then, auto detect TS or JS, and auto edit package.json.

Auto generate feature of vitest.config.ts like pnpm dlx vitest@latest init. It would be convenient if it were there.

Alternative

If this is not within the scope of what vitest should do, or if vitest already has this functionality, please close this issue.

Additional context

No response

Validations

ShortArrow avatar Feb 25 '24 03:02 ShortArrow

What would this package actually do?

As far as I know, @storybook/builder-vite was a separate package that was used to integrate Vite into Storybook. Nowadays it's no longer needed as it's built-in into Storybook. Using this logic I have no idea what @vitest/builder-vite would do. Integrate Vite into Vitest? 😕

AriPerkkio avatar Feb 25 '24 07:02 AriPerkkio

@AriPerkkio Maybe I was tired when I post this issue. I was seeing this command pnpm dlx storybook@latest init , auto generate .storybook folder and src/stories. I will rewrite Issue.

ShortArrow avatar Feb 25 '24 11:02 ShortArrow

It looks like Jest has jest --init https://jestjs.io/docs/cli#--init and it's recently moved to create-jest package https://github.com/jestjs/jest/pull/14453

This essentially just ask 5 questions https://github.com/jestjs/jest/blob/7e33cd77ccab163ea525f5c7b45c3c48a3458630/packages/create-jest/src/questions.ts#L10-L50 and I'm not so sure if it's practically useful.

I think having the examples https://vitest.dev/guide/#examples https://github.com/vitest-dev/vitest/blob/main/examples/README.md is easier to maintain and practically more useful, so maybe we just need to tweak documentations so that new users can discover it easily.

Btw, I just found that create-vitest package is already taken by https://github.com/dolanmiu/create-vitest/ But it doesn't look like this one generates config file vitest.config.ts.

hi-ogawa avatar Feb 25 '24 23:02 hi-ogawa

As a team, we decided that it would require too much maintenance on our side to support this. We believe that frameworks themselves should integrate testing scaffolding since it is very dependent on the codebase.

If you just need a simple example of a javascript application, you can already use existing examples: https://vitest.dev/guide/#examples

sheremet-va avatar Mar 28 '24 09:03 sheremet-va