(sync)
| 30 | runTests(true); |
| 31 | |
| 32 | function runTests(sync) { |
| 33 | { |
| 34 | const dest = getTempFile(); |
| 35 | const mode = 0o666; |
| 36 | const stream = new Utf8Stream({ dest, sync, mode }); |
| 37 | |
| 38 | stream.on('ready', common.mustCall(() => { |
| 39 | assert.ok(stream.write('hello world\n')); |
| 40 | assert.ok(stream.write('something else\n')); |
| 41 | |
| 42 | stream.end(); |
| 43 | |
| 44 | stream.on('finish', common.mustCall(() => { |
| 45 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 46 | assert.strictEqual(data, 'hello world\nsomething else\n'); |
| 47 | // The actual mode may vary depending on the platform, |
| 48 | // so we check only the first bit. |
| 49 | assert.strictEqual(statSync(dest).mode & 0o700, 0o600); |
| 50 | })); |
| 51 | })); |
| 52 | })); |
| 53 | } |
| 54 | |
| 55 | { |
| 56 | const dest = getTempFile(); |
| 57 | const defaultMode = 0o600; |
| 58 | const stream = new Utf8Stream({ dest, sync }); |
| 59 | stream.on('ready', common.mustCall(() => { |
| 60 | assert.ok(stream.write('hello world\n')); |
| 61 | assert.ok(stream.write('something else\n')); |
| 62 | |
| 63 | stream.end(); |
| 64 | |
| 65 | stream.on('finish', common.mustCall(() => { |
| 66 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 67 | assert.strictEqual(data, 'hello world\nsomething else\n'); |
| 68 | assert.strictEqual(statSync(dest).mode & 0o700, defaultMode); |
| 69 | })); |
| 70 | })); |
| 71 | })); |
| 72 | } |
| 73 | |
| 74 | { |
| 75 | const dest = join(getTempFile(), 'out.log'); |
| 76 | const mode = 0o666; |
| 77 | const stream = new Utf8Stream({ dest, mkdir: true, mode, sync }); |
| 78 | |
| 79 | stream.on('ready', common.mustCall(() => { |
| 80 | assert.ok(stream.write('hello world\n')); |
| 81 | stream.flush(); |
| 82 | stream.on('drain', common.mustCall(() => { |
| 83 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 84 | assert.strictEqual(data, 'hello world\n'); |
| 85 | stream.end(); |
| 86 | })); |
| 87 | })); |
| 88 | })); |
| 89 | } |
no test coverage detected
searching dependent graphs…