Skip to content

Commit 7fc9e47

Browse files
authored
feat(vitest): 3 to 4 next steps (#797)
1 parent b8e4fc7 commit 7fc9e47

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

.changeset/ripe-lines-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
feat(vitest): when `add vitest` is used within a project that uses vitest@3, the addon will display some next steps to finalize the migration to vitest@4

packages/addons/vitest-addon/index.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@ const options = defineAddonOptions()
1515
})
1616
.build();
1717

18+
// Manage only version before current
19+
let vitestV3Installed = false;
20+
1821
export default defineAddon({
1922
id: 'vitest',
2023
shortDescription: 'unit testing',
2124
homepage: 'https://vitest.dev',
2225
options,
23-
run: ({ sv, files, typescript, kit, options }) => {
26+
27+
run: ({ sv, files, typescript, kit, options, dependencyVersion }) => {
2428
const ext = typescript ? 'ts' : 'js';
2529
const unitTesting = options.usages.includes('unit');
2630
const componentTesting = options.usages.includes('component');
2731

32+
vitestV3Installed = (dependencyVersion('vitest') ?? '')
33+
.replaceAll('^', '')
34+
.replaceAll('~', '')
35+
?.startsWith('3.');
36+
2837
sv.devDependency('vitest', '^4.0.10');
2938

3039
if (componentTesting) {
@@ -149,5 +158,27 @@ export default defineAddon({
149158

150159
return generateCode();
151160
});
161+
},
162+
163+
nextSteps: ({ highlighter, typescript, options }) => {
164+
const toReturn: string[] = [];
165+
166+
if (vitestV3Installed) {
167+
const componentTesting = options.usages.includes('component');
168+
if (componentTesting) {
169+
toReturn.push(`Uninstall ${highlighter.command('@vitest/browser')} package`);
170+
toReturn.push(
171+
`Update usage from ${highlighter.command("'@vitest/browser...'")} to ${highlighter.command("'vitest/browser'")}`
172+
);
173+
}
174+
toReturn.push(
175+
`${highlighter.optional('Optional')} Check ${highlighter.path('./vite.config.ts')} and remove duplicate project definitions`
176+
);
177+
toReturn.push(
178+
`${highlighter.optional('Optional')} Remove ${highlighter.path('./vitest-setup-client' + (typescript ? '.ts' : '.js'))} file`
179+
);
180+
}
181+
182+
return toReturn;
152183
}
153184
});

packages/cli/commands/add/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export function getHighlighter(): Highlighter {
123123
env: (str) => pc.yellow(str),
124124
path: (str) => pc.green(str),
125125
route: (str) => pc.bold(str),
126-
website: (str) => pc.whiteBright(str)
126+
website: (str) => pc.whiteBright(str),
127+
optional: (str) => pc.gray(str)
127128
};
128129
}

packages/core/addon/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type Highlighter = {
5656
website: (str: string) => string;
5757
route: (str: string) => string;
5858
env: (str: string) => string; // used for printing environment variable names
59+
optional: (str: string) => string;
5960
};
6061

6162
export function defineAddon<Args extends OptionDefinition>(config: Addon<Args>): Addon<Args> {

0 commit comments

Comments
 (0)