Skip to content

Commit 41192c5

Browse files
committed
test: add tests for WriteStream.prototype.flush
1 parent c05197c commit 41192c5

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const path = require('path');
5+
const fs = require('fs');
6+
7+
const tmpdir = require('../common/tmpdir');
8+
9+
tmpdir.refresh();
10+
11+
const file = path.join(tmpdir.path, 'write.txt');
12+
13+
function checkContent(stream, expected) {
14+
const actual = fs.readFileSync(file, 'utf-8');
15+
assert.strictEqual(actual, expected);
16+
}
17+
18+
{
19+
const stream = fs.createWriteStream(file);
20+
stream.write('data', common.mustCall(() => {
21+
stream.flush();
22+
checkContent(stream, 'data');
23+
stream.write('data');
24+
stream.flush(common.mustCall(() => {
25+
checkContent(stream, 'datadata');
26+
stream.destroy();
27+
}));
28+
}));
29+
}
30+
31+
{
32+
const stream = fs.createWriteStream(file);
33+
stream.write('data');
34+
checkContent(stream, '');
35+
stream.flush();
36+
checkContent(stream, 'data');
37+
stream.write('data');
38+
stream.flush();
39+
checkContent(stream, 'datadata');
40+
stream.destroy();
41+
}

0 commit comments

Comments
 (0)