strong-tie/inbound-calls
0
1'use strict'2 3const { test } = require('tap')4const fs = require('fs')5const proxyquire = require('proxyquire')6const { file } = require('./helper')7 8test('fsync with sync', (t) => {9 t.plan(5)10 11 const fakeFs = Object.create(fs)12 fakeFs.fsyncSync = function (fd) {13 t.pass('fake fs.fsyncSync called')14 return fs.fsyncSync(fd)15 }16 const SonicBoom = proxyquire('../', {17 fs: fakeFs18 })19 20 const dest = file()21 const fd = fs.openSync(dest, 'w')22 const stream = new SonicBoom({ fd, sync: true, fsync: true })23 24 t.ok(stream.write('hello world\n'))25 t.ok(stream.write('something else\n'))26 27 stream.end()28 29 const data = fs.readFileSync(dest, 'utf8')30 t.equal(data, 'hello world\nsomething else\n')31})32 33test('fsync with async', (t) => {34 t.plan(7)35 36 const fakeFs = Object.create(fs)37 fakeFs.fsyncSync = function (fd) {38 t.pass('fake fs.fsyncSync called')39 return fs.fsyncSync(fd)40 }41 const SonicBoom = proxyquire('../', {42 fs: fakeFs43 })44 45 const dest = file()46 const fd = fs.openSync(dest, 'w')47 const stream = new SonicBoom({ fd, fsync: true })48 49 t.ok(stream.write('hello world\n'))50 t.ok(stream.write('something else\n'))51 52 stream.end()53 54 stream.on('finish', () => {55 fs.readFile(dest, 'utf8', (err, data) => {56 t.error(err)57 t.equal(data, 'hello world\nsomething else\n')58 })59 })60 stream.on('close', () => {61 t.pass('close emitted')62 })63})64 