Skip to content

Commit aadc926

Browse files
committed
add test to ensure upgrade runs on v4 projects
And actually applies changes where it can. It will also ignore unsafe migrations such as variant order and `rounded` -> `rounded-sm`.
1 parent 37323c6 commit aadc926

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

integrations/upgrade/index.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,68 @@ test(
28932893
},
28942894
)
28952895
2896+
test(
2897+
'upgrades run on v4 projects',
2898+
{
2899+
fs: {
2900+
'package.json': json`
2901+
{
2902+
"dependencies": {
2903+
"tailwindcss": "^4",
2904+
"@tailwindcss/upgrade": "workspace:^"
2905+
},
2906+
"devDependencies": {
2907+
"@tailwindcss/cli": "workspace:^"
2908+
}
2909+
}
2910+
`,
2911+
'src/index.html': html`
2912+
<!-- Migrating 'ring', 'rounded' and 'outline-none' are unsafe in v4 -> v4 migrations -->
2913+
<div class="ring rounded outline"></div>
2914+
2915+
<!-- Variant order is also unsafe to change in v4 projects -->
2916+
<div class="file:hover:flex *:hover:flex"></div>
2917+
<div class="hover:file:flex hover:*:flex"></div>
2918+
2919+
<!-- These are safe to migrate: -->
2920+
<div class="!flex bg-red-500/[var(--my-opacity)] [@media(pointer:fine)]:flex"></div>
2921+
`,
2922+
'src/input.css': css`
2923+
@import 'tailwindcss';
2924+
2925+
.foo {
2926+
@apply !bg-[var(--my-color)];
2927+
}
2928+
`,
2929+
},
2930+
},
2931+
async ({ exec, fs, expect }) => {
2932+
await exec('npx @tailwindcss/upgrade')
2933+
2934+
expect(await fs.dumpFiles('./src/**/*.{css,html}')).toMatchInlineSnapshot(`
2935+
"
2936+
--- ./src/index.html ---
2937+
<!-- Migrating 'ring', 'rounded' and 'outline-none' are unsafe in v4 -> v4 migrations -->
2938+
<div class="ring rounded outline"></div>
2939+
2940+
<!-- Variant order is also unsafe to change in v4 projects -->
2941+
<div class="file:hover:flex *:hover:flex"></div>
2942+
<div class="hover:file:flex hover:*:flex"></div>
2943+
2944+
<!-- These are safe to migrate: -->
2945+
<div class="flex! bg-red-500/(--my-opacity) pointer-fine:flex"></div>
2946+
2947+
--- ./src/input.css ---
2948+
@import 'tailwindcss';
2949+
2950+
.foo {
2951+
@apply bg-(--my-color)!;
2952+
}
2953+
"
2954+
`)
2955+
},
2956+
)
2957+
28962958
function withBOM(text: string): string {
28972959
return '\uFEFF' + text
28982960
}

0 commit comments

Comments
 (0)