1
+ /* eslint-disable global-require */
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ /* eslint-disable @typescript-eslint/no-require-imports */
1
4
import { resolve } from 'path' ;
2
5
3
6
import getAutoPreprocess from '../../src' ;
4
7
import { preprocess } from '../utils' ;
5
8
6
9
describe ( 'transformer - postcss' , ( ) => {
7
- const template = `<div></div><style>div{appearance:none;}</style>` ;
8
- const templateSass = `<div></div><style lang="scss">div{appearance:none;}</style>` ;
9
- const optsWithoutConfigFile = getAutoPreprocess ( {
10
- postcss : {
11
- plugins : [
12
- require ( 'autoprefixer' ) ( {
13
- overrideBrowserslist : 'Safari >= 5.1' ,
14
- } ) ,
15
- ] ,
16
- } ,
17
- } ) ;
18
-
19
10
it ( 'should not transform plain css with postcss if { postcss: falsy }' , async ( ) => {
11
+ const template = `<div></div><style>div{appearance:none;}</style>` ;
20
12
const preprocessed = await preprocess ( template , getAutoPreprocess ( ) ) ;
13
+
21
14
expect ( preprocessed . toString ( ) ) . not . toMatch ( / - w e b k i t - / ) ;
22
15
} ) ;
23
16
24
17
it ( 'should not transform plain css with postcss if { postcss: true } and no configuration file at cwd' , async ( ) => {
18
+ const template = `<div></div><style>div{appearance:none;}</style>` ;
25
19
const preprocessed = await preprocess (
26
20
template ,
27
21
getAutoPreprocess ( {
28
22
postcss : true ,
29
23
} ) ,
30
24
) ;
25
+
31
26
expect ( preprocessed . toString ( ) ) . not . toMatch ( / - w e b k i t - / ) ;
32
27
} ) ;
33
28
34
29
it ( 'should transform plain css with postcss if { postcss: { plugins... } }' , async ( ) => {
30
+ const template = `<div></div><style>div{appearance:none;}</style>` ;
31
+ const optsWithoutConfigFile = getAutoPreprocess ( {
32
+ postcss : {
33
+ plugins : [
34
+ require ( 'autoprefixer' ) ( {
35
+ overrideBrowserslist : 'Safari >= 5.1' ,
36
+ } ) ,
37
+ ] ,
38
+ } ,
39
+ } ) ;
35
40
const preprocessed = await preprocess ( template , optsWithoutConfigFile ) ;
41
+
36
42
expect ( preprocessed . toString ( ) ) . toMatch ( / - w e b k i t - / ) ;
37
43
} ) ;
38
44
39
45
it ( 'should transform async preprocessed css with postcss if { postcss: { plugins... } }' , async ( ) => {
46
+ const templateSass = `<div></div><style lang="scss">div{appearance:none;}</style>` ;
47
+ const optsWithoutConfigFile = getAutoPreprocess ( {
48
+ postcss : {
49
+ plugins : [
50
+ require ( 'autoprefixer' ) ( {
51
+ overrideBrowserslist : 'Safari >= 5.1' ,
52
+ } ) ,
53
+ ] ,
54
+ } ,
55
+ } ) ;
40
56
const preprocessed = await preprocess ( templateSass , optsWithoutConfigFile ) ;
57
+
41
58
expect ( preprocessed . toString ( ) ) . toMatch ( / - w e b k i t - / ) ;
42
59
} ) ;
43
60
44
61
it ( 'should transform plain css with postcss if { postcss: { configFilePath: ... } }' , async ( ) => {
62
+ const template = `<div></div><style>div{appearance:none;}</style>` ;
45
63
const preprocessed = await preprocess (
46
64
template ,
47
65
getAutoPreprocess ( {
@@ -50,6 +68,7 @@ describe('transformer - postcss', () => {
50
68
} ,
51
69
} ) ,
52
70
) ;
71
+
53
72
expect ( preprocessed . toString ( ) ) . toMatch ( / - w e b k i t - / ) ;
54
73
} ) ;
55
74
@@ -61,6 +80,7 @@ describe('transformer - postcss', () => {
61
80
} ,
62
81
} ) ;
63
82
const preprocessed = await preprocess ( template , opts ) ;
83
+
64
84
expect ( preprocessed . dependencies ) . toContain (
65
85
resolve ( __dirname , '..' , 'fixtures' , 'style.css' ) ,
66
86
) ;
78
98
} ,
79
99
} ) ;
80
100
const preprocessed = await preprocess ( template , opts ) ;
101
+
81
102
expect ( preprocessed . toString ( ) ) . toContain ( `div {
82
103
color: red
83
104
}` ) ;
0 commit comments