1
- import path from 'path' ;
1
+ import { Buffer } from 'node:buffer' ;
2
+ import path from 'node:path' ;
3
+ import { fileURLToPath } from 'node:url' ;
2
4
import test from 'ava' ;
3
5
import Vinyl from 'vinyl' ;
4
6
import sourceMaps from 'gulp-sourcemaps' ;
5
- import pEvent from 'p-event' ;
6
- import autoprefixer from '.' ;
7
+ import { pEvent } from 'p-event' ;
8
+ import autoprefixer from './index.js' ;
9
+
10
+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
7
11
8
12
test ( 'autoprefix CSS' , async t => {
9
13
const stream = autoprefixer ( ) ;
@@ -13,7 +17,7 @@ test('autoprefix CSS', async t => {
13
17
cwd : __dirname ,
14
18
base : path . join ( __dirname , 'fixture' ) ,
15
19
path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
16
- contents : Buffer . from ( '::placeholder {\n\tcolor: gray;\n}' )
20
+ contents : Buffer . from ( '::placeholder {\n\tcolor: gray;\n}' ) ,
17
21
} ) ) ;
18
22
19
23
const file = await data ;
@@ -28,7 +32,7 @@ test('generate source maps', async t => {
28
32
29
33
init
30
34
. pipe ( autoprefixer ( {
31
- overrideBrowserslist : [ 'Firefox ESR' ]
35
+ overrideBrowserslist : [ 'Firefox ESR' ] ,
32
36
} ) )
33
37
. pipe ( write ) ;
34
38
@@ -37,7 +41,7 @@ test('generate source maps', async t => {
37
41
base : path . join ( __dirname , 'fixture' ) ,
38
42
path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
39
43
contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}' ) ,
40
- sourceMap : ''
44
+ sourceMap : '' ,
41
45
} ) ) ;
42
46
43
47
const file = await data ;
@@ -48,36 +52,35 @@ test('generate source maps', async t => {
48
52
} ) ;
49
53
50
54
test ( 'read upstream source maps' , async t => {
51
- let testFile ;
52
55
const stream = autoprefixer ( ) ;
53
- const write = sourceMaps . write ( ) ;
54
- const sourcesContent = [
55
- 'a {\n display: flex;\n}\n' ,
56
- 'a {\n\tdisplay: flex;\n}\n'
57
- ] ;
56
+ const finalStream = stream . pipe ( sourceMaps . write ( ) ) ;
57
+ const data = pEvent ( finalStream , 'data' ) ;
58
58
59
- const data = pEvent ( write , 'data' ) ;
59
+ const testFile = new Vinyl ( {
60
+ cwd : __dirname ,
61
+ base : path . join ( __dirname , 'fixture' ) ,
62
+ path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
63
+ contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}\n' ) ,
64
+ } ) ;
60
65
61
- stream . pipe ( write ) ;
66
+ testFile . sourceMap = {
67
+ version : 3 ,
68
+ sources : [ 'imported.less' ] ,
69
+ names : [ ] ,
70
+ mappings : 'AAAA;EACC,aAAA' ,
71
+ file : 'fixture.css' ,
72
+ sourcesContent : [ 'a {\n display: flex;\n}\n' ] ,
73
+ } ;
62
74
63
- stream . end (
64
- testFile = new Vinyl ( {
65
- cwd : __dirname ,
66
- base : path . join ( __dirname , 'fixture' ) ,
67
- path : path . join ( __dirname , 'fixture' , 'fixture.css' ) ,
68
- contents : Buffer . from ( 'a {\n\tdisplay: flex;\n}\n' )
69
- } ) ,
70
- testFile . sourceMap = {
71
- version : 3 ,
72
- sources : [ 'imported.less' ] ,
73
- names : [ ] ,
74
- mappings : 'AAAA;EACC,aAAA' ,
75
- file : 'fixture.css' ,
76
- sourcesContent : [ 'a {\n display: flex;\n}\n' ]
77
- }
78
- ) ;
75
+ stream . end ( testFile ) ;
79
76
80
77
const file = await data ;
78
+
79
+ const sourcesContent = [
80
+ 'a {\n display: flex;\n}\n' ,
81
+ 'a {\n\tdisplay: flex;\n}\n' ,
82
+ ] ;
83
+
81
84
t . is ( file . sourceMap . sourcesContent [ 0 ] , sourcesContent [ 0 ] ) ;
82
85
t . is ( file . sourceMap . sourcesContent [ 1 ] , sourcesContent [ 1 ] ) ;
83
86
} ) ;
0 commit comments