• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4
5const { Writable } = require('stream');
6
7{
8  const w = new Writable({
9    write() {}
10  });
11  assert.strictEqual(w.writable, true);
12  w.destroy();
13  assert.strictEqual(w.writable, false);
14}
15
16{
17  const w = new Writable({
18    write: common.mustCall((chunk, encoding, callback) => {
19      callback(new Error());
20    })
21  });
22  assert.strictEqual(w.writable, true);
23  w.write('asd');
24  assert.strictEqual(w.writable, false);
25  w.on('error', common.mustCall());
26}
27
28{
29  const w = new Writable({
30    write: common.mustCall((chunk, encoding, callback) => {
31      process.nextTick(() => {
32        callback(new Error());
33        assert.strictEqual(w.writable, false);
34      });
35    })
36  });
37  w.write('asd');
38  w.on('error', common.mustCall());
39}
40
41{
42  const w = new Writable({
43    write: common.mustNotCall()
44  });
45  assert.strictEqual(w.writable, true);
46  w.end();
47  assert.strictEqual(w.writable, false);
48}
49