/
others.spec.js
76 lines (62 loc) · 2.13 KB
/
others.spec.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
'use strict';
var expect = require('expect.js');
var path = require('path');
var fs = require('fs');
var imageSize = require('..');
// If something other than a buffer or filepath is passed
describe('Invalid invocation', function () {
describe('invalid type', function () {
it('should throw', function() {
expect(imageSize.bind(null, {})).to.throwException(function (e) {
expect(e).to.be.a(TypeError);
expect(e.message).to.be('invalid invocation');
});
});
});
describe('non existant file', function () {
it('should throw', function() {
expect(imageSize.bind(null, '/monkey/man/yo')).to.throwException(function (e) {
// expect(e.errno).to.be(34);
expect(e.code).to.be('ENOENT');
});
});
});
describe('passing buffer for tiff', function () {
var buffer;
beforeEach(function () {
var bufferSize = 2048;
var file = 'specs/images/valid/tiff/little-endian.tiff';
buffer = Buffer.alloc(bufferSize);
var filepath = path.resolve(file);
var descriptor = fs.openSync(filepath, 'r');
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
});
it('should throw', function () {
expect(imageSize.bind(null, buffer)).to.throwException(function (e) {
expect(e).to.be.a(TypeError);
expect(e.message).to.contain('doesn\'t support buffer');
});
});
});
});
describe('Callback function', function () {
it('should be called only once', function(done) {
var tmpError = new Error();
var origException = process.listeners('uncaughtException').pop();
process.removeListener('uncaughtException', origException);
process.once('uncaughtException', function (err) {
expect(err).to.be(tmpError);
});
imageSize('specs/images/valid/jpg/sample.jpg', function() {
process.nextTick(function () {
done();
});
throw tmpError;
});
});
});
describe('.types property', function () {
it('should expose supported file types', function() {
expect(imageSize.types).to.eql(['bmp', 'cur', 'dds', 'gif', 'icns', 'ico', 'jpg', 'png', 'psd', 'svg', 'tiff', 'webp']);
});
});