-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
48 lines (41 loc) · 918 Bytes
/
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
var test = require('tape');
var each = require('./');
var co = require('co');
var fs = require('fs');
test('args', function(t) {
co(function*() {
t.plan(9);
var arr = [0, 1, 2];
var i = 0;
yield each(arr, function*(el, j, all) {
t.equal(el, i);
t.equal(j, i);
t.deepEqual(all, arr);
i++;
});
});
});
test('backup', function(t) {
co(function*() {
t.plan(2);
var files = [
'index.js', 'README.md'
];
yield each(files, backup);
t.equal(yield read('index.js'), yield read('index.js.bck'));
t.equal(yield read('README.md'), yield read('README.md.bck'));
});
});
function read(path) {
return function(done) {
fs.readFile(path, 'utf8', done);
}
}
function backup(path) {
return function(done) {
fs.createReadStream(path)
.pipe(fs.createWriteStream(path + '.bck'))
.on('error', done)
.on('close', done);
};
}