Skip to content

Commit 04814b7

Browse files
committedMay 8, 2017
Rewrite tests to use AVA
1 parent 7df69ba commit 04814b7

File tree

2 files changed

+34
-43
lines changed

2 files changed

+34
-43
lines changed
 

‎package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=4"
13+
"node": ">=4.5"
1414
},
1515
"scripts": {
16-
"test": "xo && mocha"
16+
"test": "xo && ava"
1717
},
1818
"files": [
1919
"index.js"
@@ -37,8 +37,9 @@
3737
"vinyl-sourcemaps-apply": "^0.2.0"
3838
},
3939
"devDependencies": {
40+
"ava": "*",
4041
"gulp-sourcemaps": "^2.6.0",
41-
"mocha": "*",
42+
"p-event": "^1.1.0",
4243
"xo": "*"
4344
}
4445
}

‎test.js

+30-40
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,66 @@
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(/flex/.test(contents));
43-
assert(/sourceMappingURL=data:application\/json;charset=utf8;base64/.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(/flex/.test(contents));
47+
t.true(/sourceMappingURL=data:application\/json;charset=utf8;base64/.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

Comments
 (0)
Please sign in to comment.