File: read_write.t.mjs

package info (click to toggle)
libnginx-mod-js 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,808 kB
  • sloc: ansic: 114,096; perl: 8,447; javascript: 2,520; exp: 487; sh: 322; xml: 312; python: 181; makefile: 18
file content (47 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download
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
/*---
includes: [compareArray.js, compatFs.js]
flags: [async]
---*/

var fname = `${test_dir}/fs_promises_01`;

let stages = [];

let test = () => Promise.resolve()
.then(() => {
    return fsp.writeFile(fname, fname);
})
.then(data => {
    stages.push('init');
    assert.sameValue(data, undefined, 'init');
})
.then(() => {
    return fsp.readFile(fname).then(fsp.readFile);
})
.then(data => {
    stages.push('short circut');
    assert.sameValue(data.toString(), fname, 'short circut');
})
.then(() => {
    var read = fsp.readFile.bind(fsp, fname, 'utf8');
    var write = fsp.writeFile.bind(fsp, fname);
    var append = fsp.appendFile.bind(fsp, fname);

    return write(fname).then(read).then(append).then(read);
})
.then(data => {
    stages.push('chain');
    assert.sameValue(data, fname + fname, 'chain');
})
.then(() => {
    stages.push('errors ok');
})
.then(() => {
    assert.compareArray(stages, ["init", "short circut", "chain", "errors ok"]);
})

let p = Promise.resolve()
    .then(test)
    .then(() => assert.compareArray(stages, ["init", "short circut", "chain", "errors ok"]))

p.then($DONE, $DONE);