|
| 1 | +import { deleteFile, expectFileToMatch, writeFile } from '../../../utils/fs'; |
| 2 | +import { installPackage, uninstallPackage } from '../../../utils/packages'; |
| 3 | +import { ng, silentExec } from '../../../utils/process'; |
| 4 | +import { expectToFail } from '../../../utils/utils'; |
| 5 | + |
| 6 | +export default async function () { |
| 7 | + // Install Tailwind |
| 8 | + await installPackage('tailwindcss@3'); |
| 9 | + |
| 10 | + // Create configuration file |
| 11 | + await silentExec('npx', 'tailwindcss', 'init'); |
| 12 | + |
| 13 | + // Add Tailwind directives to a component style |
| 14 | + await writeFile('src/app/app.component.css', '@tailwind base; @tailwind components;'); |
| 15 | + |
| 16 | + // Add Tailwind directives to a global style |
| 17 | + await writeFile('src/styles.css', '@tailwind base; @tailwind components;'); |
| 18 | + |
| 19 | + // Build should succeed and process Tailwind directives |
| 20 | + await ng('build', '--configuration=development'); |
| 21 | + |
| 22 | + // Check for Tailwind output |
| 23 | + await expectFileToMatch('dist/test-project/styles.css', /::placeholder/); |
| 24 | + await expectFileToMatch('dist/test-project/main.js', /::placeholder/); |
| 25 | + await expectToFail(() => |
| 26 | + expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;'), |
| 27 | + ); |
| 28 | + await expectToFail(() => |
| 29 | + expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;'), |
| 30 | + ); |
| 31 | + |
| 32 | + // Remove configuration file |
| 33 | + await deleteFile('tailwind.config.js'); |
| 34 | + |
| 35 | + // Ensure Tailwind is disabled when no configuration file is present |
| 36 | + await ng('build', '--configuration=development'); |
| 37 | + await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;'); |
| 38 | + await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;'); |
| 39 | + |
| 40 | + // Recreate configuration file |
| 41 | + await silentExec('npx', 'tailwindcss', 'init'); |
| 42 | + |
| 43 | + // Uninstall Tailwind |
| 44 | + await uninstallPackage('tailwindcss'); |
| 45 | + |
| 46 | + // Ensure installation warning is present |
| 47 | + const { stderr } = await ng('build', '--configuration=development'); |
| 48 | + if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) { |
| 49 | + throw new Error('Expected tailwind installation warning'); |
| 50 | + } |
| 51 | + |
| 52 | + // Tailwind directives should be unprocessed with missing package |
| 53 | + await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;'); |
| 54 | + await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;'); |
| 55 | +} |
0 commit comments