Skip to content

Commit

Permalink
CI : Move from sleep to watch exists (#748)
Browse files Browse the repository at this point in the history
* Extend sleep for windows tests

* move from sleep to watch

* Review

* fix empty files behaviour
  • Loading branch information
zekth authored and mcollina committed Dec 2, 2019
1 parent 29ceca4 commit 6fe7476
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions test/basic.test.js
@@ -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

0 comments on commit 6fe7476

Please sign in to comment.