|
| 1 | +import path from 'node:path' |
| 2 | +import { candidate, css, html, js, json, test, yaml } from '../utils' |
| 3 | + |
| 4 | +test( |
| 5 | + 'production build', |
| 6 | + { |
| 7 | + fs: { |
| 8 | + 'package.json': json`{}`, |
| 9 | + 'pnpm-workspace.yaml': yaml` |
| 10 | + # |
| 11 | + packages: |
| 12 | + - project-a |
| 13 | + `, |
| 14 | + 'project-a/package.json': json` |
| 15 | + { |
| 16 | + "dependencies": { |
| 17 | + "tailwindcss": "workspace:^", |
| 18 | + "@tailwindcss/cli": "workspace:^" |
| 19 | + } |
| 20 | + } |
| 21 | + `, |
| 22 | + 'project-a/index.html': html` |
| 23 | + <div |
| 24 | + class="underline 2xl:font-bold hocus:underline inverted:flex" |
| 25 | + ></div> |
| 26 | + `, |
| 27 | + 'project-a/plugin.js': js` |
| 28 | + module.exports = function ({ addVariant }) { |
| 29 | + addVariant('inverted', '@media (inverted-colors: inverted)') |
| 30 | + addVariant('hocus', ['&:focus', '&:hover']) |
| 31 | + } |
| 32 | + `, |
| 33 | + 'project-a/src/index.css': css` |
| 34 | + @import 'tailwindcss/utilities'; |
| 35 | + @content '../../project-b/src/**/*.js'; |
| 36 | + @plugin '../plugin.js'; |
| 37 | + `, |
| 38 | + 'project-a/src/index.js': js` |
| 39 | + const className = "content-['a/src/index.js']" |
| 40 | + module.exports = { className } |
| 41 | + `, |
| 42 | + 'project-b/src/index.js': js` |
| 43 | + const className = "content-['b/src/index.js']" |
| 44 | + module.exports = { className } |
| 45 | + `, |
| 46 | + }, |
| 47 | + }, |
| 48 | + async ({ root, fs, exec }) => { |
| 49 | + await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', { |
| 50 | + cwd: path.join(root, 'project-a'), |
| 51 | + }) |
| 52 | + |
| 53 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 54 | + candidate`underline`, |
| 55 | + candidate`content-['a/src/index.js']`, |
| 56 | + candidate`content-['b/src/index.js']`, |
| 57 | + candidate`inverted:flex`, |
| 58 | + candidate`hocus:underline`, |
| 59 | + ]) |
| 60 | + }, |
| 61 | +) |
| 62 | + |
| 63 | +test( |
| 64 | + 'watch mode', |
| 65 | + { |
| 66 | + fs: { |
| 67 | + 'package.json': json`{}`, |
| 68 | + 'pnpm-workspace.yaml': yaml` |
| 69 | + # |
| 70 | + packages: |
| 71 | + - project-a |
| 72 | + `, |
| 73 | + 'project-a/package.json': json` |
| 74 | + { |
| 75 | + "dependencies": { |
| 76 | + "tailwindcss": "workspace:^", |
| 77 | + "@tailwindcss/cli": "workspace:^" |
| 78 | + } |
| 79 | + } |
| 80 | + `, |
| 81 | + 'project-a/index.html': html` |
| 82 | + <div |
| 83 | + class="underline 2xl:font-bold hocus:underline inverted:flex" |
| 84 | + ></div> |
| 85 | + `, |
| 86 | + 'project-a/plugin.js': js` |
| 87 | + module.exports = function ({ addVariant }) { |
| 88 | + addVariant('inverted', '@media (inverted-colors: inverted)') |
| 89 | + addVariant('hocus', ['&:focus', '&:hover']) |
| 90 | + } |
| 91 | + `, |
| 92 | + 'project-a/src/index.css': css` |
| 93 | + @import 'tailwindcss/utilities'; |
| 94 | + @content '../../project-b/src/**/*.js'; |
| 95 | + @plugin '../plugin.js'; |
| 96 | + `, |
| 97 | + 'project-a/src/index.js': js` |
| 98 | + const className = "content-['a/src/index.js']" |
| 99 | + module.exports = { className } |
| 100 | + `, |
| 101 | + 'project-b/src/index.js': js` |
| 102 | + const className = "content-['b/src/index.js']" |
| 103 | + module.exports = { className } |
| 104 | + `, |
| 105 | + }, |
| 106 | + }, |
| 107 | + async ({ root, fs, spawn }) => { |
| 108 | + await spawn('pnpm tailwindcss --input src/index.css --output dist/out.css --watch', { |
| 109 | + cwd: path.join(root, 'project-a'), |
| 110 | + }) |
| 111 | + |
| 112 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 113 | + candidate`underline`, |
| 114 | + candidate`content-['a/src/index.js']`, |
| 115 | + candidate`content-['b/src/index.js']`, |
| 116 | + candidate`inverted:flex`, |
| 117 | + candidate`hocus:underline`, |
| 118 | + ]) |
| 119 | + |
| 120 | + await fs.write( |
| 121 | + 'project-a/src/index.js', |
| 122 | + js` |
| 123 | + const className = "[.changed_&]:content-['project-a/src/index.js']" |
| 124 | + module.exports = { className } |
| 125 | + `, |
| 126 | + ) |
| 127 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 128 | + candidate`[.changed_&]:content-['project-a/src/index.js']`, |
| 129 | + ]) |
| 130 | + |
| 131 | + await fs.write( |
| 132 | + 'project-b/src/index.js', |
| 133 | + js` |
| 134 | + const className = "[.changed_&]:content-['project-b/src/index.js']" |
| 135 | + module.exports = { className } |
| 136 | + `, |
| 137 | + ) |
| 138 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 139 | + candidate`[.changed_&]:content-['project-b/src/index.js']`, |
| 140 | + ]) |
| 141 | + }, |
| 142 | +) |
0 commit comments