| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | const assert = require('chai').assert
|
|---|
| 4 | const spooks = require('spooks')
|
|---|
| 5 |
|
|---|
| 6 | const modulePath = '../../src/datastream'
|
|---|
| 7 |
|
|---|
| 8 | suite('datastream:', () => {
|
|---|
| 9 | let log
|
|---|
| 10 |
|
|---|
| 11 | setup(() => {
|
|---|
| 12 | log = {}
|
|---|
| 13 | })
|
|---|
| 14 |
|
|---|
| 15 | test('require does not throw', () => {
|
|---|
| 16 | assert.doesNotThrow(() => {
|
|---|
| 17 | require(modulePath)
|
|---|
| 18 | })
|
|---|
| 19 | })
|
|---|
| 20 |
|
|---|
| 21 | test('require returns function', () => {
|
|---|
| 22 | assert.isFunction(require(modulePath))
|
|---|
| 23 | })
|
|---|
| 24 |
|
|---|
| 25 | suite('require:', () => {
|
|---|
| 26 | let Stream
|
|---|
| 27 |
|
|---|
| 28 | setup(() => {
|
|---|
| 29 | Stream = require(modulePath)
|
|---|
| 30 | })
|
|---|
| 31 |
|
|---|
| 32 | test('Stream expects two arguments', () => {
|
|---|
| 33 | assert.lengthOf(Stream, 2)
|
|---|
| 34 | })
|
|---|
| 35 |
|
|---|
| 36 | test('calling Stream with function argument doesNotThrow', () => {
|
|---|
| 37 | assert.doesNotThrow(() => {
|
|---|
| 38 | Stream(() => {})
|
|---|
| 39 | })
|
|---|
| 40 | })
|
|---|
| 41 |
|
|---|
| 42 | test('calling Stream with object argument throws', () => {
|
|---|
| 43 | assert.throws(() => {
|
|---|
| 44 | Stream({ read: () => {} })
|
|---|
| 45 | })
|
|---|
| 46 | })
|
|---|
| 47 |
|
|---|
| 48 | test('calling Stream with new returns Stream instance', () => {
|
|---|
| 49 | assert.instanceOf(new Stream(() => {}), Stream)
|
|---|
| 50 | })
|
|---|
| 51 |
|
|---|
| 52 | test('calling Stream with new returns Readable instance', () => {
|
|---|
| 53 | assert.instanceOf(new Stream(() => {}), require('stream').Readable)
|
|---|
| 54 | })
|
|---|
| 55 |
|
|---|
| 56 | test('calling Stream without new returns Stream instance', () => {
|
|---|
| 57 | assert.instanceOf(Stream(() => {}), Stream)
|
|---|
| 58 | })
|
|---|
| 59 |
|
|---|
| 60 | suite('instantiate:', () => {
|
|---|
| 61 | let datastream
|
|---|
| 62 |
|
|---|
| 63 | setup(() => {
|
|---|
| 64 | datastream = new Stream(spooks.fn({ name: 'read', log: log }))
|
|---|
| 65 | })
|
|---|
| 66 |
|
|---|
| 67 | test('datastream has _read method', () => {
|
|---|
| 68 | assert.isFunction(datastream._read)
|
|---|
| 69 | })
|
|---|
| 70 |
|
|---|
| 71 | test('_read expects no arguments', () => {
|
|---|
| 72 | assert.lengthOf(datastream._read, 0)
|
|---|
| 73 | })
|
|---|
| 74 |
|
|---|
| 75 | test('read was not called', () => {
|
|---|
| 76 | assert.strictEqual(log.counts.read, 0)
|
|---|
| 77 | })
|
|---|
| 78 |
|
|---|
| 79 | suite('datastream._read:', () => {
|
|---|
| 80 | setup(() => {
|
|---|
| 81 | datastream._read()
|
|---|
| 82 | })
|
|---|
| 83 |
|
|---|
| 84 | test('read was called once', () => {
|
|---|
| 85 | assert.strictEqual(log.counts.read, 1)
|
|---|
| 86 | assert.isUndefined(log.these.read[0])
|
|---|
| 87 | })
|
|---|
| 88 |
|
|---|
| 89 | test('read was called correctly', () => {
|
|---|
| 90 | assert.lengthOf(log.args.read[0], 0)
|
|---|
| 91 | })
|
|---|
| 92 | })
|
|---|
| 93 | })
|
|---|
| 94 | })
|
|---|
| 95 | })
|
|---|