UNPKG

1.08 kBJavaScriptView Raw
1var fs = require('fs')
2var http = require('http')
3var nugget = require('../')
4var path = require('path')
5var test = require('tape')
6
7var testServer = http.createServer(function(req, res) {
8 res.end('hello')
9})
10
11var target = path.join(__dirname, 'resume.html')
12if (fs.existsSync(target)) fs.unlinkSync(target)
13
14testServer.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})