1
1
import path from 'node:path'
2
- import { candidate , css , html , js , json , retryAssertion , test , ts , yaml } from '../utils'
2
+ import { candidate , css , html , js , json , test , ts , yaml } from '../utils'
3
3
4
4
test (
5
5
'production build (string)' ,
@@ -662,35 +662,72 @@ test(
662
662
` ,
663
663
'src/index.css' : css ` @import './tailwind.css'; ` ,
664
664
'src/tailwind.css' : css `
665
- @reference 'tailwindcss/does-not-exist ';
665
+ @reference 'tailwindcss/theme ';
666
666
@import 'tailwindcss/utilities';
667
667
` ,
668
668
} ,
669
669
} ,
670
670
async ( { fs, expect, spawn } ) => {
671
+ // 1. Start the watcher
672
+ //
673
+ // It must have valid CSS for the initial build
671
674
let process = await spawn ( 'pnpm postcss src/index.css --output dist/out.css --watch --verbose' )
672
675
676
+ await process . onStderr ( ( message ) => message . includes ( 'Waiting for file changes...' ) )
677
+
678
+ expect ( await fs . dumpFiles ( 'dist/*.css' ) ) . toMatchInlineSnapshot ( `
679
+ "
680
+ --- dist/out.css ---
681
+ .underline {
682
+ text-decoration-line: underline;
683
+ }
684
+ "
685
+ ` )
686
+
687
+ // 2. Cause an error
688
+ await fs . write (
689
+ 'src/tailwind.css' ,
690
+ css `
691
+ @reference 'tailwindcss/does-not-exist';
692
+ @import 'tailwindcss/utilities';
693
+ ` ,
694
+ )
695
+
696
+ // 2.5 Write to a content file
697
+ await fs . write ( 'src/index.html' , html `
698
+ <div class="flex underline"></div>
699
+ ` )
700
+
673
701
await process . onStderr ( ( message ) =>
674
702
message . includes ( 'does-not-exist is not exported from package' ) ,
675
703
)
676
704
677
- await retryAssertion ( async ( ) => expect ( await fs . read ( 'dist/out.css' ) ) . toEqual ( '' ) )
678
-
679
- await process . onStderr ( ( message ) => message . includes ( 'Waiting for file changes...' ) )
705
+ expect ( await fs . dumpFiles ( 'dist/*.css' ) ) . toMatchInlineSnapshot ( `
706
+ "
707
+ --- dist/out.css ---
708
+ .underline {
709
+ text-decoration-line: underline;
710
+ }
711
+ "
712
+ ` )
680
713
681
- // Fix the CSS file
714
+ // 3. Fix the CSS file
682
715
await fs . write (
683
716
'src/tailwind.css' ,
684
717
css `
685
718
@reference 'tailwindcss/theme';
686
719
@import 'tailwindcss/utilities';
687
720
` ,
688
721
)
689
- await process . onStderr ( ( message ) => message . includes ( 'Finished' ) )
722
+
723
+ await process . onStderr ( ( message ) => message . includes ( 'Waiting for file changes...' ) )
690
724
691
725
expect ( await fs . dumpFiles ( 'dist/*.css' ) ) . toMatchInlineSnapshot ( `
692
726
"
693
727
--- dist/out.css ---
728
+ .flex {
729
+ display: flex;
730
+ }
694
731
.underline {
695
732
text-decoration-line: underline;
696
733
}
@@ -705,11 +742,22 @@ test(
705
742
@import 'tailwindcss/utilities';
706
743
` ,
707
744
)
745
+
708
746
await process . onStderr ( ( message ) =>
709
747
message . includes ( 'does-not-exist is not exported from package' ) ,
710
748
)
711
749
712
- await retryAssertion ( async ( ) => expect ( await fs . read ( 'dist/out.css' ) ) . toEqual ( '' ) )
750
+ expect ( await fs . dumpFiles ( 'dist/*.css' ) ) . toMatchInlineSnapshot ( `
751
+ "
752
+ --- dist/out.css ---
753
+ .flex {
754
+ display: flex;
755
+ }
756
+ .underline {
757
+ text-decoration-line: underline;
758
+ }
759
+ "
760
+ ` )
713
761
} ,
714
762
)
715
763
0 commit comments