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