Skip to content

Commit 86e9e4d

Browse files
committed
add CLI watch mode tests for @source and source(…)
1 parent 9f6ab1a commit 86e9e4d

File tree

1 file changed

+100
-2
lines changed

1 file changed

+100
-2
lines changed

integrations/cli/index.test.ts

+100-2
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe.each([
257257
})
258258

259259
test(
260-
'source(…) and `@source` can be configured to use auto source detection',
260+
'source(…) and `@source` can be configured to use auto source detection (build + watch mode)',
261261
{
262262
fs: {
263263
'package.json': json`{}`,
@@ -364,7 +364,7 @@ test(
364364
`,
365365
},
366366
},
367-
async ({ fs, exec, root }) => {
367+
async ({ fs, exec, spawn, root }) => {
368368
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', {
369369
cwd: path.join(root, 'project-a'),
370370
})
@@ -406,5 +406,103 @@ test(
406406
}
407407
"
408408
`)
409+
410+
// Watch mode tests
411+
await spawn('pnpm tailwindcss --input src/index.css --output dist/out.css --watch', {
412+
cwd: path.join(root, 'project-a'),
413+
})
414+
415+
// Changes to project-a should not be included in the output, we changed the
416+
// base folder to project-b.
417+
await fs.write(
418+
'project-a/src/index.html',
419+
html`<div class="[.changed_&]:content-['project-a/src/index.html']"></div>`,
420+
)
421+
await fs.expectFileNotToContain('./project-a/dist/out.css', [
422+
candidate`[.changed_&]:content-['project-a/src/index.html']`,
423+
])
424+
425+
// Changes to this file should be included, because we explicitly listed
426+
// them using `@source`.
427+
await fs.write(
428+
'project-a/src/logo.jpg',
429+
html`<div class="[.changed_&]:content-['project-a/src/logo.jpg']"></div>`,
430+
)
431+
await fs.expectFileToContain('./project-a/dist/out.css', [
432+
candidate`[.changed_&]:content-['project-a/src/logo.jpg']`,
433+
])
434+
435+
// Changes to these files should be included, because we explicitly listed
436+
// them using `@source`.
437+
await fs.write(
438+
'project-a/node_modules/my-lib-1/src/index.html',
439+
html`<div
440+
class="[.changed_&]:content-['project-a/node_modules/my-lib-1/src/index.html']"
441+
></div>`,
442+
)
443+
await fs.expectFileToContain('./project-a/dist/out.css', [
444+
candidate`[.changed_&]:content-['project-a/node_modules/my-lib-1/src/index.html']`,
445+
])
446+
await fs.write(
447+
'project-a/node_modules/my-lib-2/src/index.html',
448+
html`<div
449+
class="[.changed_&]:content-['project-a/node_modules/my-lib-2/src/index.html']"
450+
></div>`,
451+
)
452+
await fs.expectFileToContain('./project-a/dist/out.css', [
453+
candidate`[.changed_&]:content-['project-a/node_modules/my-lib-2/src/index.html']`,
454+
])
455+
456+
// Changes to this file should be included, because we changed the base to
457+
// `project-b`.
458+
await fs.write(
459+
'project-b/src/index.html',
460+
html`<div class="[.changed_&]:content-['project-b/src/index.html']"></div>`,
461+
)
462+
await fs.expectFileToContain('./project-a/dist/out.css', [
463+
candidate`[.changed_&]:content-['project-b/src/index.html']`,
464+
])
465+
466+
// Changes to this file should not be included. We did change the base to
467+
// `project-b`, but we still apply the auto source detection rules which
468+
// ignore `node_modules`.
469+
await fs.write(
470+
'project-b/node_modules/my-lib-3/src/index.html',
471+
html`<div
472+
class="[.changed_&]:content-['project-b/node_modules/my-lib-3/src/index.html']"
473+
></div>`,
474+
)
475+
await fs.expectFileNotToContain('./project-a/dist/out.css', [
476+
candidate`[.changed_&]:content-['project-b/node_modules/my-lib-3/src/index.html']`,
477+
])
478+
479+
// Project C was added explicitly via `@source`, therefore changes to these
480+
// files should be included.
481+
await fs.write(
482+
'project-c/src/index.html',
483+
html`<div class="[.changed_&]:content-['project-c/src/index.html']"></div>`,
484+
)
485+
await fs.expectFileToContain('./project-a/dist/out.css', [
486+
candidate`[.changed_&]:content-['project-c/src/index.html']`,
487+
])
488+
489+
// Except for these files, since they are ignored by the default auto source
490+
// detection rules.
491+
await fs.write(
492+
'project-c/src/logo.jpg',
493+
html`<div class="[.changed_&]:content-['project-c/src/logo.jpg']"></div>`,
494+
)
495+
await fs.expectFileNotToContain('./project-a/dist/out.css', [
496+
candidate`[.changed_&]:content-['project-c/src/logo.jpg']`,
497+
])
498+
await fs.write(
499+
'project-c/node_modules/my-lib-1/src/index.html',
500+
html`<div
501+
class="[.changed_&]:content-['project-c/node_modules/my-lib-1/src/index.html']"
502+
></div>`,
503+
)
504+
await fs.expectFileNotToContain('./project-a/dist/out.css', [
505+
candidate`[.changed_&]:content-['project-c/node_modules/my-lib-1/src/index.html']`,
506+
])
409507
},
410508
)

0 commit comments

Comments
 (0)