diff --git a/package.json b/package.json index 603bef6..09bae1a 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,10 @@ "svgfilter": "=0.3.1" }, "devDependencies": { - "expect.js": "=0.2.0", "express": "=3.0.3", "mocha": "=1.7.3", - "request": "=2.12.0" + "request": "=2.12.0", + "unexpected": "=1.0.11" }, "scripts": { "test": "mocha", diff --git a/test/processImage.js b/test/processImage.js index a40538d..56e6f52 100644 --- a/test/processImage.js +++ b/test/processImage.js @@ -2,7 +2,7 @@ var express = require('express'), Path = require('path'), request = require('request'), passError = require('passerror'), - expect = require('expect.js'), + expect = require('unexpected'), processImage = require('../lib/processImage'), Stream = require('stream'), gm = require('gm'); @@ -43,38 +43,38 @@ describe('test server', function () { it('should not mess with request for non-image file', function (done) { request(baseUrl + '/something.txt', passError(done, function (response, body) { - expect(body).to.equal("foo\n"); - expect(response.headers['content-type']).to.equal('text/plain; charset=UTF-8'); + expect(body, 'to equal', 'foo\n'); + expect(response.headers['content-type'], 'to equal', 'text/plain; charset=UTF-8'); done(); })); }); it('should not mess with request for image with no query string', function (done) { request({url: baseUrl + '/ancillaryChunks.png', encoding: null}, passError(done, function (response, body) { - expect(body.length).to.equal(152); - expect(response.headers['content-type']).to.equal('image/png'); + expect(body.length, 'to equal', 152); + expect(response.headers['content-type'], 'to equal', 'image/png'); done(); })); }); it('should not mess with request for image with an unsupported operation in the query string', function (done) { request({url: baseUrl + '/ancillaryChunks.png?foo=bar', encoding: null}, passError(done, function (response, body) { - expect(body.length).to.equal(152); - expect(response.headers['content-type']).to.equal('image/png'); + expect(body.length, 'to equal', 152); + expect(response.headers['content-type'], 'to equal', 'image/png'); done(); })); }); it('should run the image through pngcrush when the pngcrush CGI param is specified', function (done) { request({url: baseUrl + '/ancillaryChunks.png?pngcrush=-rem+alla', encoding: null}, passError(done, function (response, body) { - expect(response.statusCode).to.equal(200); - expect(response.headers['content-type']).to.equal('image/png'); - expect(body.length).to.be.lessThan(152); - expect(body.length).to.be.greaterThan(0); + expect(response.statusCode, 'to equal', 200); + expect(response.headers['content-type'], 'to equal', 'image/png'); + expect(body.length, 'to be less than', 152); + expect(body.length, 'to be greater than', 0); getImageMetadataFromBuffer(body, passError(done, function (metadata) { - expect(metadata.format).to.equal('PNG'); - expect(metadata.size.width).to.equal(12); - expect(metadata.size.height).to.equal(5); + expect(metadata.format, 'to equal', 'PNG'); + expect(metadata.size.width, 'to equal', 12); + expect(metadata.size.height, 'to equal', 5); done(); })); })); @@ -82,14 +82,14 @@ describe('test server', function () { it('should run the image through pngquant when the pngquant CGI param is specified', function (done) { request({url: baseUrl + '/purplealpha24bit.png?pngquant', encoding: null}, passError(done, function (response, body) { - expect(response.statusCode).to.equal(200); - expect(response.headers['content-type']).to.equal('image/png'); - expect(body.length).to.be.lessThan(8285); - expect(body.length).to.be.greaterThan(0); + expect(response.statusCode, 'to equal', 200); + expect(response.headers['content-type'], 'to equal', 'image/png'); + expect(body.length, 'to be less than', 8285); + expect(body.length, 'to be greater than', 0); getImageMetadataFromBuffer(body, passError(done, function (metadata) { - expect(metadata.format).to.equal('PNG'); - expect(metadata.size.width).to.equal(100); - expect(metadata.size.height).to.equal(100); + expect(metadata.format, 'to equal', 'PNG'); + expect(metadata.size.width, 'to equal', 100); + expect(metadata.size.height, 'to equal', 100); done(); })); })); @@ -97,15 +97,15 @@ describe('test server', function () { it('should run the image through jpegtran when the jpegtran CGI param is specified', function (done) { request({url: baseUrl + '/turtle.jpg?jpegtran=-grayscale,-flip,horizontal', encoding: null}, passError(done, function (response, body) { - expect(response.statusCode).to.equal(200); - expect(response.headers['content-type']).to.equal('image/jpeg'); - expect(body.length).to.be.lessThan(105836); - expect(body.length).to.be.greaterThan(0); + expect(response.statusCode, 'to equal', 200); + expect(response.headers['content-type'], 'to equal', 'image/jpeg'); + expect(body.length, 'to be less than', 105836); + expect(body.length, 'to be greater than', 0); getImageMetadataFromBuffer(body, passError(done, function (metadata) { - expect(metadata.format).to.equal('JPEG'); - expect(metadata.size.width).to.equal(481); - expect(metadata.size.height).to.equal(424); - expect(metadata['Channel Depths'].Gray).to.equal('8 bits'); + expect(metadata.format, 'to equal', 'JPEG'); + expect(metadata.size.width, 'to equal', 481); + expect(metadata.size.height, 'to equal', 424); + expect(metadata['Channel Depths'].Gray, 'to equal', '8 bits'); done(); })); })); @@ -113,15 +113,15 @@ describe('test server', function () { it('should run the image through graphicsmagick when methods exposed by the gm module are added as CGI params', function (done) { request({url: baseUrl + '/turtle.jpg?resize=340,300', encoding: null}, passError(done, function (response, body) { - expect(response.statusCode).to.equal(200); - expect(response.headers['content-type']).to.equal('image/jpeg'); - expect(body.slice(0, 10).toString()).to.equal(new Buffer([0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46]).toString()); - expect(body.length).to.be.lessThan(105836); - expect(body.length).to.be.greaterThan(0); + expect(response.statusCode, 'to equal', 200); + expect(response.headers['content-type'], 'to equal', 'image/jpeg'); + expect(body.slice(0, 10).toString(), 'to equal', new Buffer([0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46]).toString()); + expect(body.length, 'to be less than', 105836); + expect(body.length, 'to be greater than', 0); getImageMetadataFromBuffer(body, passError(done, function (metadata) { - expect(metadata.format).to.equal('JPEG'); - expect(metadata.size.width).to.equal(340); - expect(metadata.size.height).to.equal(300); + expect(metadata.format, 'to equal', 'JPEG'); + expect(metadata.size.width, 'to equal', 340); + expect(metadata.size.height, 'to equal', 300); done(); })); })); @@ -129,14 +129,14 @@ describe('test server', function () { it('should run the image through svgfilter when the svgfilter parameter is specified', function (done) { request({url: baseUrl + '/dialog-information.svg?svgfilter=--runScript=addBogusElement.js,--bogusElementId=theBogusElementId'}, passError(done, function (response, svgText) { - expect(response.statusCode).to.equal(200); - expect(response.headers['content-type']).to.equal('image/svg+xml'); - expect(response.headers.etag).to.be.ok(); - // expect(response.headers.etag).to.match(/^"\d+-\d+-697ebc4fd42e6b09794a5d60968435a7-processimage"$/); - expect(svgText).to.match(/