-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
94 lines (73 loc) · 2.44 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
import fs from 'node:fs';
import path from 'node:path';
import test from 'ava';
import {imageDimensionsFromStream, imageDimensionsFromData} from './index.js';
const matches = (t, filename, dimensions) => {
const data = fs.readFileSync(path.join('fixtures', filename));
t.deepEqual(imageDimensionsFromData(data), dimensions);
};
test('png', t => {
matches(t, 'png/valid.png', {width: 30, height: 20});
});
test('png - minified', t => {
matches(t, 'png/minified.png', {width: 30, height: 20});
});
test('png - apple minified', t => {
matches(t, 'png/apple-minified.png', {width: 30, height: 20});
});
test('png - invalid', t => {
matches(t, 'png/invalid.png', undefined);
});
test('png - animated', t => {
matches(t, 'png/animated.png', {width: 30, height: 17});
});
test('jpg', t => {
matches(t, 'jpeg/valid.jpg', {width: 200, height: 133});
});
test('jpg - no exif', t => {
matches(t, 'jpeg/no-exif.jpg', {width: 200, height: 133});
});
test('jpg - progressive', t => {
matches(t, 'jpeg/progressive.jpg', {width: 40, height: 27});
});
test('gif', t => {
matches(t, 'gif/valid.gif', {width: 30, height: 17});
});
test.failing('jpeg xl', t => {
matches(t, 'jpeg xl/valid.jxl', {width: 30, height: 17});
});
test('avif', t => {
matches(t, 'avif/valid.avif', {width: 30, height: 20});
});
test.failing('heic', t => {
matches(t, 'heic/valid.heic', {width: 30, height: 17});
});
test('webp - vp8', t => {
matches(t, 'webp/vp8.webp', {width: 30, height: 20});
});
test('webp - vp8l', t => {
matches(t, 'webp/vp8l.webp', {width: 30, height: 20});
});
test('webp - vp8x', t => {
matches(t, 'webp/vp8x.webp', {width: 30, height: 20});
});
test('webp - animated', t => {
matches(t, 'webp/animated.webp', {width: 30, height: 17});
});
test('imageDimensionsFromData - error handling on DataView methods', t => {
const data = fs.readFileSync('fixtures/png/valid.png').subarray(0, 20);
t.is(imageDimensionsFromData(data), undefined);
});
test('imageDimensionsFromStream - Node.js stream', async t => {
const stream = fs.createReadStream('fixtures/png/valid.png');
t.deepEqual(await imageDimensionsFromStream(stream), {width: 30, height: 20});
});
test('imageDimensionsFromStream - web stream', async t => {
const stream = ReadableStream.from(fs.createReadStream('fixtures/png/valid.png'));
t.deepEqual(await imageDimensionsFromStream(stream), {width: 30, height: 20});
});
test('empty', t => {
t.notThrows(() => {
imageDimensionsFromData(new Uint8Array());
});
});