|
| 1 | +import { expectFileToMatch, moveFile, writeFile } from '../../../utils/fs'; |
| 2 | +import { installPackage } from '../../../utils/packages'; |
| 3 | +import { ng, silentExec } from '../../../utils/process'; |
| 4 | +import { updateJsonFile } from '../../../utils/project'; |
| 5 | +import { expectToFail } from '../../../utils/utils'; |
| 6 | + |
| 7 | +export default async function () { |
| 8 | + // Temporarily turn off caching until the build cache accounts for the presence of tailwind |
| 9 | + // and its configuration file. Otherwise cached builds without tailwind will cause test failures. |
| 10 | + await ng('cache', 'off'); |
| 11 | + |
| 12 | + // Add type module in package.json. |
| 13 | + await updateJsonFile('package.json', (json) => { |
| 14 | + json['type'] = 'module'; |
| 15 | + }); |
| 16 | + |
| 17 | + // Install Tailwind |
| 18 | + await installPackage('tailwindcss@3'); |
| 19 | + |
| 20 | + // Create configuration file |
| 21 | + await silentExec('npx', 'tailwindcss', 'init'); |
| 22 | + |
| 23 | + // tailwind doesn't create the config file with a cjs extension. |
| 24 | + // We need to rename it manually until |
| 25 | + // https://github.com/tailwindlabs/tailwindcss/commit/6c63f67d20c433b5c7281e9e26744038ed41ccc2 is released. |
| 26 | + await moveFile('tailwind.config.js', 'tailwind.config.cjs'); |
| 27 | + |
| 28 | + // Add Tailwind directives to a global style |
| 29 | + await writeFile('src/styles.css', '@tailwind base; @tailwind components;'); |
| 30 | + |
| 31 | + // Build should succeed and process Tailwind directives |
| 32 | + await ng('build', '--configuration=development'); |
| 33 | + |
| 34 | + // Check for Tailwind output |
| 35 | + await expectFileToMatch('dist/test-project/styles.css', /::placeholder/); |
| 36 | + await expectToFail(() => |
| 37 | + expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;'), |
| 38 | + ); |
| 39 | +} |
0 commit comments