|
| 1 | +import { candidate, css, fetchStyles, html, js, retryAssertion, test, ts, txt } from '../utils' |
| 2 | + |
| 3 | +const WORKSPACE = { |
| 4 | + fs: { |
| 5 | + 'package.json': txt` |
| 6 | + { |
| 7 | + "type": "module", |
| 8 | + "dependencies": { |
| 9 | + "tailwind-merge": "^2", |
| 10 | + "@tailwindcss/vite": "workspace:^", |
| 11 | + "tailwindcss": "workspace:^" |
| 12 | + }, |
| 13 | + "devDependencies": { |
| 14 | + "vite": "^6" |
| 15 | + } |
| 16 | + } |
| 17 | + `, |
| 18 | + 'vite.config.ts': ts` |
| 19 | + import tailwindcss from '@tailwindcss/vite' |
| 20 | + import { defineConfig } from 'vite' |
| 21 | +
|
| 22 | + export default defineConfig({ |
| 23 | + build: { cssMinify: false }, |
| 24 | + plugins: [tailwindcss()], |
| 25 | + }) |
| 26 | + `, |
| 27 | + 'index.html': html` |
| 28 | + <head> |
| 29 | + <link rel="stylesheet" href="./src/index.css" /> |
| 30 | + <script type="module" src="./src/index.js"></script> |
| 31 | + </head> |
| 32 | + `, |
| 33 | + 'src/index.js': js` |
| 34 | + import { twMerge } from 'tailwind-merge' |
| 35 | +
|
| 36 | + twMerge('underline') |
| 37 | +
|
| 38 | + console.log('underline') |
| 39 | + `, |
| 40 | + 'src/index.css': css`@import 'tailwindcss/utilities' layer(utilities);`, |
| 41 | + }, |
| 42 | +} |
| 43 | + |
| 44 | +test( |
| 45 | + 'does not scan tailwind-merge in production builds', |
| 46 | + WORKSPACE, |
| 47 | + async ({ fs, exec, expect }) => { |
| 48 | + await exec('pnpm vite build') |
| 49 | + |
| 50 | + let files = await fs.glob('dist/**/*.css') |
| 51 | + expect(files).toHaveLength(1) |
| 52 | + let [, content] = files[0] |
| 53 | + |
| 54 | + expect(content).toMatchInlineSnapshot(` |
| 55 | + "@layer utilities { |
| 56 | + .underline { |
| 57 | + text-decoration-line: underline; |
| 58 | + } |
| 59 | + } |
| 60 | + " |
| 61 | + `) |
| 62 | + }, |
| 63 | +) |
| 64 | + |
| 65 | +test('does not scan tailwind-merge in dev builds', WORKSPACE, async ({ spawn, expect }) => { |
| 66 | + let process = await spawn('pnpm vite dev') |
| 67 | + await process.onStdout((m) => m.includes('ready in')) |
| 68 | + |
| 69 | + let url = '' |
| 70 | + await process.onStdout((m) => { |
| 71 | + let match = /Local:\s*(http.*)\//.exec(m) |
| 72 | + if (match) url = match[1] |
| 73 | + return Boolean(url) |
| 74 | + }) |
| 75 | + |
| 76 | + await retryAssertion(async () => { |
| 77 | + let styles = await fetchStyles(url, '/index.html') |
| 78 | + |
| 79 | + expect(styles).not.toContain(candidate`flex`) |
| 80 | + }) |
| 81 | +}) |
0 commit comments