summaryrefslogtreecommitdiff
path: root/test/parallel/test-whatwg-webstreams-coverage.js
blob: 4d0ffe818f43f8e8a2c9925e67710d08ebc8e6f1 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Flags: --no-warnings --expose-internals
'use strict';

require('../common');

const {
  ByteLengthQueuingStrategy,
  CountQueuingStrategy,
} = require('stream/web');

const {
  inspect,
} = require('util');

const {
  isPromisePending,
} = require('internal/webstreams/util');

const assert = require('assert');

assert(!isPromisePending({}));
assert(!isPromisePending(Promise.resolve()));
assert(isPromisePending(new Promise(() => {})));

// Brand checking works
assert.throws(() => {
  Reflect.get(ByteLengthQueuingStrategy.prototype, 'highWaterMark', {});
}, {
  name: 'TypeError',
  message: /Cannot read private member/,
});

assert.throws(() => {
  Reflect.get(ByteLengthQueuingStrategy.prototype, 'size', {});
}, {
  name: 'TypeError',
  message: /Cannot read private member/,
});

assert.throws(() => {
  Reflect.get(CountQueuingStrategy.prototype, 'highWaterMark', {});
}, {
  name: 'TypeError',
  message: /Cannot read private member/,
});

assert.throws(() => {
  Reflect.get(CountQueuingStrategy.prototype, 'size', {});
}, {
  name: 'TypeError',
  message: /Cannot read private member/,
});

// Custom Inspect Works

{
  const strategy = new CountQueuingStrategy({ highWaterMark: 1 });

  assert.strictEqual(
    inspect(strategy, { depth: null }),
    'CountQueuingStrategy { highWaterMark: 1 }');

  assert.strictEqual(
    inspect(strategy),
    'CountQueuingStrategy { highWaterMark: 1 }');

  assert.strictEqual(
    inspect(strategy, { depth: 0 }),
    'CountQueuingStrategy [Object]');

  assert.strictEqual(
    inspect(new ByteLengthQueuingStrategy({ highWaterMark: 1 })),
    'ByteLengthQueuingStrategy { highWaterMark: 1 }');
}