tldraw/e2e/wdio.util.js
Orange Mug 545e421423
Adds CI for webdriver tests (#1343)
Github action CI workflows added for webdriver tests.

I've also refactored the `./scripts/e2e-*` scripts. These scripts were
somewhat unique compared to the other scripts. They are now more inline
with the other scripts in that directory and run via

```
% yarn e2e --help                               
Usage: yarn e2e <command> [options]

Commands:
  yarn e2e serve              start test server
  yarn e2e test:ci [env]      runner for CI (github-actions)
  yarn e2e test:local         run webdriver tests locally
  yarn e2e test:browserstack  run webdriver tests on browserstack
  yarn e2e selenium:grid      start selenium grid (test linux)

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
``` 

I've also added an experimental linux runner see 


2cca4ddb77/e2e/README.md (L320-L333)

### Change Type

- [x] `tests` — Changes to any testing-related code only (will not
publish a new version)


### Release Notes

- Github action CI workflows added for webdriver tests
- Refactored e2e test runner
2023-05-12 15:25:14 +00:00

65 lines
2 KiB
JavaScript

let BUILD_NAME = 'e2e'
if (process.env.GH_EVENT_NAME === 'pull_request') {
BUILD_NAME += `-pr-${process.env.GH_PR_NUMBER}`
} else if (process.env.WB_BUILD_NAME) {
BUILD_NAME += `-${process.env.WB_BUILD_NAME}`
}
async function logBrowserstackUrl() {
const sessionId = capabilities['webdriver.remote.sessionid']
const headers = new Headers()
headers.set(
'Authorization',
'Basic ' + btoa(process.env.BROWSERSTACK_USER + ':' + process.env.BROWSERSTACK_KEY)
)
const resp = await fetch(`https://api.browserstack.com/automate/sessions/${sessionId}.json`, {
method: 'GET',
headers: headers,
})
const respJson = await resp.json()
console.log(`==================================
browser_url: <${respJson.automation_session.browser_url}>
==================================`)
}
function filterCapabilities(capabilities) {
let browsers = (process.env.BROWSERS || 'chrome').split(',').map((b) => b.trim())
const validBrowsers = ['chrome', 'safari', 'firefox', 'edge', 'vscode']
const skippedBrowsers = []
if (browsers.includes('safari')) {
console.log(
'NOTE: In safari you need to run `safaridriver --enable`, see <https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari> for details.'
)
}
for (const browser of browsers) {
if (!validBrowsers.includes(browser)) {
throw new Error(`'${browser}' not a valid browser name`)
}
if (skippedBrowsers.includes(browser)) {
console.error(`'${browser}' not currently supported`)
}
}
// let oses = (process.env.OS || process.platform).split(',').map((b) => b.trim())
// const validOses = ['darwin', 'win32', 'linux']
// for (const os of oses) {
// if (!validOses.includes(os)) {
// throw new Error(`'${os}' not a valid OS name`)
// }
// }
const filterFn = (capability) => {
return browsers.includes(capability['tldraw:options'].browser)
// oses.includes(capability['tldraw:options'].os)
}
return capabilities.filter(filterFn)
}
module.exports = { BUILD_NAME, logBrowserstackUrl, filterCapabilities }