@@ -1684,13 +1684,179 @@ module.exports = {
1684
1684
expectClassDeclaration ( 'large' ) ; // Standard SCSS
1685
1685
expectClassDeclaration ( 'justified' ) ; // Standard Less
1686
1686
expectClassDeclaration ( 'lowercase' ) ; // Standard Stylus
1687
- expectClassDeclaration ( 'block' ) ; // Standard Postcss
1687
+ expectClassDeclaration ( 'block' ) ; // Standard PostCSS
1688
+
1689
+ expectClassDeclaration ( 'italic_foo' ) ; // CSS Module
1690
+ expectClassDeclaration ( 'bold_foo' ) ; // SCSS Module
1691
+ expectClassDeclaration ( 'underline_foo' ) ; // Less Module
1692
+ expectClassDeclaration ( 'rtl_foo' ) ; // Stylus Module
1693
+ expectClassDeclaration ( 'hidden_foo' ) ; // PostCSS Module
1694
+
1695
+ testSetup . requestTestPage (
1696
+ browser ,
1697
+ path . join ( config . getContext ( ) , 'www' ) ,
1698
+ [
1699
+ 'build/runtime.js' ,
1700
+ 'build/main.js'
1701
+ ] ,
1702
+ async ( { page } ) => {
1703
+ const divClassArray = await page . evaluate ( ( ) => Array . from ( document . body . querySelector ( '#app > div' ) . classList . values ( ) ) ) ;
1704
+
1705
+ expect ( divClassArray . includes ( 'red' ) ) . to . be . true ; // Standard CSS
1706
+ expect ( divClassArray . includes ( 'large' ) ) . to . be . true ; // Standard SCSS
1707
+ expect ( divClassArray . includes ( 'justified' ) ) . to . be . true ; // Standard Less
1708
+ expect ( divClassArray . includes ( 'lowercase' ) ) . to . be . true ; // Standard Stylus
1709
+ expect ( divClassArray . includes ( 'block' ) ) . to . be . true ; // Standard PostCSS
1710
+
1711
+ expect ( divClassArray . includes ( 'italic_foo' ) ) . to . be . true ; // CSS module
1712
+ expect ( divClassArray . includes ( 'bold_foo' ) ) . to . be . true ; // SCSS module
1713
+ expect ( divClassArray . includes ( 'underline_foo' ) ) . to . be . true ; // Less module
1714
+ expect ( divClassArray . includes ( 'rtl_foo' ) ) . to . be . true ; // Stylus module
1715
+ expect ( divClassArray . includes ( 'hidden_foo' ) ) . to . be . true ; // PostCSS module
1716
+
1717
+ done ( ) ;
1718
+ }
1719
+ ) ;
1720
+ } ) ;
1721
+ } ) ;
1722
+
1723
+ it ( 'React supports CSS/Sass/Less/Stylus modules' , ( done ) => {
1724
+ const appDir = testSetup . createTestAppDir ( ) ;
1725
+ const config = testSetup . createWebpackConfig ( appDir , 'www/build' , 'dev' ) ;
1726
+ config . enableSingleRuntimeChunk ( ) ;
1727
+ config . setPublicPath ( '/build' ) ;
1728
+ config . addEntry ( 'main' , './react-css-modules/main.js' ) ;
1729
+ config . enableReactPreset ( ) ;
1730
+ config . enableSassLoader ( ) ;
1731
+ config . enableLessLoader ( ) ;
1732
+ config . enableStylusLoader ( ) ;
1733
+ config . configureCssLoader ( options => {
1734
+ // Remove hashes from local ident names
1735
+ // since they are not always the same.
1736
+ if ( options . modules ) {
1737
+ options . modules . localIdentName = '[local]_foo' ;
1738
+ }
1739
+ } ) ;
1740
+
1741
+ // Enable the PostCSS loader so we can use `lang="postcss"`
1742
+ config . enablePostCssLoader ( ) ;
1743
+ fs . writeFileSync (
1744
+ path . join ( appDir , 'postcss.config.js' ) ,
1745
+ `
1746
+ module.exports = {
1747
+ plugins: [
1748
+ require('autoprefixer')()
1749
+ ]
1750
+ } `
1751
+ ) ;
1752
+
1753
+ testSetup . runWebpack ( config , ( webpackAssert ) => {
1754
+ expect ( config . outputPath ) . to . be . a . directory ( ) . with . deep . files ( [
1755
+ 'main.js' ,
1756
+ 'main.css' ,
1757
+ 'manifest.json' ,
1758
+ 'entrypoints.json' ,
1759
+ 'runtime.js' ,
1760
+ ] ) ;
1761
+
1762
+ const expectClassDeclaration = ( className ) => {
1763
+ webpackAssert . assertOutputFileContains (
1764
+ 'main.css' ,
1765
+ `.${ className } {`
1766
+ ) ;
1767
+ } ;
1768
+
1769
+ expectClassDeclaration ( 'red' ) ; // Standard CSS
1770
+ expectClassDeclaration ( 'large' ) ; // Standard SCSS
1771
+ expectClassDeclaration ( 'justified' ) ; // Standard Less
1772
+ expectClassDeclaration ( 'lowercase' ) ; // Standard Stylus
1773
+
1774
+ expectClassDeclaration ( 'italic_foo' ) ; // CSS Module
1775
+ expectClassDeclaration ( 'bold_foo' ) ; // SCSS Module
1776
+ expectClassDeclaration ( 'underline_foo' ) ; // Less Module
1777
+ expectClassDeclaration ( 'rtl_foo' ) ; // Stylus Module
1778
+
1779
+ testSetup . requestTestPage (
1780
+ browser ,
1781
+ path . join ( config . getContext ( ) , 'www' ) ,
1782
+ [
1783
+ 'build/runtime.js' ,
1784
+ 'build/main.js'
1785
+ ] ,
1786
+ async ( { page } ) => {
1787
+ const divClassArray = await page . evaluate ( ( ) => Array . from ( document . body . querySelector ( '#app > div' ) . classList . values ( ) ) ) ;
1788
+
1789
+ expect ( divClassArray . includes ( 'red' ) ) . to . be . true ; // Standard CSS
1790
+ expect ( divClassArray . includes ( 'large' ) ) . to . be . true ; // Standard SCSS
1791
+ expect ( divClassArray . includes ( 'justified' ) ) . to . be . true ; // Standard Less
1792
+ expect ( divClassArray . includes ( 'lowercase' ) ) . to . be . true ; // Standard Stylus
1793
+
1794
+ expect ( divClassArray . includes ( 'italic_foo' ) ) . to . be . true ; // CSS module
1795
+ expect ( divClassArray . includes ( 'bold_foo' ) ) . to . be . true ; // SCSS module
1796
+ expect ( divClassArray . includes ( 'underline_foo' ) ) . to . be . true ; // Less module
1797
+ expect ( divClassArray . includes ( 'rtl_foo' ) ) . to . be . true ; // Stylus module
1798
+
1799
+ done ( ) ;
1800
+ }
1801
+ ) ;
1802
+ } ) ;
1803
+ } ) ;
1804
+
1805
+ it ( 'Preact supports CSS/Sass/Less/Stylus modules' , ( done ) => {
1806
+ const appDir = testSetup . createTestAppDir ( ) ;
1807
+ const config = testSetup . createWebpackConfig ( appDir , 'www/build' , 'dev' ) ;
1808
+ config . enableSingleRuntimeChunk ( ) ;
1809
+ config . setPublicPath ( '/build' ) ;
1810
+ config . addEntry ( 'main' , './preact-css-modules/main.js' ) ;
1811
+ config . enablePreactPreset ( ) ;
1812
+ config . enableSassLoader ( ) ;
1813
+ config . enableLessLoader ( ) ;
1814
+ config . enableStylusLoader ( ) ;
1815
+ config . configureCssLoader ( options => {
1816
+ // Remove hashes from local ident names
1817
+ // since they are not always the same.
1818
+ if ( options . modules ) {
1819
+ options . modules . localIdentName = '[local]_foo' ;
1820
+ }
1821
+ } ) ;
1822
+
1823
+ // Enable the PostCSS loader so we can use `lang="postcss"`
1824
+ config . enablePostCssLoader ( ) ;
1825
+ fs . writeFileSync (
1826
+ path . join ( appDir , 'postcss.config.js' ) ,
1827
+ `
1828
+ module.exports = {
1829
+ plugins: [
1830
+ require('autoprefixer')()
1831
+ ]
1832
+ } `
1833
+ ) ;
1834
+
1835
+ testSetup . runWebpack ( config , ( webpackAssert ) => {
1836
+ expect ( config . outputPath ) . to . be . a . directory ( ) . with . deep . files ( [
1837
+ 'main.js' ,
1838
+ 'main.css' ,
1839
+ 'manifest.json' ,
1840
+ 'entrypoints.json' ,
1841
+ 'runtime.js' ,
1842
+ ] ) ;
1843
+
1844
+ const expectClassDeclaration = ( className ) => {
1845
+ webpackAssert . assertOutputFileContains (
1846
+ 'main.css' ,
1847
+ `.${ className } {`
1848
+ ) ;
1849
+ } ;
1850
+
1851
+ expectClassDeclaration ( 'red' ) ; // Standard CSS
1852
+ expectClassDeclaration ( 'large' ) ; // Standard SCSS
1853
+ expectClassDeclaration ( 'justified' ) ; // Standard Less
1854
+ expectClassDeclaration ( 'lowercase' ) ; // Standard Stylus
1688
1855
1689
1856
expectClassDeclaration ( 'italic_foo' ) ; // CSS Module
1690
1857
expectClassDeclaration ( 'bold_foo' ) ; // SCSS Module
1691
1858
expectClassDeclaration ( 'underline_foo' ) ; // Less Module
1692
1859
expectClassDeclaration ( 'rtl_foo' ) ; // Stylus Module
1693
- expectClassDeclaration ( 'hidden_foo' ) ; // Stylus Module
1694
1860
1695
1861
testSetup . requestTestPage (
1696
1862
browser ,
@@ -1706,13 +1872,11 @@ module.exports = {
1706
1872
expect ( divClassArray . includes ( 'large' ) ) . to . be . true ; // Standard SCSS
1707
1873
expect ( divClassArray . includes ( 'justified' ) ) . to . be . true ; // Standard Less
1708
1874
expect ( divClassArray . includes ( 'lowercase' ) ) . to . be . true ; // Standard Stylus
1709
- expect ( divClassArray . includes ( 'block' ) ) . to . be . true ; // Standard Stylus
1710
1875
1711
1876
expect ( divClassArray . includes ( 'italic_foo' ) ) . to . be . true ; // CSS module
1712
1877
expect ( divClassArray . includes ( 'bold_foo' ) ) . to . be . true ; // SCSS module
1713
1878
expect ( divClassArray . includes ( 'underline_foo' ) ) . to . be . true ; // Less module
1714
1879
expect ( divClassArray . includes ( 'rtl_foo' ) ) . to . be . true ; // Stylus module
1715
- expect ( divClassArray . includes ( 'hidden_foo' ) ) . to . be . true ; // Stylus module
1716
1880
1717
1881
done ( ) ;
1718
1882
}
0 commit comments