@@ -2776,6 +2776,123 @@ test(
27762776 } ,
27772777)
27782778
2779+ test (
2780+ 'upgrades are idempotent, and can run on v4 projects' ,
2781+ {
2782+ fs : {
2783+ 'package.json' : json `
2784+ {
2785+ "dependencies": {
2786+ "tailwindcss": "^3",
2787+ "@tailwindcss/upgrade": "workspace:^"
2788+ },
2789+ "devDependencies": {
2790+ "@tailwindcss/cli": "workspace:^"
2791+ }
2792+ }
2793+ ` ,
2794+ 'tailwind.config.js' : js `
2795+ /** @type {import('tailwindcss').Config} */
2796+ module.exports = {
2797+ content: [' ./ src/**/ * .{html , js }'],
2798+ }
2799+ ` ,
2800+ 'src/index.html' : html `
2801+ <div class="ring"></div>
2802+ ` ,
2803+ 'src/input.css' : css `
2804+ @tailwind base;
2805+ @tailwind components;
2806+ @tailwind utilities;
2807+
2808+ .foo {
2809+ @apply !bg-[var(--my-color)] rounded;
2810+ }
2811+ ` ,
2812+ } ,
2813+ } ,
2814+ async ( { exec, fs, expect } ) => {
2815+ await exec ( 'npx @tailwindcss/upgrade' )
2816+
2817+ let before = await fs . dumpFiles ( './src/**/*.{css,html}' )
2818+ expect ( before ) . toMatchInlineSnapshot ( `
2819+ "
2820+ --- ./src/index.html ---
2821+ <div class="ring-3"></div>
2822+
2823+ --- ./src/input.css ---
2824+ @import 'tailwindcss';
2825+
2826+ /*
2827+ The default border color has changed to \`currentcolor\` in Tailwind CSS v4,
2828+ so we've added these compatibility styles to make sure everything still
2829+ looks the same as it did with Tailwind CSS v3.
2830+
2831+ If we ever want to remove these styles, we need to add an explicit border
2832+ color utility to any element that depends on these defaults.
2833+ */
2834+ @layer base {
2835+ *,
2836+ ::after,
2837+ ::before,
2838+ ::backdrop,
2839+ ::file-selector-button {
2840+ border-color: var(--color-gray-200, currentcolor);
2841+ }
2842+ }
2843+
2844+ .foo {
2845+ @apply bg-(--my-color)! rounded-sm;
2846+ }
2847+ "
2848+ ` )
2849+
2850+ // Commit the changes
2851+ await exec ( 'git add .' )
2852+ await exec ( 'git commit -m "upgrade"' )
2853+
2854+ // Run the upgrade again
2855+ let output = await exec ( 'npx @tailwindcss/upgrade' )
2856+ expect ( output ) . toContain ( 'No changes were made to your repository' )
2857+
2858+ let after = await fs . dumpFiles ( './src/**/*.{css,html}' )
2859+ expect ( after ) . toMatchInlineSnapshot ( `
2860+ "
2861+ --- ./src/index.html ---
2862+ <div class="ring-3"></div>
2863+
2864+ --- ./src/input.css ---
2865+ @import 'tailwindcss';
2866+
2867+ /*
2868+ The default border color has changed to \`currentcolor\` in Tailwind CSS v4,
2869+ so we've added these compatibility styles to make sure everything still
2870+ looks the same as it did with Tailwind CSS v3.
2871+
2872+ If we ever want to remove these styles, we need to add an explicit border
2873+ color utility to any element that depends on these defaults.
2874+ */
2875+ @layer base {
2876+ *,
2877+ ::after,
2878+ ::before,
2879+ ::backdrop,
2880+ ::file-selector-button {
2881+ border-color: var(--color-gray-200, currentcolor);
2882+ }
2883+ }
2884+
2885+ .foo {
2886+ @apply bg-(--my-color)! rounded-sm;
2887+ }
2888+ "
2889+ ` )
2890+
2891+ // Ensure the file system is in the same state
2892+ expect ( before ) . toEqual ( after )
2893+ } ,
2894+ )
2895+
27792896function withBOM ( text : string ) : string {
27802897 return '\uFEFF' + text
27812898}
0 commit comments