Skip to content

Commit

Permalink
switch to ava for testing
Browse files Browse the repository at this point in the history
brings the testing time down from 31sec to 11sec :D
  • Loading branch information
sindresorhus committed Jul 6, 2014
1 parent 0d5c04d commit 663be15
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"node": ">=0.10.0" "node": ">=0.10.0"
}, },
"scripts": { "scripts": {
"test": "mocha --timeout 0" "test": "node test/test.js"
}, },
"files": [ "files": [
"index.js", "index.js",
Expand Down Expand Up @@ -62,8 +62,8 @@
"viewport-list": "^0.2.0" "viewport-list": "^0.2.0"
}, },
"devDependencies": { "devDependencies": {
"ava": "0.0.3",
"concat-stream": "^1.4.5", "concat-stream": "^1.4.5",
"image-size": "^0.3.0", "image-size": "^0.3.0"
"mocha": "*"
} }
} }
83 changes: 43 additions & 40 deletions test/test.js
Original file line number Original file line Diff line number Diff line change
@@ -1,119 +1,122 @@
'use strict'; 'use strict';
var assert = require('assert');
var fs = require('fs'); var fs = require('fs');
var test = require('ava');
var imageSize = require('image-size'); var imageSize = require('image-size');
var concat = require('concat-stream'); var concat = require('concat-stream');
var Pageres = require('../'); var Pageres = require('../');


process.chdir(__dirname); process.chdir(__dirname);


before(function () { test('generate screenshots', function (t) {
this.timeout(20000); t.plan(5);
});


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


pageres.run(function (err, streams) { pageres.run(function (err, streams) {
assert(!err, err); t.assert(!err, err);
assert.strictEqual(streams.length, 5); t.assert(streams.length === 5);
assert.strictEqual(streams[0].filename, 'todomvc.com-1280x1024.png'); t.assert(streams[0].filename === 'todomvc.com-1280x1024.png');
assert.strictEqual(streams[4].filename, 'yeoman.io-320x568.png'); t.assert(streams[4].filename === 'yeoman.io-320x568.png');


streams[0].once('data', function (data) { streams[0].once('data', function (data) {
assert(data.length > 1000); t.assert(data.length > 1000);
cb();
}); });
}); });
}); });


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() var pageres = new Pageres()
.src('http://www.microsoft.com/?query=pageres*|<>:"\\', ['1024x768']); .src('http://www.microsoft.com/?query=pageres*|<>:"\\', ['1024x768']);


pageres.run(function (err, streams) { pageres.run(function (err, streams) {
assert(!err, err); t.assert(!err, err);
assert.strictEqual(streams.length, 1); t.assert(streams.length === 1);
assert.strictEqual(streams[0].filename, 'microsoft.com!query=pageres-1024x768.png'); t.assert(streams[0].filename === 'microsoft.com!query=pageres-1024x768.png');
cb(); 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 }) var pageres = new Pageres({ delay: 2 })
.src('http://todomvc.com', ['1024x768']); .src('http://todomvc.com', ['1024x768']);


pageres.run(function (err, streams) { pageres.run(function (err, streams) {
assert(!err, err); t.assert(!err, err);


var now = new Date(); var now = new Date();


streams[0].once('data', function () { streams[0].once('data', function () {
assert((new Date()) - now > 2000); t.assert((new Date()) - now > 2000);
cb();
}); });
}); });
}); });


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 }) var pageres = new Pageres({ crop: true })
.src('http://todomvc.com', ['1024x768']); .src('http://todomvc.com', ['1024x768']);


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


streams[0].pipe(concat(function (data) { streams[0].pipe(concat(function (data) {
var size = imageSize(data); var size = imageSize(data);
assert.strictEqual(size.width, 1024); t.assert(size.width === 1024);
assert.strictEqual(size.height, 768); t.assert(size.height === 768);
cb();
})); }));
}); });
}); });


it('should support local relative files', function (cb) { test('support local relative files', function (t) {
t.plan(3);

var pageres = new Pageres() var pageres = new Pageres()
.src('fixture.html', ['1024x768']); .src('fixture.html', ['1024x768']);


pageres.run(function (err, streams) { pageres.run(function (err, streams) {
assert(!err, err); t.assert(!err, err);

t.assert(streams[0].filename === 'fixture.html-1024x768.png');
assert.strictEqual(streams[0].filename, 'fixture.html-1024x768.png');


streams[0].once('data', function (data) { streams[0].once('data', function (data) {
assert(data.length > 1000); t.assert(data.length > 1000);
cb();
}); });
}); });
}); });


it('should fetch resolutions from w3counter', function (cb) { test('fetch resolutions from w3counter', function (t) {
t.plan(3);

var pageres = new Pageres() var pageres = new Pageres()
.src('yeoman.io', ['w3counter']); .src('yeoman.io', ['w3counter']);


pageres.run(function (err, streams) { pageres.run(function (err, streams) {
assert(!err, err); t.assert(!err, err);
assert.strictEqual(streams.length, 10); t.assert(streams.length === 10);


streams[0].once('data', function (data) { streams[0].once('data', function (data) {
assert(data.length > 1000); t.assert(data.length > 1000);
cb();
}); });
}); });
}); });


it('should save image', function (cb) { test('save image', function (t) {
t.plan(2);

var pageres = new Pageres() var pageres = new Pageres()
.src('http://todomvc.com', ['1024x768']) .src('http://todomvc.com', ['1024x768'])
.dest(__dirname); .dest(__dirname);


pageres.run(function (err) { pageres.run(function (err) {
assert(!err); t.assert(!err, err);
assert(fs.existsSync('todomvc.com-1024x768.png')); t.assert(fs.existsSync('todomvc.com-1024x768.png'));
fs.unlinkSync('todomvc.com-1024x768.png'); fs.unlinkSync('todomvc.com-1024x768.png');
cb();
}); });
}); });

0 comments on commit 663be15

Please sign in to comment.