@@ -6,17 +6,35 @@ import * as postcss from 'postcss';
6
6
import { PostcssTypescriptCss } from '../namespace/PostcssTypescriptCss' ;
7
7
import * as plugin from '../postcss-typescript-css' ;
8
8
9
- function run ( t : TestContext , input : { css : string , from : string } ) {
10
- return postcss ( [ plugin ] ) . process ( input . css , { from : input . from } )
9
+ function run ( t : TestContext , input : { css : string , from : string } , opts ?: PostcssTypescriptCss . Options ) {
10
+ return postcss ( [ plugin ( opts ) ] ) . process ( input . css , { from : input . from } )
11
11
. then ( ( result ) => {
12
- const fakeComponentTS = readFileSync ( path . join ( __dirname , 'postcss/fakeComponent.ts' ) , 'utf8' ) ;
13
- t . true ( fakeComponentTS . includes ( 'fakeComponentStyle' ) ) ;
14
- t . true ( fakeComponentTS . includes ( 'fakeComponent:' ) ) ;
15
- t . true ( fakeComponentTS . includes ( 'fakeComponentDescendentName:' ) ) ;
16
- t . true ( fakeComponentTS . includes ( 'fakeComponentModifierName:' ) ) ;
12
+ let fakeComponentTS ;
13
+ if ( opts ) {
14
+ fakeComponentTS = readFileSync ( path . join ( __dirname , 'postcss/fakeComponentModules.ts' ) , 'utf8' ) ;
15
+ t . true ( fakeComponentTS . includes ( 'fakeComponentModulesStyle' ) ) ;
16
+ t . true ( fakeComponentTS . includes ( 'fakeComponentModules:' ) ) ;
17
+ t . true ( fakeComponentTS . includes ( 'fakeComponentModulesDescendentName:' ) ) ;
18
+ t . true ( fakeComponentTS . includes ( 'fakeComponentModulesModifierName:' ) ) ;
19
+ } else {
20
+ fakeComponentTS = readFileSync ( path . join ( __dirname , 'postcss/fakeComponent.ts' ) , 'utf8' ) ;
21
+ t . true ( fakeComponentTS . includes ( 'fakeComponentStyle' ) ) ;
22
+ t . true ( fakeComponentTS . includes ( 'fakeComponent:' ) ) ;
23
+ t . true ( fakeComponentTS . includes ( 'fakeComponentDescendentName:' ) ) ;
24
+ t . true ( fakeComponentTS . includes ( 'fakeComponentModifierName:' ) ) ;
25
+ }
17
26
} )
18
27
. catch ( ( err : string ) => {
19
- t . true ( err . includes ( 'TypeError: Path must be a string' ) ) ;
28
+ if ( opts ) {
29
+ if ( ! opts . cssFileName ) {
30
+ t . is ( err , 'The property cssFileName can not be null' ) ;
31
+ }
32
+ if ( ! opts . content ) {
33
+ t . is ( err , 'The property content can not be null' ) ;
34
+ }
35
+ } else {
36
+ t . true ( err . includes ( 'TypeError: Path must be a string' ) ) ;
37
+ }
20
38
} ) ;
21
39
}
22
40
@@ -26,6 +44,17 @@ test('should create a ts file', t => {
26
44
return run ( t , { css : cssContent , from : cssFile } ) ;
27
45
} ) ;
28
46
47
+ test ( 'should create a ts file with postcss-modules configuration' , t => {
48
+ const cssFileName = path . join ( __dirname , 'postcss/fakeComponentModules.postcss' ) ;
49
+ const content = JSON . parse ( readFileSync ( path . join ( __dirname , 'postcss/fakeComponentModules.json' ) , 'utf8' ) ) ;
50
+ return run ( t , { css : '' , from : '' } , { cssFileName, content } ) ;
51
+ } ) ;
52
+
29
53
test ( 'throws if cssFileName is null' , t => {
30
- return run ( t , { css : '' , from : '' } ) ;
54
+ return run ( t , { css : '' , from : '' } , { cssFileName : null , content : [ '.class' ] } ) ;
55
+ } ) ;
56
+
57
+ test ( 'throws if content is null' , t => {
58
+ const cssFileName = path . join ( __dirname , 'postcss/fakeComponentModules.postcss' ) ;
59
+ return run ( t , { css : '' , from : '' } , { cssFileName, content : null } ) ;
31
60
} ) ;
0 commit comments