-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.test.js
56 lines (44 loc) · 1.65 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
'use strict'
const fs = require('fs-extra')
const path = require('path')
const test = require('ava')
const globby = require('globby')
const lqip = require('.')
const fixtures = globby.sync('fixtures/*.{jpg,jpeg,webp,png}')
const outputDir = 'output'
test.before(async () => {
await fs.ensureDir(outputDir)
})
for (const fixture of fixtures) {
const name = fixture.split('/').pop().split('.').shift()
test(`${fixture} => webp`, async (t) => {
const result = await lqip(fixture)
t.truthy(result)
t.true(Buffer.isBuffer(result.content))
t.true(result.metadata.width < result.metadata.originalWidth)
t.true(result.metadata.height < result.metadata.originalHeight)
await fs.writeFile(path.join(outputDir, `${name}.webp`), result.content)
console.log(fixture, result.metadata)
t.snapshot(result.metadata)
})
test(`${fixture} => jpeg`, async (t) => {
const result = await lqip(fixture, { outputFormat: 'jpeg' })
t.truthy(result)
t.true(Buffer.isBuffer(result.content))
t.true(result.metadata.width < result.metadata.originalWidth)
t.true(result.metadata.height < result.metadata.originalHeight)
await fs.writeFile(path.join(outputDir, `${name}.jpg`), result.content)
console.log(fixture, result.metadata)
t.snapshot(result.metadata)
})
}
test('array of inputs', async (t) => {
const results = await lqip(fixtures)
t.true(Array.isArray(results))
t.is(results.length, fixtures.length)
for (const result of results) {
t.true(Buffer.isBuffer(result.content))
t.true(result.metadata.width < result.metadata.originalWidth)
t.true(result.metadata.height < result.metadata.originalHeight)
}
})