From 7751d33a40040975aa35ebb7f38c011414466248 Mon Sep 17 00:00:00 2001 From: Ivan Tymoshenko Date: Thu, 14 Mar 2024 10:07:19 +0100 Subject: [PATCH] update --- package.json | 1 + test/open.test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/package.json b/package.json index 8640514..abf681a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "homepage": "https://github.com/platformatic/tail-file-stream#readme", "devDependencies": { "@types/node": "^20.11.26", + "@matteo.collina/tspl": "^0.1.1", "c8": "^9.1.0", "standard": "^17.1.0", "tsd": "^0.30.7" diff --git a/test/open.test.js b/test/open.test.js index 772da5f..8af240a 100644 --- a/test/open.test.js +++ b/test/open.test.js @@ -3,8 +3,29 @@ const assert = require('node:assert') const { test } = require('node:test') const { join } = require('node:path') +const { tspl } = require('@matteo.collina/tspl') const { createReadStream } = require('..') +test('should open a file', (t, done) => { + const { strictEqual, ok } = tspl(t, { plan: 2 }) + + const pathToFile = join(__dirname, 'files', 'test-file-1.txt') + const stream = createReadStream(pathToFile, { autoWatch: false }) + + stream.on('open', (fd) => { + strictEqual(typeof fd, 'number') + }) + + stream.on('ready', () => { + ok(true) + }) + + stream.on('data', () => { + stream.destroy() + done() + }) +}) + test('should fail to open a fail', (t, done) => { const pathToFile = join(__dirname, 'files', 'test-file-wrong.txt') const stream = createReadStream(pathToFile, { autoWatch: false })