forked from hacksparrow/node-easyimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
206 lines (157 loc) · 5.35 KB
/
test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
var assert = chai.assert;
var expect = chai.expect;
var fs = require('fs');
var outputDir = './output';
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
var easyimg = require('./easyimage.js');
var srcimg = 'kitten.jpg';
var warningimg = 'letter.png';
describe('.info - ', function () {
describe('valid file type', function () {
it('should show file info', function () {
return easyimg.info(srcimg);
});
});
describe('valid file type with warning', function () {
it('should show file info', function () {
return expect(easyimg.info(warningimg)).to.eventually.have.property('warnings');
});
});
describe('invalid file type', function () {
it('should not be supported', function () {
return assert.isRejected(easyimg.info('./test.js'), /^identify/);
});
});
});
describe('.convert -', function () {
afterEach(function(done) {
fs.unlink('./output/convert.png', function() {
/* ignore any error unlinking */
done();
});
});
it('should convert an image format to another', function () {
return easyimg.convert({src:srcimg, dst:'./output/convert.png', quality:10}).then(function (file) {
file.should.be.a('object');
file.should.have.property('type');
file.type.should.be.equal('PNG');
file.name.should.be.equal('convert.png');
});
});
});
describe('.rotate -', function () {
afterEach(function(done) {
fs.unlink('./output/convert.png', function() {
/* ignore any error unlinking */
done();
});
});
it('should rotate the image by 90 degrees', function () {
return easyimg.info(srcimg).then(function(info){
info.should.have.property('width')
info.should.have.property('height')
// Mainly check only if width and height are swaped
return easyimg.rotate({src:srcimg, dst:'./output/convert.jpg', degrees: 90}).then(function (file) {
file.should.be.a('object');
file.name.should.be.equal('convert.jpg');
file.should.have.property('width');
file.width.should.be.equal(info.height);
file.height.should.be.equal(info.width);
});
})
});
});
describe('.resize -', function () {
afterEach(function(done) {
fs.unlink('./output/resize.jpg', function() {
/* ignore any error unlinking */
done();
});
});
it('should resize an image', function () {
return easyimg.resize({src:srcimg, dst:'./output/resize.jpg', width:640, height:480}).then(function (file) {
file.should.be.a('object');
file.should.have.property('width');
file.width.should.be.equal(640);
file.name.should.be.equal('resize.jpg');
});
});
});
describe('.crop -', function () {
afterEach(function(done) {
fs.unlink('./output/crop.jpg', function() {
/* ignore any error unlinking */
done();
});
});
it('should crop an image', function () {
return easyimg.crop({
src:srcimg, dst:'./output/crop.jpg',
cropwidth:128, cropheight:128,
x:400, y:0
}).then(function (file) {
file.should.be.a('object');
file.should.have.property('width');
file.width.should.be.equal(128);
file.name.should.be.equal('crop.jpg');
});
});
});
describe('.rescrop -', function () {
afterEach(function(done) {
fs.unlink('./output/rescrop.jpg', function() {
/* ignore any error unlinking */
done();
});
});
it('should resize and crop', function () {
return easyimg.rescrop({
src:srcimg, dst:'./output/rescrop.jpg',
width:400, height:5400,
cropwidth:100, cropheight:100,
x:0, y:0
}).then(function (file) {
file.should.be.a('object');
file.should.have.property('width');
file.width.should.be.equal(100);
file.name.should.be.equal('rescrop.jpg');
});
});
});
describe('.thumbnail -', function () {
afterEach(function(done) {
fs.unlink('./output/thumbnail.jpg', function() {
/* ignore any error unlinking */
done();
});
});
//this.timeout(5000);
it('should generate a thumbnail', function () {
return easyimg.thumbnail({
src:srcimg, dst:'./output/thumbnail.jpg',
width:128, height:128,
x:0, y:0
}).then(function (file) {
file.should.be.a('object');
file.should.have.property('width');
file.width.should.be.equal(128);
file.name.should.be.equal('thumbnail.jpg');
});
});
});
describe('.exec -', function () {
afterEach(function(done) {
fs.unlink('./output/command.gif', function() {
/* ignore any error unlinking */
done();
});
});
it('should invoke `convert` command', function () {
return easyimg.exec('convert '+ srcimg +' ./output/command.gif').then(function (file) {
});
});
});