/
erioxis
/
web-nodejs
Обзор
Документация
Войти
/
erioxis
/
web-nodejs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/node_modules/sonic-boom/test/fsync.test.js
63 строки
1 KB
erioxis
lab11fix
15 дек 2025, 23:21
15 дек 2025, 23:21
70dc7ba
Код
Авторство
О чём код?
'use strict' const { test } = require('tap') const fs = require('fs') const proxyquire = require('proxyquire') const { file } = require('./helper') test('fsync with sync', (t) => { t.plan(5) const fakeFs = Object.create(fs) fakeFs.fsyncSync = function (fd) { t.pass('fake fs.fsyncSync called') return fs.fsyncSync(fd) } const SonicBoom = proxyquire('../', { fs: fakeFs }) const dest = file() const fd = fs.openSync(dest, 'w') const stream = new SonicBoom({ fd, sync: true, fsync: true }) t.ok(stream.write('hello world\n')) t.ok(stream.write('something else\n')) stream.end() const data = fs.readFileSync(dest, 'utf8') t.equal(data, 'hello world\nsomething else\n') }) test('fsync with async', (t) => { t.plan(7) const fakeFs = Object.create(fs) fakeFs.fsyncSync = function (fd) { t.pass('fake fs.fsyncSync called') return fs.fsyncSync(fd) } const SonicBoom = proxyquire('../', { fs: fakeFs }) const dest = file() const fd = fs.openSync(dest, 'w') const stream = new SonicBoom({ fd, fsync: true }) t.ok(stream.write('hello world\n')) t.ok(stream.write('something else\n')) stream.end() stream.on('finish', () => { fs.readFile(dest, 'utf8', (err, data) => { t.error(err) t.equal(data, 'hello world\nsomething else\n') }) }) stream.on('close', () => { t.pass('close emitted') }) })