Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI : Move from sleep to watch exists #748

Merged
merged 4 commits into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
'use strict'
const os = require('os')
const { join } = require('path')
const { readFileSync } = require('fs')
const { readFileSync, existsSync, statSync } = require('fs')
const { test } = require('tap')
const { sink, check, once } = require('./helper')
const pino = require('../')
const { version } = require('../package.json')
const { pid } = process
const hostname = os.hostname()
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
const watchFileCreated = (filename) => new Promise((resolve, reject) => {
const TIMEOUT = 800
const INTERVAL = 100
const threshold = TIMEOUT / INTERVAL
let counter = 0
const interval = setInterval(() => {
// On some CI runs file is created but not filled
if (existsSync(filename) && statSync(filename).size !== 0) {
clearInterval(interval)
resolve()
} else if (counter <= threshold) {
counter++
} else {
clearInterval(interval)
reject(new Error(`${filename} was not created.`))
}
}, INTERVAL)
})

test('pino version is exposed on export', async ({ is }) => {
is(pino.version, version)
Expand Down Expand Up @@ -479,7 +496,7 @@ test('pino.destination', async ({ same }) => {
)
const instance = pino(pino.destination(tmp))
instance.info('hello')
await sleep(300)
await watchFileCreated(tmp)
const result = JSON.parse(readFileSync(tmp).toString())
delete result.time
same(result, {
Expand All @@ -498,7 +515,7 @@ test('auto pino.destination with a string', async ({ same }) => {
)
const instance = pino(tmp)
instance.info('hello')
await sleep(300)
await watchFileCreated(tmp)
const result = JSON.parse(readFileSync(tmp).toString())
delete result.time
same(result, {
Expand All @@ -517,7 +534,7 @@ test('auto pino.destination with a string as second argument', async ({ same })
)
const instance = pino(null, tmp)
instance.info('hello')
await sleep(300)
await watchFileCreated(tmp)
const result = JSON.parse(readFileSync(tmp).toString())
delete result.time
same(result, {
Expand All @@ -538,7 +555,7 @@ test('does not override opts with a string as second argument', async ({ same })
timestamp: () => ',"time":"none"'
}, tmp)
instance.info('hello')
await sleep(300)
await watchFileCreated(tmp)
const result = JSON.parse(readFileSync(tmp).toString())
same(result, {
pid: pid,
Expand Down