forked from typicode/steno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
63 lines (50 loc) · 1.28 KB
/
Copy pathtest.js
File metadata and controls
63 lines (50 loc) · 1.28 KB
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
57
58
59
60
61
62
63
var fs = require('fs')
var path = require('path')
var after = require('after')
var test = require('tape')
var steno = require('./')
function reset () {
if (fs.existsSync('.~tmp.txt')) fs.unlinkSync('.~tmp.txt')
if (fs.existsSync('tmp.txt')) fs.unlinkSync('tmp.txt')
}
var max = 1000
test('There should be a race condition with fs', function (t) {
reset()
t.plan(1)
var next = after(max, function () {
t.notEqual(+fs.readFileSync('tmp.txt'), max)
})
for (var i = 0; i < max; ++i) {
fs.writeFile('tmp.txt', i, function (err) {
if (err) throw err
next()
})
}
})
test('There should not be a race condition with steno', function (t) {
reset()
t.plan(1)
var next = after(max, function () {
t.notEqual(+fs.readFileSync('tmp.txt'), max)
})
for (var i = 0; i < max; ++i) {
steno.writeFile('tmp.txt', i, function (err) {
if (err) throw err
next()
})
}
})
test('There should be a synchronous version', function (t) {
reset()
t.plan(1)
steno.writeFileSync('tmp.txt', 0)
t.equal(+fs.readFileSync('tmp.txt'), 0)
})
test('Error handling with steno', function (t) {
reset()
t.plan(1)
var file = path.join(__dirname, 'dir/doesnt/exist')
steno.writeFile(file, '', function (err) {
t.equal(err.code, 'ENOENT')
})
})