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
Expand Up @@ -16,7 +16,7 @@
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha --timeout 0"
"test": "node test/test.js"
},
"files": [
"index.js",
Expand Down Expand Up @@ -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"
}
}
83 changes: 43 additions & 40 deletions 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();
});
});

0 comments on commit 663be15

Please sign in to comment.