1
- /* eslint-env mocha */
2
- 'use strict' ;
3
- const path = require ( 'path' ) ;
4
- const assert = require ( 'assert' ) ;
5
- const gutil = require ( 'gulp-util' ) ;
6
- const sourceMaps = require ( 'gulp-sourcemaps' ) ;
7
- const autoprefixer = require ( './' ) ;
1
+ import path from 'path' ;
2
+ import test from 'ava' ;
3
+ import gutil from 'gulp-util' ;
4
+ import sourceMaps from 'gulp-sourcemaps' ;
5
+ import pEvent from 'p-event' ;
6
+ import m from '.' ;
8
7
9
- it ( 'should autoprefix CSS' , cb => {
10
- const stream = autoprefixer ( ) ;
8
+ test ( 'autoprefix CSS' , async t => {
9
+ const stream = m ( ) ;
10
+ const data = pEvent ( stream , 'data' ) ;
11
11
12
- stream . on ( 'data' , file => {
13
- assert ( / - / . test ( file . contents . toString ( ) ) ) ;
14
- assert . equal ( file . relative , 'fixture.css' ) ;
15
- } ) ;
16
-
17
- stream . on ( 'end' , cb ) ;
18
-
19
- stream . write ( new gutil . File ( {
12
+ stream . end ( new gutil . File ( {
20
13
cwd : __dirname ,
21
14
base : path . join ( __dirname , 'fixture' ) ,
22
15
path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
23
16
contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}' )
24
17
} ) ) ;
25
18
26
- stream . end ( ) ;
19
+ const file = await data ;
20
+ t . true ( / - / . test ( file . contents . toString ( ) ) ) ;
21
+ t . is ( file . relative , 'fixture.css' ) ;
27
22
} ) ;
28
23
29
- it ( 'should generate source maps', cb => {
24
+ test ( ' generate source maps', async t => {
30
25
const init = sourceMaps . init ( ) ;
31
26
const write = sourceMaps . write ( ) ;
27
+ const data = pEvent ( write , 'data' ) ;
32
28
33
29
init
34
- . pipe ( autoprefixer ( {
30
+ . pipe ( m ( {
35
31
browsers : [ 'Firefox ESR' ]
36
32
} ) )
37
33
. pipe ( write ) ;
38
34
39
- write . on ( 'data' , file => {
40
- assert . equal ( file . sourceMap . mappings , 'AAAA;CACC,cAAc;CACd' ) ;
41
- const contents = file . contents . toString ( ) ;
42
- assert ( / f l e x / . test ( contents ) ) ;
43
- assert ( / s o u r c e M a p p i n g U R L = d a t a : a p p l i c a t i o n \/ j s o n ; c h a r s e t = u t f 8 ; b a s e 6 4 / . test ( contents ) ) ;
44
- cb ( ) ;
45
- } ) ;
46
-
47
- init . write ( new gutil . File ( {
35
+ init . end ( new gutil . File ( {
48
36
cwd : __dirname ,
49
37
base : path . join ( __dirname , 'fixture' ) ,
50
38
path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
51
39
contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}' ) ,
52
40
sourceMap : ''
53
41
} ) ) ;
54
42
55
- init . end ( ) ;
43
+ const file = await data ;
44
+ t . is ( file . sourceMap . mappings , 'AAAA;CACC,cAAc;CACd' ) ;
45
+ const contents = file . contents . toString ( ) ;
46
+ t . true ( / f l e x / . test ( contents ) ) ;
47
+ t . true ( / s o u r c e M a p p i n g U R L = d a t a : a p p l i c a t i o n \/ j s o n ; c h a r s e t = u t f 8 ; b a s e 6 4 / . test ( contents ) ) ;
56
48
} ) ;
57
49
58
- it ( 'should read upstream source maps', cb => {
50
+ test ( ' read upstream source maps', async t => {
59
51
let testFile ;
60
- const stream = autoprefixer ( ) ;
52
+ const stream = m ( ) ;
61
53
const write = sourceMaps . write ( ) ;
62
54
const sourcesContent = [
63
55
'a {\n display: flex;\n}\n' ,
64
56
'a {\n\tdisplay: flex;\n}\n'
65
57
] ;
66
58
67
- stream . pipe ( write ) ;
59
+ const data = pEvent ( write , 'data' ) ;
68
60
69
- write . on ( 'data' , file => {
70
- assert . equal ( file . sourceMap . sourcesContent [ 0 ] , sourcesContent [ 0 ] ) ;
71
- assert . equal ( file . sourceMap . sourcesContent [ 1 ] , sourcesContent [ 1 ] ) ;
72
- cb ( ) ;
73
- } ) ;
61
+ stream . pipe ( write ) ;
74
62
75
- stream . write (
63
+ stream . end (
76
64
testFile = new gutil . File ( {
77
65
cwd : __dirname ,
78
66
base : path . join ( __dirname , 'fixture' ) ,
@@ -89,5 +77,7 @@ it('should read upstream source maps', cb => {
89
77
}
90
78
) ;
91
79
92
- stream . end ( ) ;
80
+ const file = await data ;
81
+ t . is ( file . sourceMap . sourcesContent [ 0 ] , sourcesContent [ 0 ] ) ;
82
+ t . is ( file . sourceMap . sourcesContent [ 1 ] , sourcesContent [ 1 ] ) ;
93
83
} ) ;
0 commit comments