-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
brings the testing time down from 31sec to 11sec :D
- Loading branch information
1 parent
0d5c04d
commit 663be15
Showing
2 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |