Skip to content

Commit

Permalink
test(driver): fix assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 6, 2023
1 parent 7151157 commit 940245d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/browserless/test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isCI = !!process.env.CI

const getChromiumPs = async () => {
const ps = await psList()
return ps.filter(ps => ps.name === 'Google Chrome for Testing')
return ps.filter(ps => ps.cmd.includes('Google Chrome for Testing')).length
}

;(isCI ? test.skip : test)('.close() will kill process and subprocess', async t => {
Expand All @@ -17,27 +17,33 @@ const getChromiumPs = async () => {
const browserlessFactory = createBrowser()
t.teardown(browserlessFactory.close)

t.is((await getChromiumPs()).length, 1)
t.is((await getChromiumPs())[0].pid, (await browserlessFactory.browser()).process().pid)
const browserPid = (await browserlessFactory.browser()).process().pid

t.truthy((await psList()).find(ps => ps.pid === browserPid))

const runningPs = await getChromiumPs()

const browserless = await browserlessFactory.createContext()
t.is((await getChromiumPs()).length, 1)

t.is(runningPs, await getChromiumPs())

await browserless.destroyContext()
t.is((await getChromiumPs()).length, 1)

t.is(runningPs, await getChromiumPs())

await browserlessFactory.close()
t.is((await getChromiumPs()).length, initialPs.length)

t.is(initialPs, await getChromiumPs())
})
;(isCI ? test.skip : test)('.close() is idempotency', async t => {
const initialPs = await getChromiumPs()

const browserlessFactory = createBrowser()
t.is((await getChromiumPs()).length, 1)
t.is(await getChromiumPs(), 1)

await browserlessFactory.close()
t.is((await getChromiumPs()).length, initialPs.length)
t.is(await getChromiumPs(), initialPs)

await browserlessFactory.close()
t.is((await getChromiumPs()).length, initialPs.length)
t.is(await getChromiumPs(), initialPs)
})

0 comments on commit 940245d

Please sign in to comment.