-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
74 lines (64 loc) · 1.85 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
import assert from 'assert'
import rewire from 'rewire'
it('loadPlugin.catch(err) => just logging', () =>
rewire('.').__get__('loadPlugin')('invalidName')
)
describe('o2o', () => {
const o2o = rewire('.').__get__('o2o')
const plugins = []
it('imagemin(plugins)', () => assert.deepEqual(o2o(plugins), { plugins }))
it('imagemin({ plugins })', () => assert.deepEqual(o2o({ plugins }), { plugins }))
it('imagemin()', () => assert.equal(o2o().plugins.length, 4))
it('imagemin({ [name] })', () =>
assert.equal(
o2o({
gifsicle: {
interlaced: true,
optimizationLevel: 2,
colors: 200
},
jpegtran: {
progressive: true,
arithmetic: true
},
optipng: {
optimizationLevel: 4,
bitDepthReduction: false,
colorTypeReduction: false,
paletteReduction: false
},
svgo: {
full: true,
floatPrecision: 3,
dataurl: 'unenc',
plugins: [],
js2svg: {
pretty: true,
indent: ' '
}
}
})
.plugins
.length,
4
)
)
})
describe('imagemin', () => {
const imagemin = rewire('.')
const { promisify } = require('util')
const readFile = promisify(require('fs').readFile)
const { resolve } = require('path')
const test = (filename, opts) => () =>
readFile(resolve(`./images/${filename}`)).then(buffer =>
imagemin(opts)
.processor(buffer)
.then(processed =>
assert.ok(processed.length < buffer.length)
)
)
it('gif', test('gif.gif', { gifsicle: {} }))
it('jpg', test('jpg.jpg', { jpegtran: { arithmetic: true } }))
it('png', test('png.png', { optipng: {} }))
it('svg', test('svg.svg', { svgo: {} }))
})