strong-tie/inbound-calls
0
1'use strict'2 3const fs = require('fs')4const SonicBoom = require('../')5const { file, runTests } = require('./helper')6 7runTests(buildTests)8 9function buildTests (test, sync) {10 // Reset the umask for testing11 process.umask(0o000)12 13 test('destroy', (t) => {14 t.plan(5)15 16 const dest = file()17 const fd = fs.openSync(dest, 'w')18 const stream = new SonicBoom({ fd, sync })19 20 t.ok(stream.write('hello world\n'))21 stream.destroy()22 t.throws(() => { stream.write('hello world\n') })23 24 fs.readFile(dest, 'utf8', function (err, data) {25 t.error(err)26 t.equal(data, 'hello world\n')27 })28 29 stream.on('finish', () => {30 t.fail('finish emitted')31 })32 33 stream.on('close', () => {34 t.pass('close emitted')35 })36 })37 38 test('destroy while opening', (t) => {39 t.plan(1)40 41 const dest = file()42 const stream = new SonicBoom({ dest })43 44 stream.destroy()45 stream.on('close', () => {46 t.pass('close emitted')47 })48 })49}50 