Skip to content

Commit 663be15

Browse files
committed
switch to ava for testing
brings the testing time down from 31sec to 11sec :D
1 parent 0d5c04d commit 663be15

File tree

2 files changed

+46
-43
lines changed

2 files changed

+46
-43
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"node": ">=0.10.0"
1717
},
1818
"scripts": {
19-
"test": "mocha --timeout 0"
19+
"test": "node test/test.js"
2020
},
2121
"files": [
2222
"index.js",
@@ -62,8 +62,8 @@
6262
"viewport-list": "^0.2.0"
6363
},
6464
"devDependencies": {
65+
"ava": "0.0.3",
6566
"concat-stream": "^1.4.5",
66-
"image-size": "^0.3.0",
67-
"mocha": "*"
67+
"image-size": "^0.3.0"
6868
}
6969
}

test/test.js

+43-40
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,122 @@
11
'use strict';
2-
var assert = require('assert');
32
var fs = require('fs');
3+
var test = require('ava');
44
var imageSize = require('image-size');
55
var concat = require('concat-stream');
66
var Pageres = require('../');
77

88
process.chdir(__dirname);
99

10-
before(function () {
11-
this.timeout(20000);
12-
});
10+
test('generate screenshots', function (t) {
11+
t.plan(5);
1312

14-
it('should generate screenshots', function (cb) {
1513
var pageres = new Pageres()
1614
.src('yeoman.io', ['480x320', '1024x768', 'iphone 5s'])
1715
.src('todomvc.com', ['1280x1024', '1920x1080']);
1816

1917
pageres.run(function (err, streams) {
20-
assert(!err, err);
21-
assert.strictEqual(streams.length, 5);
22-
assert.strictEqual(streams[0].filename, 'todomvc.com-1280x1024.png');
23-
assert.strictEqual(streams[4].filename, 'yeoman.io-320x568.png');
18+
t.assert(!err, err);
19+
t.assert(streams.length === 5);
20+
t.assert(streams[0].filename === 'todomvc.com-1280x1024.png');
21+
t.assert(streams[4].filename === 'yeoman.io-320x568.png');
2422

2523
streams[0].once('data', function (data) {
26-
assert(data.length > 1000);
27-
cb();
24+
t.assert(data.length > 1000);
2825
});
2926
});
3027
});
3128

32-
it('should remove special characters from the URL to create a valid filename', function (cb) {
29+
test('remove special characters from the URL to create a valid filename', function (t) {
30+
t.plan(3);
31+
3332
var pageres = new Pageres()
3433
.src('http://www.microsoft.com/?query=pageres*|<>:"\\', ['1024x768']);
3534

3635
pageres.run(function (err, streams) {
37-
assert(!err, err);
38-
assert.strictEqual(streams.length, 1);
39-
assert.strictEqual(streams[0].filename, 'microsoft.com!query=pageres-1024x768.png');
36+
t.assert(!err, err);
37+
t.assert(streams.length === 1);
38+
t.assert(streams[0].filename === 'microsoft.com!query=pageres-1024x768.png');
4039
cb();
4140
});
4241
});
4342

44-
it('should have a `delay` option', function (cb) {
43+
test('have a `delay` option', function (t) {
44+
t.plan(2);
45+
4546
var pageres = new Pageres({ delay: 2 })
4647
.src('http://todomvc.com', ['1024x768']);
4748

4849
pageres.run(function (err, streams) {
49-
assert(!err, err);
50+
t.assert(!err, err);
5051

5152
var now = new Date();
5253

5354
streams[0].once('data', function () {
54-
assert((new Date()) - now > 2000);
55-
cb();
55+
t.assert((new Date()) - now > 2000);
5656
});
5757
});
5858
});
5959

60-
it('should crop image using the `crop` option', function (cb) {
60+
test('crop image using the `crop` option', function (t) {
61+
t.plan(4);
62+
6163
var pageres = new Pageres({ crop: true })
6264
.src('http://todomvc.com', ['1024x768']);
6365

6466
pageres.run(function (err, streams) {
65-
assert(!err, err);
66-
assert.strictEqual(streams[0].filename, 'todomvc.com-1024x768-cropped.png');
67+
t.assert(!err, err);
68+
t.assert(streams[0].filename === 'todomvc.com-1024x768-cropped.png');
6769

6870
streams[0].pipe(concat(function (data) {
6971
var size = imageSize(data);
70-
assert.strictEqual(size.width, 1024);
71-
assert.strictEqual(size.height, 768);
72-
cb();
72+
t.assert(size.width === 1024);
73+
t.assert(size.height === 768);
7374
}));
7475
});
7576
});
7677

77-
it('should support local relative files', function (cb) {
78+
test('support local relative files', function (t) {
79+
t.plan(3);
80+
7881
var pageres = new Pageres()
7982
.src('fixture.html', ['1024x768']);
8083

8184
pageres.run(function (err, streams) {
82-
assert(!err, err);
83-
84-
assert.strictEqual(streams[0].filename, 'fixture.html-1024x768.png');
85+
t.assert(!err, err);
86+
t.assert(streams[0].filename === 'fixture.html-1024x768.png');
8587

8688
streams[0].once('data', function (data) {
87-
assert(data.length > 1000);
88-
cb();
89+
t.assert(data.length > 1000);
8990
});
9091
});
9192
});
9293

93-
it('should fetch resolutions from w3counter', function (cb) {
94+
test('fetch resolutions from w3counter', function (t) {
95+
t.plan(3);
96+
9497
var pageres = new Pageres()
9598
.src('yeoman.io', ['w3counter']);
9699

97100
pageres.run(function (err, streams) {
98-
assert(!err, err);
99-
assert.strictEqual(streams.length, 10);
101+
t.assert(!err, err);
102+
t.assert(streams.length === 10);
100103

101104
streams[0].once('data', function (data) {
102-
assert(data.length > 1000);
103-
cb();
105+
t.assert(data.length > 1000);
104106
});
105107
});
106108
});
107109

108-
it('should save image', function (cb) {
110+
test('save image', function (t) {
111+
t.plan(2);
112+
109113
var pageres = new Pageres()
110114
.src('http://todomvc.com', ['1024x768'])
111115
.dest(__dirname);
112116

113117
pageres.run(function (err) {
114-
assert(!err);
115-
assert(fs.existsSync('todomvc.com-1024x768.png'));
118+
t.assert(!err, err);
119+
t.assert(fs.existsSync('todomvc.com-1024x768.png'));
116120
fs.unlinkSync('todomvc.com-1024x768.png');
117-
cb();
118121
});
119122
});

0 commit comments

Comments
 (0)