|
| 1 | +import { stripVTControlCharacters } from 'node:util' |
| 2 | +// @ts-expect-error This path does exist |
| 3 | +import { version } from '../../packages/tailwindcss/package.json' |
| 4 | +import { css, html, js, json, test } from '../utils' |
| 5 | + |
| 6 | +test( |
| 7 | + 'upgrades half-upgraded v3 project to v4 (pnpm)', |
| 8 | + { |
| 9 | + fs: { |
| 10 | + 'package.json': json` |
| 11 | + { |
| 12 | + "dependencies": { |
| 13 | + "tailwindcss": "^3", |
| 14 | + "@tailwindcss/upgrade": "workspace:^" |
| 15 | + }, |
| 16 | + "devDependencies": { |
| 17 | + "@tailwindcss/cli": "workspace:^" |
| 18 | + } |
| 19 | + } |
| 20 | + `, |
| 21 | + 'tailwind.config.js': js` |
| 22 | + /** @type {import('tailwindcss').Config} */ |
| 23 | + module.exports = { |
| 24 | + content: ['./src/**/*.{html,js}'], |
| 25 | + } |
| 26 | + `, |
| 27 | + 'src/index.html': html` |
| 28 | + <div class="!flex">Hello World</div> |
| 29 | + `, |
| 30 | + 'src/input.css': css` |
| 31 | + @tailwind base; |
| 32 | + @tailwind components; |
| 33 | + @tailwind utilities; |
| 34 | + `, |
| 35 | + }, |
| 36 | + }, |
| 37 | + async ({ exec, expect }) => { |
| 38 | + // Ensure we are in a git repo |
| 39 | + await exec('git init') |
| 40 | + await exec('git add --all') |
| 41 | + await exec('git commit -m "before migration"') |
| 42 | + |
| 43 | + // Fully upgrade to v4 |
| 44 | + await exec('npx @tailwindcss/upgrade') |
| 45 | + |
| 46 | + // Undo all changes to the current repo. This will bring the repo back to a |
| 47 | + // v3 state, but the `node_modules` will now have v4 installed. |
| 48 | + await exec('git reset --hard HEAD') |
| 49 | + |
| 50 | + // Re-running the upgrade should result in an error |
| 51 | + return expect(() => { |
| 52 | + return exec('npx @tailwindcss/upgrade', {}, { ignoreStdErr: true }).catch((e) => { |
| 53 | + // Replacing the current version with a hardcoded `v4` to make it stable |
| 54 | + // when we release new minor/patch versions. |
| 55 | + return Promise.reject(stripVTControlCharacters(e.message.replaceAll(version, '4.0.0'))) |
| 56 | + }) |
| 57 | + }).rejects.toThrowErrorMatchingInlineSnapshot(` |
| 58 | + "Command failed: npx @tailwindcss/upgrade |
| 59 | + ≈ tailwindcss v4.0.0 |
| 60 | +
|
| 61 | + │ ↳ Upgrading from Tailwind CSS \`v4.0.0\` |
| 62 | +
|
| 63 | + │ ↳ Version mismatch |
| 64 | + │ |
| 65 | + │ \`\`\`diff |
| 66 | + │ - "tailwindcss": "^3" (expected version in package.json / lockfile) |
| 67 | + │ + "tailwindcss": "4.0.0" (installed version in \`node_modules\`) |
| 68 | + │ \`\`\` |
| 69 | + │ |
| 70 | + │ Make sure to run \`pnpm install\`, and try again. |
| 71 | +
|
| 72 | + " |
| 73 | + `) |
| 74 | + }, |
| 75 | +) |
| 76 | + |
| 77 | +test( |
| 78 | + 'upgrades half-upgraded v3 project to v4 (bun)', |
| 79 | + { |
| 80 | + fs: { |
| 81 | + 'package.json': json` |
| 82 | + { |
| 83 | + "dependencies": { |
| 84 | + "tailwindcss": "^3", |
| 85 | + "@tailwindcss/upgrade": "workspace:^" |
| 86 | + }, |
| 87 | + "devDependencies": { |
| 88 | + "@tailwindcss/cli": "workspace:^", |
| 89 | + "bun": "^1.0.0" |
| 90 | + } |
| 91 | + } |
| 92 | + `, |
| 93 | + 'tailwind.config.js': js` |
| 94 | + /** @type {import('tailwindcss').Config} */ |
| 95 | + module.exports = { |
| 96 | + content: ['./src/**/*.{html,js}'], |
| 97 | + } |
| 98 | + `, |
| 99 | + 'src/index.html': html` |
| 100 | + <div class="!flex">Hello World</div> |
| 101 | + `, |
| 102 | + 'src/input.css': css` |
| 103 | + @tailwind base; |
| 104 | + @tailwind components; |
| 105 | + @tailwind utilities; |
| 106 | + `, |
| 107 | + }, |
| 108 | + }, |
| 109 | + async ({ exec, expect }) => { |
| 110 | + // Use `bun` to install dependencies |
| 111 | + await exec('rm ./pnpm-lock.yaml') |
| 112 | + await exec('npx bun install') |
| 113 | + |
| 114 | + // Ensure we are in a git repo |
| 115 | + await exec('git init') |
| 116 | + await exec('git add --all') |
| 117 | + await exec('git commit -m "before migration"') |
| 118 | + |
| 119 | + // Fully upgrade to v4 |
| 120 | + await exec('npx @tailwindcss/upgrade') |
| 121 | + |
| 122 | + // Undo all changes to the current repo. This will bring the repo back to a |
| 123 | + // v3 state, but the `node_modules` will now have v4 installed. |
| 124 | + await exec('git reset --hard HEAD') |
| 125 | + |
| 126 | + // Re-running the upgrade should result in an error |
| 127 | + return expect(() => { |
| 128 | + return exec('npx @tailwindcss/upgrade', {}, { ignoreStdErr: true }).catch((e) => { |
| 129 | + // Replacing the current version with a hardcoded `v4` to make it stable |
| 130 | + // when we release new minor/patch versions. |
| 131 | + return Promise.reject(stripVTControlCharacters(e.message.replaceAll(version, '4.0.0'))) |
| 132 | + }) |
| 133 | + }).rejects.toThrowErrorMatchingInlineSnapshot(` |
| 134 | + "Command failed: npx @tailwindcss/upgrade |
| 135 | + ≈ tailwindcss v4.0.0 |
| 136 | +
|
| 137 | + │ ↳ Upgrading from Tailwind CSS \`v4.0.0\` |
| 138 | +
|
| 139 | + │ ↳ Version mismatch |
| 140 | + │ |
| 141 | + │ \`\`\`diff |
| 142 | + │ - "tailwindcss": "^3" (expected version in package.json / lockfile) |
| 143 | + │ + "tailwindcss": "4.0.0" (installed version in \`node_modules\`) |
| 144 | + │ \`\`\` |
| 145 | + │ |
| 146 | + │ Make sure to run \`bun install\`, and try again. |
| 147 | +
|
| 148 | + " |
| 149 | + `) |
| 150 | + }, |
| 151 | +) |
| 152 | + |
| 153 | +test( |
| 154 | + 'upgrades half-upgraded v3 project to v4 (npm)', |
| 155 | + { |
| 156 | + fs: { |
| 157 | + 'package.json': json` |
| 158 | + { |
| 159 | + "dependencies": { |
| 160 | + "tailwindcss": "^3", |
| 161 | + "@tailwindcss/upgrade": "workspace:^" |
| 162 | + }, |
| 163 | + "devDependencies": { |
| 164 | + "@tailwindcss/cli": "workspace:^" |
| 165 | + } |
| 166 | + } |
| 167 | + `, |
| 168 | + 'tailwind.config.js': js` |
| 169 | + /** @type {import('tailwindcss').Config} */ |
| 170 | + module.exports = { |
| 171 | + content: ['./src/**/*.{html,js}'], |
| 172 | + } |
| 173 | + `, |
| 174 | + 'src/index.html': html` |
| 175 | + <div class="!flex">Hello World</div> |
| 176 | + `, |
| 177 | + 'src/input.css': css` |
| 178 | + @tailwind base; |
| 179 | + @tailwind components; |
| 180 | + @tailwind utilities; |
| 181 | + `, |
| 182 | + }, |
| 183 | + }, |
| 184 | + async ({ exec, expect }) => { |
| 185 | + // Use `bun` to install dependencies |
| 186 | + await exec('rm ./pnpm-lock.yaml') |
| 187 | + await exec('rm -rf ./node_modules') |
| 188 | + await exec('npm install') |
| 189 | + |
| 190 | + // Ensure we are in a git repo |
| 191 | + await exec('git init') |
| 192 | + await exec('git add --all') |
| 193 | + await exec('git commit -m "before migration"') |
| 194 | + |
| 195 | + // Fully upgrade to v4 |
| 196 | + await exec('npx @tailwindcss/upgrade') |
| 197 | + |
| 198 | + // Undo all changes to the current repo. This will bring the repo back to a |
| 199 | + // v3 state, but the `node_modules` will now have v4 installed. |
| 200 | + await exec('git reset --hard HEAD') |
| 201 | + |
| 202 | + // Re-running the upgrade should result in an error |
| 203 | + return expect(() => { |
| 204 | + return exec('npx @tailwindcss/upgrade', {}, { ignoreStdErr: true }).catch((e) => { |
| 205 | + // Replacing the current version with a hardcoded `v4` to make it stable |
| 206 | + // when we release new minor/patch versions. |
| 207 | + return Promise.reject(stripVTControlCharacters(e.message.replaceAll(version, '4.0.0'))) |
| 208 | + }) |
| 209 | + }).rejects.toThrowErrorMatchingInlineSnapshot(` |
| 210 | + "Command failed: npx @tailwindcss/upgrade |
| 211 | + ≈ tailwindcss v4.0.0 |
| 212 | +
|
| 213 | + │ ↳ Upgrading from Tailwind CSS \`v4.0.0\` |
| 214 | +
|
| 215 | + │ ↳ Version mismatch |
| 216 | + │ |
| 217 | + │ \`\`\`diff |
| 218 | + │ - "tailwindcss": "^3" (expected version in package.json / lockfile) |
| 219 | + │ + "tailwindcss": "4.0.0" (installed version in \`node_modules\`) |
| 220 | + │ \`\`\` |
| 221 | + │ |
| 222 | + │ Make sure to run \`npm install\`, and try again. |
| 223 | +
|
| 224 | + " |
| 225 | + `) |
| 226 | + }, |
| 227 | +) |
0 commit comments