Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed Oct 8, 2020
1 parent ef2711e commit e3b9510
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const index = require('../src/index')
jest.mock('fs')
jest.mock('child_process')
const { fork } = require('child_process')
const fs = require('fs')

beforeAll(() => {
process.exit = jest.fn()
Expand Down Expand Up @@ -39,8 +40,8 @@ test('run (with args, process.send available)', async () => {
args,
bin: 'aio-run-detached',
logs: {
stdout: `${args[0]}.out.log`,
stderr: `${args[0]}.err.log`
stdout: `logs/${args[0]}.out.log`,
stderr: `logs/${args[0]}.err.log`
},
pid
},
Expand All @@ -62,3 +63,19 @@ test('run (with args, process.send not available)', async () => {

expect(forkMockReturn.unref).toHaveBeenCalled()
})

test('run (with args, logs folder exists', async () => {
const pid = 789
const forkMockReturn = {
pid,
unref: jest.fn()
}
fork.mockReturnValueOnce(forkMockReturn)
fs.existsSync.mockReturnValueOnce(true)

const args = ['command', 'arg1']
process.send = undefined
await index.run(args)

expect(forkMockReturn.unref).toHaveBeenCalled()
})

0 comments on commit e3b9510

Please sign in to comment.