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 '.' ;
87
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' ) ;
1111
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 ( {
2013 cwd : __dirname ,
2114 base : path . join ( __dirname , 'fixture' ) ,
2215 path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
2316 contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}' )
2417 } ) ) ;
2518
26- stream . end ( ) ;
19+ const file = await data ;
20+ t . true ( / - / . test ( file . contents . toString ( ) ) ) ;
21+ t . is ( file . relative , 'fixture.css' ) ;
2722} ) ;
2823
29- it ( 'should generate source maps', cb => {
24+ test ( ' generate source maps', async t => {
3025 const init = sourceMaps . init ( ) ;
3126 const write = sourceMaps . write ( ) ;
27+ const data = pEvent ( write , 'data' ) ;
3228
3329 init
34- . pipe ( autoprefixer ( {
30+ . pipe ( m ( {
3531 browsers : [ 'Firefox ESR' ]
3632 } ) )
3733 . pipe ( write ) ;
3834
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 ( {
4836 cwd : __dirname ,
4937 base : path . join ( __dirname , 'fixture' ) ,
5038 path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
5139 contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}' ) ,
5240 sourceMap : ''
5341 } ) ) ;
5442
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 ) ) ;
5648} ) ;
5749
58- it ( 'should read upstream source maps', cb => {
50+ test ( ' read upstream source maps', async t => {
5951 let testFile ;
60- const stream = autoprefixer ( ) ;
52+ const stream = m ( ) ;
6153 const write = sourceMaps . write ( ) ;
6254 const sourcesContent = [
6355 'a {\n display: flex;\n}\n' ,
6456 'a {\n\tdisplay: flex;\n}\n'
6557 ] ;
6658
67- stream . pipe ( write ) ;
59+ const data = pEvent ( write , 'data' ) ;
6860
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 ) ;
7462
75- stream . write (
63+ stream . end (
7664 testFile = new gutil . File ( {
7765 cwd : __dirname ,
7866 base : path . join ( __dirname , 'fixture' ) ,
@@ -89,5 +77,7 @@ it('should read upstream source maps', cb => {
8977 }
9078 ) ;
9179
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 ] ) ;
9383} ) ;
0 commit comments