forked from aheckmann/gm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (64 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// gm - Copyright Aaron Heckmann <[email protected]> (MIT Licensed)
var async = require('async');
var dir = __dirname + '/../examples/imgs';
var gm = require('../');
var assert = require('assert');
var fs = require('fs');
var only = process.argv.slice(2);
gm.integration = !! ~process.argv.indexOf('--integration');
if (gm.integration) only.shift();
var files = fs.readdirSync(__dirname).filter(filter);
function filter (file) {
if (!/\.js$/.test(file)) return false;
if ('index.js' === file) return false;
if (only.length && !~only.indexOf(file)) return false;
var filename = __dirname + '/' + file;
if (!fs.statSync(filename).isFile()) return false;
return true;
}
function test (imagemagick) {
if (imagemagick)
return gm(dir + '/original.jpg').options({ imageMagick: true });
return gm(dir + '/original.jpg');
}
function finish (filename) {
return function (err) {
if (err) {
console.error('\n\nError occured with file: ' + filename);
throw err;
}
process.stdout.write('\033[2K');
process.stdout.write('\033[0G');
process.stdout.write('pending ' + (q.length()+q.running()));
}
}
process.stdout.write('\033[?25l');
var q = async.queue(function (task, callback) {
var filename = task.filename;
var im = task.imagemagick;
require(filename)(test(im), dir, function (err) {
finish(filename)(err);
callback();
}, gm, im);
}, 1);
q.drain = function(){
process.stdout.write('\033[?25h');
process.stdout.write('\033[2K');
process.stdout.write('\033[0G');
console.error("\n\u001B[32mAll tests passed\u001B[0m");
};
files = files.map(function (file) {
return __dirname + '/' + file
})
files.forEach(function (file) {
q.push({
imagemagick: false,
filename: file
})
})
files.forEach(function (file) {
q.push({
imagemagick: true,
filename: file
})
})