mirror of
https://github.com/danbulant/pngjs
synced 2026-07-08 04:30:33 +00:00
Tap ftw
This commit is contained in:
parent
cdd6f0c5ab
commit
288a696584
4 changed files with 93 additions and 101 deletions
|
|
@ -32,9 +32,9 @@
|
||||||
"example": "examples"
|
"example": "examples"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"coverage": "istanbul -- cover ./test nolarge",
|
"coverage": "istanbul -- cover node_modules/tape/bin/tape test/*-spec.js nolarge",
|
||||||
"coverage-report": "npm run coverage && istanbul report html",
|
"coverage-report": "npm run coverage && istanbul report html",
|
||||||
"test": "node test",
|
"test": "tape test/*-spec.js nolarge | tap-dot && node test/run-compare",
|
||||||
"lint": "eslint lib"
|
"lint": "eslint lib"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
@ -51,6 +51,8 @@
|
||||||
"eslint": "^1.0.0",
|
"eslint": "^1.0.0",
|
||||||
"istanbul": "^0.3.17",
|
"istanbul": "^0.3.17",
|
||||||
"phantomjs": "^1.9.17",
|
"phantomjs": "^1.9.17",
|
||||||
"serve-static": "^1.10.0"
|
"serve-static": "^1.10.0",
|
||||||
|
"tap-dot": "^1.0.0",
|
||||||
|
"tape": "^4.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
88
test/convert-images-spec.js
Normal file
88
test/convert-images-spec.js
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
var PNG = require('../lib/png').PNG;
|
||||||
|
var test = require('tape');
|
||||||
|
|
||||||
|
fs.readdir(__dirname + '/in/', function (err, files) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
files = files.filter(function(file) {
|
||||||
|
return ((process.argv[3] || "").indexOf("nolarge") < 0 || !file.match(/large/i)) && Boolean(file.match(/\.png$/i));
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Converting images");
|
||||||
|
|
||||||
|
files.forEach(function (file) {
|
||||||
|
|
||||||
|
var expectedError = false;
|
||||||
|
if (file.match(/^x/)) {
|
||||||
|
expectedError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('convert sync - ' + file, function(t) {
|
||||||
|
|
||||||
|
if (file.match(/large/)) {
|
||||||
|
t.timeoutAfter(1000 * 60);
|
||||||
|
} else {
|
||||||
|
t.timeoutAfter(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = fs.readFileSync(__dirname + '/in/' + file);
|
||||||
|
try {
|
||||||
|
var png = PNG.sync.read(data);
|
||||||
|
} catch (e) {
|
||||||
|
if (!expectedError) {
|
||||||
|
t.fail('Unexpected error parsing..' + file + '\n' + e.message + "\n" + e.stack);
|
||||||
|
} else {
|
||||||
|
t.pass("completed");
|
||||||
|
}
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expectedError) {
|
||||||
|
t.fail("Sync: Error expected, parsed fine .. - " + file);
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
var outpng = new PNG();
|
||||||
|
outpng.gamma = png.gamma;
|
||||||
|
outpng.data = png.data;
|
||||||
|
outpng.width = png.width;
|
||||||
|
outpng.height = png.height;
|
||||||
|
outpng.pack()
|
||||||
|
.pipe(fs.createWriteStream(__dirname + '/outsync/' + file)
|
||||||
|
.on("finish", function () {
|
||||||
|
t.pass("completed");
|
||||||
|
t.end();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert async - ' + file, function(t) {
|
||||||
|
fs.createReadStream(__dirname + '/in/' + file)
|
||||||
|
.pipe(new PNG())
|
||||||
|
.on('error', function (err) {
|
||||||
|
if (!expectedError) {
|
||||||
|
t.fail("Async: Unexpected error parsing.." + file + '\n' + err.message + '\n' + err.stack);
|
||||||
|
} else {
|
||||||
|
t.pass("completed");
|
||||||
|
}
|
||||||
|
t.end();
|
||||||
|
})
|
||||||
|
.on('parsed', function () {
|
||||||
|
|
||||||
|
if (expectedError) {
|
||||||
|
t.fail("Async: Error expected, parsed fine .." + file);
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pack()
|
||||||
|
.pipe(
|
||||||
|
fs.createWriteStream(__dirname + '/out/' + file)
|
||||||
|
.on("finish", function() {
|
||||||
|
t.pass("completed");
|
||||||
|
t.end();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
|
|
||||||
var fs = require('fs'),
|
|
||||||
PNG = require('../lib/png').PNG;
|
|
||||||
|
|
||||||
module.exports = function(done) {
|
|
||||||
|
|
||||||
fs.readdir(__dirname + '/in/', function (err, files) {
|
|
||||||
if (err) throw err;
|
|
||||||
|
|
||||||
files = files.filter(function(file) {
|
|
||||||
return ((process.argv[2] || "").indexOf("nolarge") < 0 || !file.match(/large/i)) && Boolean(file.match(/\.png$/i));
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("Converting images");
|
|
||||||
|
|
||||||
var completed = 0;
|
|
||||||
var expected = files.length * 2;
|
|
||||||
var anyFailures = false;
|
|
||||||
function complete(isSuccessful) {
|
|
||||||
completed++;
|
|
||||||
anyFailures = anyFailures || !isSuccessful;
|
|
||||||
if (expected === completed) {
|
|
||||||
if (anyFailures) {
|
|
||||||
process.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
files.forEach(function (file) {
|
|
||||||
|
|
||||||
//console.log(file);
|
|
||||||
var expectedError = false;
|
|
||||||
if (file.match(/^x/)) {
|
|
||||||
expectedError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var syncError = false;
|
|
||||||
var data = fs.readFileSync(__dirname + '/in/' + file);
|
|
||||||
try {
|
|
||||||
var png = PNG.sync.read(data);
|
|
||||||
} catch (e) {
|
|
||||||
if (!expectedError) {
|
|
||||||
console.log("Sync: Unexpected error parsing.." + file);
|
|
||||||
console.log(e);
|
|
||||||
console.log(e.stack);
|
|
||||||
}
|
|
||||||
syncError = true;
|
|
||||||
complete(expectedError);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!syncError) {
|
|
||||||
if (expectedError) {
|
|
||||||
console.log("Sync: Error expected, parsed fine ..", file);
|
|
||||||
complete(false);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var outpng = new PNG();
|
|
||||||
outpng.gamma = png.gamma;
|
|
||||||
outpng.data = png.data;
|
|
||||||
outpng.width = png.width;
|
|
||||||
outpng.height = png.height;
|
|
||||||
outpng.pack()
|
|
||||||
.pipe(fs.createWriteStream(__dirname + '/outsync/' + file)
|
|
||||||
.on("finish", function () {
|
|
||||||
complete(true);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.createReadStream(__dirname + '/in/' + file)
|
|
||||||
.pipe(new PNG())
|
|
||||||
.on('error', function (err) {
|
|
||||||
if (!expectedError) {
|
|
||||||
console.log("Async: Unexpected error parsing.." + file, err);
|
|
||||||
}
|
|
||||||
complete(expectedError);
|
|
||||||
})
|
|
||||||
.on('parsed', function () {
|
|
||||||
|
|
||||||
if (expectedError) {
|
|
||||||
console.log("Async: Error expected, parsed fine ..", file);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pack()
|
|
||||||
.pipe(
|
|
||||||
fs.createWriteStream(__dirname + '/out/' + file)
|
|
||||||
.on("finish", function() {
|
|
||||||
complete(true);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
require("./convert-images")(function() {
|
|
||||||
require("./run-compare");
|
|
||||||
});
|
|
||||||
Loading…
Reference in a new issue