Skip to content

Commit

Permalink
test: add driver.close assertions (#479)
Browse files Browse the repository at this point in the history
* test: add driver.close assertions

* test: play nice with the rest of tests
  • Loading branch information
Kikobeats committed Jul 3, 2023
1 parent 5c0063a commit 867f17b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/browserless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"superlock": "~1.0.1"
},
"devDependencies": {
"ps-list": "7",
"@browserless/test": "^9.11.0",
"ava": "latest"
},
Expand All @@ -62,4 +63,4 @@
"timeout": "30s",
"workerThreads": false
}
}
}
43 changes: 43 additions & 0 deletions packages/browserless/test/driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const { createBrowser } = require('@browserless/test/util')
const psList = require('ps-list')
const isCI = require('is-ci')
const test = require('ava')

const getChromiumPs = async () => {
const ps = await psList()
return ps.filter(ps => ps.name.includes('Chromium'))
}

;(isCI ? test.skip : test.serial)('.close() will kill process and subprocess', async t => {
const initialPs = await getChromiumPs()

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 browserless = await browserlessFactory.createContext()
t.is((await getChromiumPs()).length, 3)

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

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

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

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

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

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

0 comments on commit 867f17b

Please sign in to comment.