Skip to content

Commit 5fb31c4

Browse files
committed
Bump AVA version
1 parent 9b30963 commit 5fb31c4

7 files changed

Lines changed: 131 additions & 193 deletions

File tree

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- 'iojs'
5-
- '0.12'
6-
- '0.10'
4+
- '6'
5+
- '4'

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"node": ">=0.10.0"
1414
},
1515
"scripts": {
16-
"test": "xo && node test/test.js"
16+
"test": "xo && ava"
1717
},
1818
"files": [
1919
"index.js"
@@ -33,10 +33,12 @@
3333
"os-filter-obj": "^1.0.0"
3434
},
3535
"devDependencies": {
36-
"ava": "^0.0.4",
37-
"nock": "^2.6.0",
38-
"path-exists": "^1.0.0",
36+
"ava": "*",
37+
"nock": "^8.0.0",
38+
"path-exists": "^3.0.0",
39+
"pify": "^2.3.0",
3940
"rimraf": "^2.2.8",
41+
"tempfile": "^1.1.1",
4042
"xo": "*"
4143
}
4244
}

test.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import nock from 'nock';
4+
import pathExists from 'path-exists';
5+
import pify from 'pify';
6+
import rimraf from 'rimraf';
7+
import test from 'ava';
8+
import tempfile from 'tempfile';
9+
import Fn from './';
10+
11+
const fsP = pify(fs);
12+
const rimrafP = pify(rimraf);
13+
const fixture = path.join.bind(path, __dirname, 'fixtures');
14+
15+
test.beforeEach(() => {
16+
nock('http://foo.com')
17+
.get('/gifsicle.tar.gz')
18+
.replyWithFile(200, fixture('gifsicle-' + process.platform + '.tar.gz'))
19+
.get('/gifsicle-darwin.tar.gz')
20+
.replyWithFile(200, fixture('gifsicle-darwin.tar.gz'))
21+
.get('/gifsicle-win32.tar.gz')
22+
.replyWithFile(200, fixture('gifsicle-win32.tar.gz'))
23+
.get('/test.js')
24+
.replyWithFile(200, __filename);
25+
});
26+
27+
test('expose a constructor', t => {
28+
t.is(typeof Fn, 'function');
29+
});
30+
31+
test('add a source', t => {
32+
const bin = new Fn().src('http://foo.com/bar.tar.gz');
33+
t.is(bin._src[0].url, 'http://foo.com/bar.tar.gz');
34+
});
35+
36+
test('add a source to a specific os', t => {
37+
const bin = new Fn().src('http://foo.com', process.platform);
38+
t.is(bin._src[0].os, process.platform);
39+
});
40+
41+
test('set destination directory', t => {
42+
const bin = new Fn().dest(path.join(__dirname, 'foo'));
43+
t.is(bin._dest, path.join(__dirname, 'foo'));
44+
});
45+
46+
test('set which file to use as the binary', t => {
47+
const bin = new Fn().use('foo');
48+
t.is(bin._use, 'foo');
49+
});
50+
51+
test('set a version range to test against', t => {
52+
const bin = new Fn().version('1.0.0');
53+
t.is(bin._version, '1.0.0');
54+
});
55+
56+
test('get the binary path', t => {
57+
const bin = new Fn()
58+
.dest('tmp')
59+
.use('foo');
60+
61+
t.is(bin.path(), path.join('tmp', 'foo'));
62+
});
63+
64+
test('verify that a binary is working', async t => {
65+
const bin = new Fn()
66+
.src('http://foo.com/gifsicle.tar.gz')
67+
.dest(tempfile())
68+
.use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle');
69+
70+
await pify(bin.run.bind(bin))();
71+
t.true(await pathExists(bin.path()));
72+
await rimrafP(bin.dest());
73+
});
74+
75+
test('meet the desired version', async t => {
76+
const bin = new Fn()
77+
.src('http://foo.com/gifsicle.tar.gz')
78+
.dest(tempfile())
79+
.use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle')
80+
.version('>=1.71');
81+
82+
await pify(bin.run.bind(bin))();
83+
t.true(await pathExists(bin.path()));
84+
await rimrafP(bin.dest());
85+
});
86+
87+
test('download files even if they are not used', async t => {
88+
const bin = new Fn({strip: 0, skipCheck: true})
89+
.src('http://foo.com/gifsicle-darwin.tar.gz')
90+
.src('http://foo.com/gifsicle-win32.tar.gz')
91+
.src('http://foo.com/test.js')
92+
.dest(tempfile())
93+
.use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle');
94+
95+
await pify(bin.run.bind(bin))();
96+
const files = await fsP.readdirSync(bin.dest());
97+
98+
t.is(files.length, 3);
99+
t.is(files[0], 'gifsicle');
100+
t.is(files[1], 'gifsicle.exe');
101+
t.is(files[2], 'test.js');
102+
103+
await rimrafP(bin.dest());
104+
});
105+
106+
test('skip running binary check', async t => {
107+
const bin = new Fn({skipCheck: true})
108+
.src('http://foo.com/gifsicle.tar.gz')
109+
.dest(tempfile())
110+
.use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle');
111+
112+
await pify(bin.run.bind(bin))(['--shouldNotFailAnyway']);
113+
t.true(await pathExists(bin.path()));
114+
await rimrafP(bin.dest());
115+
});
116+
117+
test('error if no binary is found and no source is provided', t => {
118+
const bin = new Fn()
119+
.dest(tempfile())
120+
.use(process.platform === 'win32' ? 'gifsicle.exe' : 'gifsicle');
121+
122+
t.throws(pify(bin.run.bind(bin))(), 'No binary found matching your system. It\'s probably not supported.');
123+
});

test/test.js

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)