|
| 1 | +let $ = require('../../execute') |
| 2 | +let { css, html, javascript } = require('../../syntax') |
| 3 | + |
| 4 | +let { |
| 5 | + readOutputFile, |
| 6 | + appendToInputFile, |
| 7 | + writeInputFile, |
| 8 | + waitForOutputFileCreation, |
| 9 | + waitForOutputFileChange, |
| 10 | +} = require('../../io')({ output: 'dist', input: 'src' }) |
| 11 | + |
| 12 | +describe('static build', () => { |
| 13 | + it('should be possible to generate tailwind output', async () => { |
| 14 | + await writeInputFile('index.html', html`<div class="font-bold"></div>`) |
| 15 | + |
| 16 | + await $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css', { |
| 17 | + env: { NODE_ENV: 'production' }, |
| 18 | + }) |
| 19 | + |
| 20 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 21 | + css` |
| 22 | + .font-bold { |
| 23 | + font-weight: 700; |
| 24 | + } |
| 25 | + ` |
| 26 | + ) |
| 27 | + }) |
| 28 | +}) |
| 29 | + |
| 30 | +describe('watcher', () => { |
| 31 | + test('classes are generated when the html file changes', async () => { |
| 32 | + await writeInputFile('index.html', html`<div class="font-bold"></div>`) |
| 33 | + |
| 34 | + let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w') |
| 35 | + |
| 36 | + await waitForOutputFileCreation('main.css') |
| 37 | + |
| 38 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 39 | + css` |
| 40 | + .font-bold { |
| 41 | + font-weight: 700; |
| 42 | + } |
| 43 | + ` |
| 44 | + ) |
| 45 | + |
| 46 | + await waitForOutputFileChange('main.css', async () => { |
| 47 | + await appendToInputFile('index.html', html`<div class="font-normal"></div>`) |
| 48 | + }) |
| 49 | + |
| 50 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 51 | + css` |
| 52 | + .font-bold { |
| 53 | + font-weight: 700; |
| 54 | + } |
| 55 | + .font-normal { |
| 56 | + font-weight: 400; |
| 57 | + } |
| 58 | + ` |
| 59 | + ) |
| 60 | + |
| 61 | + await waitForOutputFileChange('main.css', async () => { |
| 62 | + await appendToInputFile('index.html', html`<div class="bg-red-500"></div>`) |
| 63 | + }) |
| 64 | + |
| 65 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 66 | + css` |
| 67 | + .bg-red-500 { |
| 68 | + --tw-bg-opacity: 1; |
| 69 | + background-color: rgba(239, 68, 68, var(--tw-bg-opacity)); |
| 70 | + } |
| 71 | + .font-bold { |
| 72 | + font-weight: 700; |
| 73 | + } |
| 74 | + .font-normal { |
| 75 | + font-weight: 400; |
| 76 | + } |
| 77 | + ` |
| 78 | + ) |
| 79 | + |
| 80 | + return runningProcess.stop() |
| 81 | + }) |
| 82 | + |
| 83 | + test('classes are generated when the tailwind.config.js file changes', async () => { |
| 84 | + await writeInputFile('index.html', html`<div class="font-bold md:font-medium"></div>`) |
| 85 | + |
| 86 | + let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w') |
| 87 | + |
| 88 | + await waitForOutputFileCreation('main.css') |
| 89 | + |
| 90 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 91 | + css` |
| 92 | + .font-bold { |
| 93 | + font-weight: 700; |
| 94 | + } |
| 95 | + @media (min-width: 768px) { |
| 96 | + .md\\:font-medium { |
| 97 | + font-weight: 500; |
| 98 | + } |
| 99 | + } |
| 100 | + ` |
| 101 | + ) |
| 102 | + |
| 103 | + await waitForOutputFileChange('main.css', async () => { |
| 104 | + await writeInputFile( |
| 105 | + '../tailwind.config.js', |
| 106 | + javascript` |
| 107 | + module.exports = { |
| 108 | + purge: ['./src/index.html'], |
| 109 | + mode: 'jit', |
| 110 | + darkMode: false, // or 'media' or 'class' |
| 111 | + theme: { |
| 112 | + extend: { |
| 113 | + screens: { |
| 114 | + md: '800px' |
| 115 | + }, |
| 116 | + fontWeight: { |
| 117 | + bold: 'bold' |
| 118 | + } |
| 119 | + }, |
| 120 | + }, |
| 121 | + variants: { |
| 122 | + extend: {}, |
| 123 | + }, |
| 124 | + corePlugins: { |
| 125 | + preflight: false, |
| 126 | + }, |
| 127 | + plugins: [], |
| 128 | + } |
| 129 | + ` |
| 130 | + ) |
| 131 | + }) |
| 132 | + |
| 133 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 134 | + css` |
| 135 | + .font-bold { |
| 136 | + font-weight: bold; |
| 137 | + } |
| 138 | + @media (min-width: 800px) { |
| 139 | + .md\\:font-medium { |
| 140 | + font-weight: 500; |
| 141 | + } |
| 142 | + } |
| 143 | + ` |
| 144 | + ) |
| 145 | + |
| 146 | + return runningProcess.stop() |
| 147 | + }) |
| 148 | + |
| 149 | + test('classes are generated when the index.css file changes', async () => { |
| 150 | + await writeInputFile('index.html', html`<div class="font-bold btn"></div>`) |
| 151 | + |
| 152 | + let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w') |
| 153 | + |
| 154 | + await waitForOutputFileCreation('main.css') |
| 155 | + |
| 156 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 157 | + css` |
| 158 | + .font-bold { |
| 159 | + font-weight: 700; |
| 160 | + } |
| 161 | + ` |
| 162 | + ) |
| 163 | + |
| 164 | + await waitForOutputFileChange('main.css', async () => { |
| 165 | + await writeInputFile( |
| 166 | + 'index.css', |
| 167 | + css` |
| 168 | + @tailwind base; |
| 169 | + @tailwind components; |
| 170 | + @tailwind utilities; |
| 171 | +
|
| 172 | + @layer components { |
| 173 | + .btn { |
| 174 | + @apply px-2 py-1 rounded; |
| 175 | + } |
| 176 | + } |
| 177 | + ` |
| 178 | + ) |
| 179 | + }) |
| 180 | + |
| 181 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 182 | + css` |
| 183 | + .btn { |
| 184 | + border-radius: 0.25rem; |
| 185 | + padding-left: 0.5rem; |
| 186 | + padding-right: 0.5rem; |
| 187 | + padding-top: 0.25rem; |
| 188 | + padding-bottom: 0.25rem; |
| 189 | + } |
| 190 | + .font-bold { |
| 191 | + font-weight: 700; |
| 192 | + } |
| 193 | + ` |
| 194 | + ) |
| 195 | + |
| 196 | + await waitForOutputFileChange('main.css', async () => { |
| 197 | + await writeInputFile( |
| 198 | + 'index.css', |
| 199 | + css` |
| 200 | + @tailwind base; |
| 201 | + @tailwind components; |
| 202 | + @tailwind utilities; |
| 203 | +
|
| 204 | + @layer components { |
| 205 | + .btn { |
| 206 | + @apply px-2 py-1 rounded bg-red-500; |
| 207 | + } |
| 208 | + } |
| 209 | + ` |
| 210 | + ) |
| 211 | + }) |
| 212 | + |
| 213 | + expect(await readOutputFile('main.css')).toIncludeCss( |
| 214 | + css` |
| 215 | + .btn { |
| 216 | + border-radius: 0.25rem; |
| 217 | + --tw-bg-opacity: 1; |
| 218 | + background-color: rgba(239, 68, 68, var(--tw-bg-opacity)); |
| 219 | + padding-left: 0.5rem; |
| 220 | + padding-right: 0.5rem; |
| 221 | + padding-top: 0.25rem; |
| 222 | + padding-bottom: 0.25rem; |
| 223 | + } |
| 224 | + .font-bold { |
| 225 | + font-weight: 700; |
| 226 | + } |
| 227 | + ` |
| 228 | + ) |
| 229 | + |
| 230 | + return runningProcess.stop() |
| 231 | + }) |
| 232 | +}) |
0 commit comments