1 | 'use strict'
|
2 |
|
3 | const assert = require('assert')
|
4 | const Writable = require('stream').Writable
|
5 | const wrote = require('../../src/index')
|
6 | const WroteContext = require('../context/WroteContext')
|
7 |
|
8 | const wroteTestSuite = {
|
9 | context: WroteContext,
|
10 | 'should be a function': () => {
|
11 | assert(typeof wrote === 'function')
|
12 | },
|
13 | 'should return a promise': () => {
|
14 | const res = wrote()
|
15 | assert(res instanceof Promise)
|
16 | return res.catch(() => {})
|
17 | },
|
18 | 'should resolve with a write stream': () => {
|
19 | const res = wrote()
|
20 | .then((ws) => {
|
21 | assert(ws instanceof Writable)
|
22 | })
|
23 | return res
|
24 | },
|
25 | 'should open specified file': (ctx) => {
|
26 | const file = ctx.tempFile
|
27 | return wrote(file)
|
28 | .then((ws) => {
|
29 | assert.equal(ws.path, file)
|
30 | assert(ws instanceof Writable && ws.writable)
|
31 | })
|
32 | },
|
33 | 'should be able to stop stream': (ctx) => {
|
34 | const file = ctx.tempFile
|
35 | return wrote(file)
|
36 | .then((ws) => {
|
37 | const promise = new Promise((resolve, reject) => {
|
38 | ws.once('close', () => resolve(ws))
|
39 | ws.once('error', reject)
|
40 | ws.close()
|
41 | })
|
42 | return promise
|
43 | })
|
44 | },
|
45 | }
|
46 |
|
47 |
|
48 | module.exports = {
|
49 | wroteTestSuite,
|
50 | }
|