Skip to content

Commit 48f68b7

Browse files
committed
improve reproduction integration tests
1 parent 3e6e0ec commit 48f68b7

File tree

2 files changed

+82
-16
lines changed

2 files changed

+82
-16
lines changed

integrations/cli/index.test.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,3 +992,78 @@ test(
992992
`)
993993
},
994994
)
995+
996+
test(
997+
'https://github.com/tailwindlabs/tailwindcss/issues/15148',
998+
{
999+
fs: {
1000+
'package.json': json`
1001+
{
1002+
"type": "module",
1003+
"dependencies": {
1004+
"tailwindcss": "workspace:^",
1005+
"@tailwindcss/cli": "workspace:^"
1006+
}
1007+
}
1008+
`,
1009+
'index.css': css`
1010+
@import 'tailwindcss';
1011+
@utility test-a {
1012+
color: red;
1013+
}
1014+
@utility test-b {
1015+
color: green;
1016+
}
1017+
@utility test-c {
1018+
color: blue;
1019+
}
1020+
@utility test-d {
1021+
color: tomato;
1022+
}
1023+
`,
1024+
'app.js': js`
1025+
const classes = [
1026+
'test-a',
1027+
'test-b',
1028+
'test-c',
1029+
'test-d',
1030+
'multiple-entries-to-keep-newlines',
1031+
'multiple-entries-to-keep-newlines',
1032+
'multiple-entries-to-keep-newlines',
1033+
'multiple-entries-to-keep-newlines',
1034+
'multiple-entries-to-keep-newlines',
1035+
'multiple-entries-to-keep-newlines',
1036+
'multiple-entries-to-keep-newlines',
1037+
'multiple-entries-to-keep-newlines',
1038+
'multiple-entries-to-keep-newlines',
1039+
'multiple-entries-to-keep-newlines',
1040+
'multiple-entries-to-keep-newlines',
1041+
'multiple-entries-to-keep-newlines',
1042+
'multiple-entries-to-keep-newlines',
1043+
'multiple-entries-to-keep-newlines',
1044+
'multiple-entries-to-keep-newlines',
1045+
'multiple-entries-to-keep-newlines',
1046+
]
1047+
`
1048+
// The original test case used Svelte, Vite, etc… The issue is caused by
1049+
// the fact that output from the compiler is what is/was scanned by Oxide.
1050+
// The Svelte compiler uses tabs for indents instead of spaces which was
1051+
// the actual cause of the bug. It could be reproduced in the CLI just by
1052+
// using tabs
1053+
.replace(/\[[\s\S]*\]/gm, (m) => m.replace(/\s+/g, '\t')),
1054+
},
1055+
},
1056+
async ({ fs, exec }) => {
1057+
await exec('pnpm tailwindcss --input index.css --output dist/out.css')
1058+
1059+
let files = await fs.glob('dist/**/*.css')
1060+
expect(files).toHaveLength(1)
1061+
1062+
await fs.expectFileToContain(files[0][0], [
1063+
candidate`test-a`,
1064+
candidate`test-b`,
1065+
candidate`test-c`,
1066+
candidate`test-d`,
1067+
])
1068+
},
1069+
)

integrations/vite/svelte.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'vitest'
2-
import { candidate, css, html, js, json, retryAssertion, test, ts } from '../utils'
2+
import { candidate, css, html, json, retryAssertion, test, ts } from '../utils'
33

44
test(
55
'production build',
@@ -253,6 +253,9 @@ test(
253253
},
254254
)
255255

256+
// Context: when using `svelte()` before `tailwindcss()` it means that
257+
// `tailwindcss()` sees the contents after the svelte compiler ran. The svelte
258+
// compiler outputs tabs instead of spaces which we didn't handle correctly.
256259
test(
257260
'https://github.com/tailwindlabs/tailwindcss/issues/15148',
258261
{
@@ -275,22 +278,13 @@ test(
275278
'vite.config.ts': ts`
276279
import { defineConfig } from 'vite'
277280
import tailwindcss from '@tailwindcss/vite'
278-
import { svelte } from '@sveltejs/vite-plugin-svelte'
281+
import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte'
279282
280283
// https://vite.dev/config/
281284
export default defineConfig({
282-
plugins: [svelte(), tailwindcss()],
285+
plugins: [svelte({ preprocess: [vitePreprocess()] }), tailwindcss()],
283286
})
284287
`,
285-
'svelte.config.js': js`
286-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
287-
288-
export default {
289-
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
290-
// for more information about preprocessors
291-
preprocess: vitePreprocess(),
292-
}
293-
`,
294288
'index.html': html`
295289
<!doctype html>
296290
<html>
@@ -355,10 +349,7 @@ test(
355349
{#each classes as cls}
356350
<div class="{cls}"></div>
357351
{/each}
358-
`
359-
360-
// Replace all spaces with tabs
361-
.replace(/\[[\s\S]*\]/gm, (m) => m.replace(/[ ]+/g, '\t')),
352+
`,
362353
},
363354
},
364355
async ({ fs, exec }) => {

0 commit comments

Comments
 (0)