forked from transitive-bullshit/puppeteer-lottie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
126 lines (99 loc) · 2.55 KB
/
index.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
'use strict'
const ffmpegProbe = require('ffmpeg-probe')
const fs = require('fs-extra')
const path = require('path')
const test = require('ava')
const imageSize = require('image-size')
const tempy = require('tempy')
const { sprintf } = require('sprintf-js')
const renderLottie = require('.')
const bodymovin = 'fixtures/bodymovin.json'
test('bodymovin.json => single frame png', async (t) => {
const output = tempy.file({ extension: 'png' })
await renderLottie({
path: bodymovin,
quiet: true,
output
})
const image = imageSize(output)
t.is(image.width, 1820)
t.is(image.height, 275)
await fs.remove(output)
})
test('bodymovin.json => single specific frame png', async (t) => {
const output = tempy.file({ extension: 'png' })
await renderLottie({
path: bodymovin,
quiet: true,
frame: 103,
output
})
const image = imageSize(output)
t.is(image.width, 1820)
t.is(image.height, 275)
await fs.remove(output)
})
test('bodymovin.json => single frame jpg scale=640:-1', async (t) => {
const output = tempy.file({ extension: 'jpg' })
await renderLottie({
path: bodymovin,
quiet: true,
width: 640,
output
})
const image = imageSize(output)
t.is(image.width, 640)
t.is(image.height, 96)
await fs.remove(output)
})
test('bodymovin.json => png frames scale=-1:100', async (t) => {
const temp = tempy.directory()
const output = path.join(temp, 'frame-%d.png')
await renderLottie({
path: bodymovin,
quiet: true,
height: 100,
output
})
for (let i = 1; i < 103; ++i) {
const image = imageSize(sprintf(output, i))
t.is(image.width, 661)
t.is(image.height, 100)
}
await fs.remove(output)
})
if (!process.env.CI) {
test('bodymovin.json => GIF', async (t) => {
const output = tempy.file({ extension: 'gif' })
await renderLottie({
path: bodymovin,
quiet: true,
output
})
console.log(output)
const image = imageSize(output)
console.log(image)
t.is(image.width, 1820)
t.is(image.height, 275)
await fs.remove(output)
})
}
test('bodymovin.json => mp4', async (t) => {
const output = tempy.file({ extension: 'mp4' })
await renderLottie({
path: bodymovin,
quiet: true,
ffmpegOptions: {
crf: 22,
profileVideo: 'high',
preset: 'fast'
},
output
})
const probe = await ffmpegProbe(output)
// height is scaled up a bit because h264 encoder requires an even height
t.is(probe.width, 1820)
t.is(probe.height, 274)
t.is(probe.streams[0].profile, 'High')
await fs.remove(output)
})