-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest.js
More file actions
39 lines (34 loc) · 952 Bytes
/
Copy pathtest.js
File metadata and controls
39 lines (34 loc) · 952 Bytes
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
import fs from 'fs';
import path from 'path';
import gifsicle from 'gifsicle';
import isGif from 'is-gif';
import pathExists from 'path-exists';
import pify from 'pify';
import test from 'ava';
import m from './';
test('set temporary directories', t => {
const {input, output} = m;
t.truthy(input);
t.truthy(output);
});
test('return a optimized buffer', async t => {
const buf = await pify(fs.readFile)(path.join(__dirname, 'fixture.gif'));
const data = await m({
input: buf,
bin: gifsicle,
args: ['-o', m.output, m.input]
});
t.true(data.length < buf.length);
t.true(isGif(data));
});
test('remove temporary files', async t => {
const buf = await pify(fs.readFile)(path.join(__dirname, 'fixture.gif'));
const err = await t.throws(m({
input: buf,
bin: 'foobarunicorn',
args: [m.output, m.input]
}));
t.is(err.code, 'ENOENT');
t.false(await pathExists(err.spawnargs[0]));
t.false(await pathExists(err.spawnargs[1]));
});