Skip to content

Commit a62b010

Browse files
committed
add integration test for source(…)
This integration test itself might change over time as we work through this PR.
1 parent 23147ff commit a62b010

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

integrations/cli/index.test.ts

+108-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os from 'node:os'
22
import path from 'node:path'
3-
import { describe } from 'vitest'
3+
import { describe, expect } from 'vitest'
44
import { candidate, css, html, js, json, test, yaml } from '../utils'
55

66
const STANDALONE_BINARY = (() => {
@@ -255,3 +255,110 @@ describe.each([
255255
},
256256
)
257257
})
258+
259+
describe.only('@source', () => {
260+
test(
261+
'it works',
262+
{
263+
fs: {
264+
'package.json': json`{}`,
265+
'pnpm-workspace.yaml': yaml`
266+
#
267+
packages:
268+
- project-a
269+
`,
270+
'project-a/package.json': json`
271+
{
272+
"dependencies": {
273+
"tailwindcss": "workspace:^",
274+
"@tailwindcss/cli": "workspace:^"
275+
}
276+
}
277+
`,
278+
'project-a/src/index.css': css`
279+
@import 'tailwindcss/theme' theme(reference);
280+
281+
/* Run auto-content detection in ../../project-b */
282+
@import 'tailwindcss/utilities' source('../../project-b');
283+
284+
/* Additive: */
285+
/* {my-lib-1,my-lib-2}: expand */
286+
/* *.html: only look for .html */
287+
@source '../node_modules/{my-lib-1,my-lib-2}/src/**/*.html';
288+
@source './logo.{jpg,png}'; /* Don't worry about it */
289+
`,
290+
'project-a/src/index.html': html`
291+
<div
292+
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-a/src/index.html']"
293+
></div>
294+
`,
295+
'project-a/src/logo.jpg': html`
296+
<div
297+
class="content-['project-a/src/logo.jpg']"
298+
></div>
299+
`,
300+
'project-a/node_modules/my-lib-1/src/index.html': html`
301+
<div
302+
class="content-['project-a/node_modules/my-lib-1/src/index.html']"
303+
></div>
304+
`,
305+
'project-a/node_modules/my-lib-2/src/index.html': html`
306+
<div
307+
class="content-['project-a/node_modules/my-lib-2/src/index.html']"
308+
></div>
309+
`,
310+
'project-b/src/index.html': html`
311+
<div
312+
class="content-['project-b/src/index.html']"
313+
></div>
314+
`,
315+
'project-b/node_modules/my-lib-3/src/index.html': html`
316+
<div
317+
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-b/node_modules/my-lib-3/src/index.html']"
318+
></div>
319+
`,
320+
},
321+
},
322+
async ({ fs, exec, root }) => {
323+
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', {
324+
cwd: path.join(root, 'project-a'),
325+
})
326+
327+
expect(await fs.dumpFiles('./project-a/dist/*.css')).toMatchInlineSnapshot(`
328+
"
329+
--- ./project-a/dist/out.css ---
330+
@tailwind utilities source('../../project-b') {
331+
.content-\\[\\'project-a\\/node_modules\\/my-lib-1\\/src\\/index\\.html\\'\\] {
332+
--tw-content: 'project-a/node modules/my-lib-1/src/index.html';
333+
content: var(--tw-content);
334+
}
335+
.content-\\[\\'project-a\\/node_modules\\/my-lib-2\\/src\\/index\\.html\\'\\] {
336+
--tw-content: 'project-a/node modules/my-lib-2/src/index.html';
337+
content: var(--tw-content);
338+
}
339+
.content-\\[\\'project-a\\/src\\/logo\\.jpg\\'\\] {
340+
--tw-content: 'project-a/src/logo.jpg';
341+
content: var(--tw-content);
342+
}
343+
.content-\\[\\'project-b\\/src\\/index\\.html\\'\\] {
344+
--tw-content: 'project-b/src/index.html';
345+
content: var(--tw-content);
346+
}
347+
}
348+
@supports (-moz-orient: inline) {
349+
@layer base {
350+
*, ::before, ::after, ::backdrop {
351+
--tw-content: "";
352+
}
353+
}
354+
}
355+
@property --tw-content {
356+
syntax: "*";
357+
inherits: false;
358+
initial-value: "";
359+
}
360+
"
361+
`)
362+
},
363+
)
364+
})

integrations/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ export function test(
303303
return Promise.all(
304304
files.map(async (file) => {
305305
let content = await fs.readFile(path.join(root, file), 'utf8')
306-
return [file, content]
306+
return [
307+
file,
308+
// Drop license comment
309+
content.replace(/[\s\n]*\/\*! tailwindcss .*? \*\/[\s\n]*/g, ''),
310+
]
307311
}),
308312
)
309313
},

0 commit comments

Comments
 (0)