-
Notifications
You must be signed in to change notification settings - Fork 10
/
copyfile.test.js
56 lines (49 loc) · 1.29 KB
/
copyfile.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
import assert from 'assert'
import path from 'path'
import fs from 'fs'
import download from '../'
import { randomFilename } from '../lib/utils'
let readFile = f => fs.readFileSync(f).toString()
let getFileSize = f => fs.statSync(f).size
describe('es2015_demo', () => {
it('复制本地文件成功', done => {
let source = __filename
let target = randomFilename()
let onProgress = false
download(source, target, (size, total) => {
onProgress = true
assert.equal(size, total)
assert.equal(total, getFileSize(source))
})
.then(filename => {
assert.equal(onProgress, true)
assert.equal(target, filename)
assert.equal(readFile(source), readFile(target))
done()
})
.catch(err => {
throw err
})
})
})
it('复制本地文件成功 callback', done => {
let source = __filename
let target = randomFilename()
let onProgress = false
download(
source,
target,
(size, total) => {
onProgress = true
assert.equal(size, total)
assert.equal(total, getFileSize(source))
},
(err, filename) => {
assert.equal(err, null)
assert.equal(onProgress, true)
assert.equal(target, filename)
assert.equal(readFile(source), readFile(target))
done()
}
)
})