forked from typicode/lowdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFile.test.ts
More file actions
35 lines (25 loc) · 741 Bytes
/
TextFile.test.ts
File metadata and controls
35 lines (25 loc) · 741 Bytes
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
import { deepStrictEqual as deepEqual, strictEqual as equal } from 'assert'
import tempy from 'tempy'
import { TextFile } from './TextFile.js'
export async function testTextFile() {
const str = 'foo'
const filename = tempy.file()
const file = new TextFile(filename)
// Null if file doesn't exist
equal(await file.read(), null)
// Write
equal(await file.write(str), undefined)
// Read
deepEqual(await file.read(), str)
}
export async function testRaceCondition() {
const filename = tempy.file()
const file = new TextFile(filename)
const promises = []
let i = 0
for (; i <= 100; i++) {
promises.push(file.write(String(i)))
}
await Promise.all(promises)
equal(await file.read(), String(i - 1))
}