-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
pica.js
56 lines (42 loc) · 1.2 KB
/
pica.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
'use strict';
const _pica = require('../');
const assert = require('assert');
const { createCanvas } = require('canvas');
describe('API', function () {
// Need node 8 to run
it('Upscale (unexpected use) via wasm should not crash', function () {
const p = _pica({ features: [ 'wasm' ] });
const input = new Uint8Array(500 * 500 * 4);
return p.init().then(() => p.resizeBuffer({
src: input,
width: 500,
height: 500,
toWidth: 1000,
toHeight: 1000
}));
});
it('Should return result in promise', function () {
let src = createCanvas();
src.width = 1000;
src.height = 1000;
let to = createCanvas();
to.width = 100;
to.height = 100;
return _pica().resize(src, to).then(result => {
assert.strictEqual(result, to);
});
});
it('Resize with bad output size should fail', function () {
let src = createCanvas();
src.width = 1000;
src.height = 1000;
let to = createCanvas();
to.width = 0;
to.height = 0;
return _pica().resize(src, to)
.then(() => { throw new Error('Resize should fail'); })
.catch(err => {
assert.equal(err.message, 'Invalid output size: 0x0');
});
});
});