Skip to content

Commit

Permalink
fix(goto): wait pre promises (#540)
Browse files Browse the repository at this point in the history
* fix: wait pre promises

this is a regression introduced at 3412549#diff-47b28dd5d66a87f05a38f36f08033b3c3c5aee0daa99badbebffa4c84d30e63eL376

* test(lighthouse): update snapshot

* test(goto): update snapshots

* test(screenshot): update snapshot

* test: run on series

* test(screenshot): enable device assertion

* test(driver): fix assertions
  • Loading branch information
Kikobeats committed Dec 6, 2023
1 parent d7d1ed1 commit 87e448f
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 72 deletions.
1 change: 1 addition & 0 deletions packages/browserless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"license": "MIT",
"ava": {
"serial": true,
"timeout": "2m",
"workerThreads": false
}
Expand Down
28 changes: 17 additions & 11 deletions packages/browserless/test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,42 @@ 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.serial)('.close() will kill process and subprocess', async t => {
;(isCI ? test.skip : test)('.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 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.serial)('.close() is idempotency', async t => {
;(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)
})
Binary file modified packages/browserless/test/snapshots/example.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/browserless/test/snapshots/example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/browserless/test/snapshots/iphone.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"license": "MIT",
"ava": {
"serial": true,
"timeout": "2m",
"workerThreads": false
}
Expand Down
26 changes: 13 additions & 13 deletions packages/function/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const opts = {

const fileUrl = `file://${path.join(__dirname, './fixtures/example.html')}`

test.serial('code runs in strict mode', async t => {
test('code runs in strict mode', async t => {
const code = () => {
function isStrict () {
return !this
Expand All @@ -48,7 +48,7 @@ test.serial('code runs in strict mode', async t => {
})
})

test.serial("don't expose process.env", async t => {
test("don't expose process.env", async t => {
const code = () => JSON.stringify(process.env)

const myFn = browserlessFunction(code, opts)
Expand All @@ -60,7 +60,7 @@ test.serial("don't expose process.env", async t => {
})
})

test.serial('handle errors', async t => {
test('handle errors', async t => {
const code = () => {
throw new Error('oh no')
}
Expand All @@ -72,7 +72,7 @@ test.serial('handle errors', async t => {
t.is(result.reason.message, 'oh no')
})

test.serial('provide a mechanism to pass things to the function ', async t => {
test('provide a mechanism to pass things to the function ', async t => {
const code = ({ query }) => query.foo
const myFn = browserlessFunction(code, opts)

Expand All @@ -83,7 +83,7 @@ test.serial('provide a mechanism to pass things to the function ', async t => {
})
})

test.serial('access to response', async t => {
test('access to response', async t => {
const code = ({ response }) => response.status()
const myFn = browserlessFunction(code, opts)

Expand All @@ -94,7 +94,7 @@ test.serial('access to response', async t => {
})
})

test.serial('access to page', async t => {
test('access to page', async t => {
const code = ({ page }) => page.title()
const myFn = browserlessFunction(code, opts)

Expand All @@ -105,7 +105,7 @@ test.serial('access to page', async t => {
})
})

test.serial('access to page (with inline code)', async t => {
test('access to page (with inline code)', async t => {
const myFn = browserlessFunction('({ page }) => page.title()', opts)

t.deepEqual(await myFn(fileUrl), {
Expand All @@ -115,7 +115,7 @@ test.serial('access to page (with inline code)', async t => {
})
})

test.serial('access to page (with semicolon)', async t => {
test('access to page (with semicolon)', async t => {
const myFn = browserlessFunction('({ page }) => page.title();', opts)

t.deepEqual(await myFn(fileUrl), {
Expand All @@ -125,7 +125,7 @@ test.serial('access to page (with semicolon)', async t => {
})
})

test.serial('access to page (with semicolon and break lines)', async t => {
test('access to page (with semicolon and break lines)', async t => {
const myFn = browserlessFunction(
`({ page }) => {
return page.title()
Expand All @@ -140,7 +140,7 @@ test.serial('access to page (with semicolon and break lines)', async t => {
})
})

test.serial('access to page (with semicolon and end break lines)', async t => {
test('access to page (with semicolon and end break lines)', async t => {
const myFn = browserlessFunction('({ page }) => page.title();\n\n', opts)

t.deepEqual(await myFn(fileUrl), {
Expand All @@ -150,7 +150,7 @@ test.serial('access to page (with semicolon and end break lines)', async t => {
})
})

test.serial('interact with a page', async t => {
test('interact with a page', async t => {
const code = async ({ page }) => {
const navigationPromise = page.waitForNavigation()
const link = 'body > div > p > a'
Expand All @@ -167,7 +167,7 @@ test.serial('interact with a page', async t => {
t.true(value.startsWith('Example Domains'))
})

test.serial('pass goto options', async t => {
test('pass goto options', async t => {
const code = ({ page }) => page.evaluate('jQuery.fn.jquery')

const fn = browserlessFunction(code, opts)
Expand All @@ -182,7 +182,7 @@ test.serial('pass goto options', async t => {
t.is(value, '3.5.0')
})

test.serial('interact with npm modules', async t => {
test('interact with npm modules', async t => {
const code = async ({ page }) =>
require('lodash').toString(await page.evaluate('jQuery.fn.jquery'))

Expand Down
14 changes: 7 additions & 7 deletions packages/function/test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const test = require('ava')

const createVm = require('../src/vm')

test.serial('passing a function', async t => {
test('passing a function', async t => {
const vm = createVm()
function template ({ name }) {
return `greetings ${name}`
Expand All @@ -23,7 +23,7 @@ test.serial('passing a function', async t => {
})
})

test.serial('catch errors', async t => {
test('catch errors', async t => {
const vm = createVm()

async function template () {
Expand All @@ -38,7 +38,7 @@ test.serial('catch errors', async t => {
t.is(result.reason.message, 'oh no')
})

test.serial('passing an arrow function', async t => {
test('passing an arrow function', async t => {
const vm = createVm()
const template = ({ name }) => `greetings ${name}`
const fn = vm(template)
Expand All @@ -50,7 +50,7 @@ test.serial('passing an arrow function', async t => {
})
})

test.serial('passing a function.toString', async t => {
test('passing a function.toString', async t => {
const vm = createVm()
const template = ({ name }) => `greetings ${name}`
const fn = vm(template.toString())
Expand All @@ -62,7 +62,7 @@ test.serial('passing a function.toString', async t => {
})
})

test.serial('passing a string as function', async t => {
test('passing a string as function', async t => {
const vm = createVm()
// eslint-disable-next-line
const fn = vm('({ name }) => `greetings ${name}`')
Expand All @@ -74,7 +74,7 @@ test.serial('passing a string as function', async t => {
})
})

test.serial('passing an async function', async t => {
test('passing an async function', async t => {
const vm = createVm()

async function template ({ name }) {
Expand All @@ -97,7 +97,7 @@ test.serial('passing an async function', async t => {
})
})

test.serial('run browserless code', async t => {
test('run browserless code', async t => {
const browserWSEndpoint = await getBrowserWSEndpoint()

const url = 'https://example.com'
Expand Down
1 change: 1 addition & 0 deletions packages/goto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
},
"license": "MIT",
"ava": {
"serial": true,
"files": [
"!test/fixtures"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/goto/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
)
}

await Promise.all(prePromises)

const { value: response, reason: error } = await run({
fn: html
? page.setContent(html, { waitUntil, ...args })
Expand Down
8 changes: 4 additions & 4 deletions packages/goto/test/e2e/evasions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getBrowserContext } = require('@browserless/test/util')
const pWaitFor = require('p-wait-for')
const test = require('ava')

test.serial('arh.antoinevastel.com/bots/areyouheadless', async t => {
test('arh.antoinevastel.com/bots/areyouheadless', async t => {
let assertion = false

const fn = async () => {
Expand All @@ -18,7 +18,7 @@ test.serial('arh.antoinevastel.com/bots/areyouheadless', async t => {
t.true(assertion)
})

test.serial('creepjs', async t => {
test('creepjs', async t => {
const browserless = await getBrowserContext(t)

const fingerprint = await browserless.evaluate(page =>
Expand All @@ -41,7 +41,7 @@ test.serial('creepjs', async t => {
t.true(fingerprintOne !== fingerprintTwo)
})

test.serial('fingerprintjs', async t => {
test('fingerprintjs', async t => {
const browserless = await getBrowserContext(t)

const fingerprint = await browserless.evaluate(page =>
Expand All @@ -56,7 +56,7 @@ test.serial('fingerprintjs', async t => {
t.true(fingerprintOne !== fingerprintTwo)
})

test.serial('amiunique.org/fp', async t => {
test('amiunique.org/fp', async t => {
const browserless = await getBrowserContext(t)
const content = await browserless.text('https://amiunique.org/fingerprint', {
waitForSelector:
Expand Down
8 changes: 4 additions & 4 deletions packages/goto/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { getBrowserContext } = require('@browserless/test/util')
const test = require('ava')

test.serial('setup `scripts`', async t => {
test('setup `scripts`', async t => {
const browserless = await getBrowserContext(t)

const getVersion = browserless.evaluate(async page => page.evaluate('jQuery.fn.jquery'))
Expand All @@ -15,7 +15,7 @@ test.serial('setup `scripts`', async t => {
t.is(version, '3.5.0')
})

test.serial('setup `modules`', async t => {
test('setup `modules`', async t => {
const browserless = await getBrowserContext(t)

const getVersion = browserless.evaluate(async page => page.evaluate('jQuery.fn.jquery'))
Expand All @@ -27,7 +27,7 @@ test.serial('setup `modules`', async t => {
t.is(version, '3.5.0')
})

test.serial('setup `styles`', async t => {
test('setup `styles`', async t => {
const browserless = await getBrowserContext(t)

const getStyle = browserless.evaluate(async page =>
Expand All @@ -41,7 +41,7 @@ test.serial('setup `styles`', async t => {
t.is(style, '"Helvetica Neue", Helvetica, Arial, sans-serif')
})

test.serial('handle page disconnections', async t => {
test('handle page disconnections', async t => {
t.plan(1)
const browserless = await getBrowserContext(t, { retry: 0 })
const onPageRequest = req => {
Expand Down

0 comments on commit 87e448f

Please sign in to comment.