From 663be15acb3dd2eb0f71b1956ef28c2cd3fdeed0 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 6 Jul 2014 18:25:11 +0200 Subject: [PATCH] switch to `ava` for testing brings the testing time down from 31sec to 11sec :D --- package.json | 6 ++-- test/test.js | 83 +++++++++++++++++++++++++++------------------------- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index eb4f9fa..5d00c3c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "mocha --timeout 0" + "test": "node test/test.js" }, "files": [ "index.js", @@ -62,8 +62,8 @@ "viewport-list": "^0.2.0" }, "devDependencies": { + "ava": "0.0.3", "concat-stream": "^1.4.5", - "image-size": "^0.3.0", - "mocha": "*" + "image-size": "^0.3.0" } } diff --git a/test/test.js b/test/test.js index df8f08f..5217b17 100644 --- a/test/test.js +++ b/test/test.js @@ -1,119 +1,122 @@ 'use strict'; -var assert = require('assert'); var fs = require('fs'); +var test = require('ava'); var imageSize = require('image-size'); var concat = require('concat-stream'); var Pageres = require('../'); process.chdir(__dirname); -before(function () { - this.timeout(20000); -}); +test('generate screenshots', function (t) { + t.plan(5); -it('should generate screenshots', function (cb) { var pageres = new Pageres() .src('yeoman.io', ['480x320', '1024x768', 'iphone 5s']) .src('todomvc.com', ['1280x1024', '1920x1080']); pageres.run(function (err, streams) { - assert(!err, err); - assert.strictEqual(streams.length, 5); - assert.strictEqual(streams[0].filename, 'todomvc.com-1280x1024.png'); - assert.strictEqual(streams[4].filename, 'yeoman.io-320x568.png'); + t.assert(!err, err); + t.assert(streams.length === 5); + t.assert(streams[0].filename === 'todomvc.com-1280x1024.png'); + t.assert(streams[4].filename === 'yeoman.io-320x568.png'); streams[0].once('data', function (data) { - assert(data.length > 1000); - cb(); + t.assert(data.length > 1000); }); }); }); -it('should remove special characters from the URL to create a valid filename', function (cb) { +test('remove special characters from the URL to create a valid filename', function (t) { + t.plan(3); + var pageres = new Pageres() .src('http://www.microsoft.com/?query=pageres*|<>:"\\', ['1024x768']); pageres.run(function (err, streams) { - assert(!err, err); - assert.strictEqual(streams.length, 1); - assert.strictEqual(streams[0].filename, 'microsoft.com!query=pageres-1024x768.png'); + t.assert(!err, err); + t.assert(streams.length === 1); + t.assert(streams[0].filename === 'microsoft.com!query=pageres-1024x768.png'); cb(); }); }); -it('should have a `delay` option', function (cb) { +test('have a `delay` option', function (t) { + t.plan(2); + var pageres = new Pageres({ delay: 2 }) .src('http://todomvc.com', ['1024x768']); pageres.run(function (err, streams) { - assert(!err, err); + t.assert(!err, err); var now = new Date(); streams[0].once('data', function () { - assert((new Date()) - now > 2000); - cb(); + t.assert((new Date()) - now > 2000); }); }); }); -it('should crop image using the `crop` option', function (cb) { +test('crop image using the `crop` option', function (t) { + t.plan(4); + var pageres = new Pageres({ crop: true }) .src('http://todomvc.com', ['1024x768']); pageres.run(function (err, streams) { - assert(!err, err); - assert.strictEqual(streams[0].filename, 'todomvc.com-1024x768-cropped.png'); + t.assert(!err, err); + t.assert(streams[0].filename === 'todomvc.com-1024x768-cropped.png'); streams[0].pipe(concat(function (data) { var size = imageSize(data); - assert.strictEqual(size.width, 1024); - assert.strictEqual(size.height, 768); - cb(); + t.assert(size.width === 1024); + t.assert(size.height === 768); })); }); }); -it('should support local relative files', function (cb) { +test('support local relative files', function (t) { + t.plan(3); + var pageres = new Pageres() .src('fixture.html', ['1024x768']); pageres.run(function (err, streams) { - assert(!err, err); - - assert.strictEqual(streams[0].filename, 'fixture.html-1024x768.png'); + t.assert(!err, err); + t.assert(streams[0].filename === 'fixture.html-1024x768.png'); streams[0].once('data', function (data) { - assert(data.length > 1000); - cb(); + t.assert(data.length > 1000); }); }); }); -it('should fetch resolutions from w3counter', function (cb) { +test('fetch resolutions from w3counter', function (t) { + t.plan(3); + var pageres = new Pageres() .src('yeoman.io', ['w3counter']); pageres.run(function (err, streams) { - assert(!err, err); - assert.strictEqual(streams.length, 10); + t.assert(!err, err); + t.assert(streams.length === 10); streams[0].once('data', function (data) { - assert(data.length > 1000); - cb(); + t.assert(data.length > 1000); }); }); }); -it('should save image', function (cb) { +test('save image', function (t) { + t.plan(2); + var pageres = new Pageres() .src('http://todomvc.com', ['1024x768']) .dest(__dirname); pageres.run(function (err) { - assert(!err); - assert(fs.existsSync('todomvc.com-1024x768.png')); + t.assert(!err, err); + t.assert(fs.existsSync('todomvc.com-1024x768.png')); fs.unlinkSync('todomvc.com-1024x768.png'); - cb(); }); });