Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
Merge a044681 into 292feee
Browse files Browse the repository at this point in the history
  • Loading branch information
SerayaEryn committed May 4, 2019
2 parents 292feee + a044681 commit ae8efcf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 37 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: node_js

node_js:
- "11"
- "12"
- "10"
- "9"
- "8"
- "6"

script:
- npm run coveralls
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "file stream being rotating daily",
"main": "lib/DailyRotatingFileStream.js",
"scripts": {
"unit": "tap test/test.js",
"unit": "ava test/test.js",
"test": "npm run lint && npm run unit",
"lint": "standard lib/* test/*.js benchmark/*",
"coveralls": "npm run unit -- --cov",
"coverage": "npm run coveralls && tap --coverage-report=lcov"
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc npm test && nyc report --reporter=html"
},
"repository": {
"type": "git",
Expand All @@ -21,9 +21,10 @@
},
"homepage": "https://github.com/SerayaEryn/daily-rotating-file-stream#readme",
"devDependencies": {
"ava": "^1.4.1",
"coveralls": "^3.0.2",
"standard": "^12.0.1",
"tap": "^12.1.1"
"nyc": "^14.1.0",
"standard": "^12.0.1"
},
"dependencies": {
"fast-date-format": "^2.0.0",
Expand All @@ -35,5 +36,8 @@
"rotate",
"file",
"stream"
]
],
"engines": {
"node": ">=8.0.0"
}
}
71 changes: 43 additions & 28 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

const DailyRotatingFileStream = require('..')
const test = require('tap').test
const test = require('ava')
const { join } = require('path')
const DateFormat = require('fast-date-format')
const fs = require('fs')

const dateFormat = new DateFormat('DDMMYYYY')

test('Should end stream', (t) => {
test.cb('Should end stream', (t) => {
t.plan(1)
const options = {
fileName: join(__dirname, '/testfiles0/console%DATE%.log')
Expand All @@ -18,12 +18,13 @@ test('Should end stream', (t) => {
stream.on('finish', () => {
t.pass()
cleanUp(getFileName(0))
t.end()
})
stream.end()
})

test('Should write to file', (t) => {
t.plan(2)
test.cb('Should write to file', (t) => {
t.plan(4)
const options = {
fileName: join(__dirname, '/testfiles1/console%DATE%.log')
}
Expand All @@ -32,17 +33,20 @@ test('Should write to file', (t) => {

stream.write('hello world')
stream.on('finish', () => {
t.pass()
fs.readFile(fileName, (err, buffer) => {
t.error(err)
t.strictEquals(buffer.toString(), 'hello world')
t.falsy(err)
t.truthy(buffer)
t.is(buffer.toString(), 'hello world')
cleanUp(fileName)
t.end()
})
})
stream.end()
})

test('Should write to file with bufferSize', (t) => {
t.plan(2)
test.cb('Should write to file with bufferSize', (t) => {
t.plan(3)
const options = {
fileName: join(__dirname, '/testfiles2/console%DATE%.log'),
bufferSize: 32
Expand All @@ -53,16 +57,18 @@ test('Should write to file with bufferSize', (t) => {
stream.write('hello world')
stream.on('finish', () => {
fs.readFile(fileName, (err, buffer) => {
t.error(err)
t.strictEquals(buffer.toString(), 'hello world')
t.falsy(err)
t.truthy(buffer)
t.is(buffer.toString(), 'hello world')
cleanUp(fileName)
t.end()
})
})
stream.end()
})

test('Should write to file with rotating', (t) => {
t.plan(3)
test.cb('Should write to file with rotating', (t) => {
t.plan(4)
const options = {
fileName: join(__dirname, '/testfiles3/console%DATE%.log')
}
Expand All @@ -78,17 +84,19 @@ test('Should write to file with rotating', (t) => {

stream.on('finish', () => {
fs.readFile(fileName, (err, buffer) => {
t.error(err)
t.strictEquals(buffer.toString(), 'hello world')
t.falsy(err)
t.truthy(buffer)
t.is(buffer.toString(), 'hello world')
cleanUp(fileName)
t.end()
})
})
stream.end()
})
})

test('Should write to file once ready', (t) => {
t.plan(2)
test.cb('Should write to file once ready', (t) => {
t.plan(3)
const options = {
fileName: join(__dirname, '/testfiles4/console%DATE%.log')
}
Expand All @@ -98,15 +106,17 @@ test('Should write to file once ready', (t) => {
stream.write('hello world')
stream.on('finish', () => {
fs.readFile(fileName, (err, buffer) => {
t.error(err)
t.strictEquals(buffer.toString(), 'hello world')
t.falsy(err)
t.truthy(buffer)
t.is(buffer.toString(), 'hello world')
cleanUp(fileName)
t.end()
})
})
stream.end()
})

test('Should end ready stream', (t) => {
test.cb('Should end ready stream', (t) => {
t.plan(2)
const options = {
fileName: join(__dirname, '/testfiles5/console%DATE%.log')
Expand All @@ -118,39 +128,44 @@ test('Should end ready stream', (t) => {
stream.on('finish', () => {
t.pass('finish emitted')
cleanUp(getFileName(5))
t.end()
})
stream.end()
})
})

test('Should destroy stream', (t) => {
test.cb('Should destroy stream', (t) => {
t.plan(1)
const options = {
fileName: join(__dirname, '/testfiles5/console%DATE%.log')
fileName: join(__dirname, '/testfiles6/console%DATE%.log')
}

const stream = new DailyRotatingFileStream(options)
stream.destroy()
stream.on('close', () => {
t.ok(stream.destroyed)
t.truthy(stream.destroyed)
cleanUp(getFileName(6))
t.end()
})
})

test('Should flush', (t) => {
t.plan(2)
test.cb('Should flush', (t) => {
t.plan(3)
const options = {
fileName: join(__dirname, '/testfiles5/console%DATE%.log')
fileName: join(__dirname, '/testfiles7/console%DATE%.log')
}
const fileName = getFileName(5)
const fileName = getFileName(7)
const stream = new DailyRotatingFileStream(options)

stream.write('hello world')
stream.flush()
stream.on('finish', () => {
fs.readFile(fileName, (err, buffer) => {
t.error(err)
t.strictEquals(buffer.toString(), 'hello world')
t.falsy(err)
t.truthy(buffer)
t.is(buffer.toString(), 'hello world')
cleanUp(fileName)
t.end()
})
})
stream.end()
Expand Down

0 comments on commit ae8efcf

Please sign in to comment.