1 | var fs = require('fs')
|
2 | var http = require('http')
|
3 | var nugget = require('../')
|
4 | var path = require('path')
|
5 | var test = require('tape')
|
6 |
|
7 | var testServer = http.createServer(function(req, res) {
|
8 | res.end('hello')
|
9 | })
|
10 |
|
11 | var target = path.join(__dirname, 'resume.html')
|
12 | if (fs.existsSync(target)) fs.unlinkSync(target)
|
13 |
|
14 | testServer.listen(0, function() {
|
15 | var port = this.address().port
|
16 | test('fetches file', function(t) {
|
17 | nugget('http://localhost:' + port + '/resume.html', {dir: __dirname}, function(err) {
|
18 | t.ok(fs.existsSync(target), 'downloaded file')
|
19 | if (fs.existsSync(target)) fs.unlinkSync(target)
|
20 | t.end()
|
21 | })
|
22 | })
|
23 |
|
24 | test('has progress events', function(t) {
|
25 | var gotProgress = false
|
26 | var dl = nugget('http://localhost:' + port + '/resume.html', {dir: __dirname}, function(err) {
|
27 | t.notOk(err, 'no error')
|
28 | t.ok(gotProgress, 'got progress event')
|
29 | t.end()
|
30 | testServer.close()
|
31 | })
|
32 | dl.once('progress', function(data) {
|
33 | t.ok(data.hasOwnProperty('percentage'), 'has percentage')
|
34 | gotProgress = true
|
35 | })
|
36 | })
|
37 | })
|