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);
|