forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add browser destination tests with saucelabs (segmentio#994)
- Loading branch information
Showing
27 changed files
with
2,853 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driver-logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Browser Destinations Integration Tests | ||
|
||
These are for tests that target the final, webpacked output of browser-destinations, and can ideally be run in multiple browsers via a device farm like Sauce Labs. | ||
|
||
These tests are meant to run in real browsers and issues that might be missed in the package unit tests, which run in a node environment. | ||
|
||
Browser targets: | ||
|
||
- latest verison of chrome | ||
- latest version of safari | ||
- latest version of firefox | ||
- iOS 13 (older version of safari) | ||
|
||
## Running tests | ||
|
||
1. Build dependencies and start local server | ||
|
||
```sh | ||
yarn browser-destinations:build && | ||
yarn start-destination-server | ||
``` | ||
|
||
2. Run tests locally | ||
|
||
```sh | ||
yarn run test:local | ||
``` | ||
|
||
3. Run tests on Sauce Labs | ||
|
||
```sh | ||
SAUCE_USERNAME=??? SAUCE_ACCESS_KEY=??? yarn run test:sauce | ||
``` |
27 changes: 27 additions & 0 deletions
27
packages/browser-destinations-integration-tests/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@segment/browser-destinations-integration-tests", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/segmentio/action-destinations", | ||
"directory": "packages/browser-destinations-integration-tests" | ||
}, | ||
"private": true, | ||
"scripts": { | ||
"test:sauce": "wdio wdio.conf.sauce.ts", | ||
"test:local": "wdio wdio.conf.local.ts", | ||
"start-destination-server": "yarn ts-node src/server/start-destination-server.ts", | ||
"browser-destinations:build": "NODE_ENV=production yarn lerna run build --scope=@segment/browser-destinations --include-dependencies --stream" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@wdio/cli": "^7.26.0", | ||
"@wdio/local-runner": "^7.26.0", | ||
"@wdio/mocha-framework": "^7.26.0", | ||
"@wdio/sauce-service": "^7.26.0", | ||
"@wdio/spec-reporter": "^7.26.0", | ||
"@wdio/types": "7", | ||
"expect": "^29.4.1" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/browser-destinations-integration-tests/src/pageobjects/page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Page { | ||
async loadDestination(destination: string): Promise<void> { | ||
await browser.url(`${browser.options.baseUrl}?destination=${destination}`) | ||
|
||
await browser.waitUntil(() => browser.execute(() => document.readyState === 'complete'), { | ||
timeout: 10000 | ||
}) | ||
} | ||
} | ||
|
||
export default new Page() |
5 changes: 5 additions & 0 deletions
5
packages/browser-destinations-integration-tests/src/server/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const config = { | ||
get destinationTestServerPort(): number { | ||
return 5555 | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/browser-destinations-integration-tests/src/server/destination-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { startServer } from './server' | ||
import { listDestinations, DESTINATIONS_DIST_WEB } from './utils' | ||
import express from 'express' | ||
import path from 'path' | ||
|
||
const htmlWithScript = (src: string): string => ` | ||
<html> | ||
<head> | ||
<script src="${src}" type="text/javascript"></script> | ||
</head> | ||
<body> | ||
Script found: "${src}" | ||
</body> | ||
</html> | ||
` | ||
|
||
export const startDestinationServer = (...args: Parameters<typeof startServer>): ReturnType<typeof startServer> => { | ||
const destinations = listDestinations() | ||
return startServer(...args).then(([app, server]) => { | ||
app.use('/js', express.static(path.join(DESTINATIONS_DIST_WEB))) | ||
app.get('/', (req, res) => { | ||
console.log('req!', req.url) | ||
const { destination } = req.query | ||
if (!destination) { | ||
return res.status(400).send('No destination param passed.') | ||
} | ||
const foundDestination = destinations.find((d) => d.dirPath === destination) | ||
if (!foundDestination) { | ||
return res.status(404).send('Cannot find destination.') | ||
} | ||
res.send(htmlWithScript(path.join('js', foundDestination.dirPath, foundDestination.fileName))) | ||
}) | ||
app.get('/destinations', (_, res) => { | ||
const dirNames = destinations.map((d) => d.dirPath) | ||
res.json(dirNames) | ||
}) | ||
|
||
return [app, server] | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/browser-destinations-integration-tests/src/server/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import express from 'express' | ||
import { Server } from 'http' | ||
|
||
const onExit = (server: Server) => { | ||
return (): void => { | ||
console.log('closing server...') | ||
server.close(() => { | ||
console.log('closed gracefully!') | ||
process.exit() | ||
}) | ||
setTimeout(() => { | ||
console.log('Force closing!') | ||
process.exit(1) | ||
}, 400) | ||
} | ||
} | ||
export const startServer = (port: string | number): Promise<[express.Application, Server]> => { | ||
if (!port) { | ||
throw new Error('please pass a PORT') | ||
} | ||
return new Promise((resolve) => { | ||
const app = express() | ||
const server = app.listen(port, () => { | ||
console.log(`Listening on http://localhost:${port} in ${app.get('env')}`) | ||
resolve([app, server]) | ||
}) | ||
process.on('SIGINT', onExit(server)) | ||
process.on('SIGTERM', onExit(server)) | ||
}) | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/browser-destinations-integration-tests/src/server/start-destination-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { config } from './config' | ||
import { startDestinationServer } from './destination-server' | ||
|
||
void startDestinationServer(config.destinationTestServerPort).catch(console.error) |
21 changes: 21 additions & 0 deletions
21
packages/browser-destinations-integration-tests/src/server/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { readdirSync } from 'fs' | ||
import path from 'path' | ||
|
||
const ls = (dirPath: string) => | ||
readdirSync(dirPath, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map((dirent) => dirent.name) | ||
|
||
export const DESTINATIONS_DIST_WEB = path.join(__dirname, '../../../browser-destinations', 'dist', 'web') | ||
|
||
export const listDestinations = () => | ||
ls(DESTINATIONS_DIST_WEB).map((dirPath) => { | ||
const destinationDirPath = path.join(DESTINATIONS_DIST_WEB, dirPath) | ||
const fileName = readdirSync(destinationDirPath).find((el) => el.endsWith('js')) | ||
if (!fileName) throw new Error('Invariant: no .js file found.') | ||
return { | ||
dirPath: dirPath, | ||
fileName, | ||
filePath: path.join(destinationDirPath, fileName) | ||
} | ||
}) |
25 changes: 25 additions & 0 deletions
25
packages/browser-destinations-integration-tests/src/tests/browser-destinations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import page from '../pageobjects/page' | ||
import { expect } from 'expect' | ||
import { listDestinations } from '../server/utils' | ||
|
||
const allDestinations = listDestinations().map((el) => el.dirPath) | ||
|
||
describe('Bundles are capable of being parsed and loaded without errors', () => { | ||
for (const destination of allDestinations) { | ||
it(destination, async () => { | ||
await page.loadDestination(destination) | ||
|
||
// written as a string so not transpiled -- using old JS to allow testing in old browsers. | ||
// the "return" is important for this to work on saucelabs. | ||
const code = `return (function() { | ||
for (var key in window) { | ||
if (key.indexOf('Destination') !== -1 && key.indexOf('webpack') === -1) { | ||
return typeof window[key] | ||
} | ||
} | ||
})()` | ||
const destinationGlobalType = await browser.execute(code) | ||
expect(destinationGlobalType).toBe('function') | ||
}) | ||
} | ||
}) |
16 changes: 16 additions & 0 deletions
16
packages/browser-destinations-integration-tests/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"moduleResolution": "node", | ||
"module": "CommonJS", | ||
"target": "es6", | ||
"esModuleInterop": true, | ||
"types": ["node", "webdriverio/async", "@wdio/mocha-framework", "expect-webdriverio", "@wdio/sauce-service"] | ||
}, | ||
"ts-node": { | ||
"transpileOnly": true, | ||
"files": true, | ||
"compilerOptions": { | ||
"module": "commonjs" // get rid of "Cannot use import statement outside a module" for local scripts | ||
} | ||
} | ||
} |
Oops, something went wrong.