Unverified Commit 06607e3d authored by Jaril's avatar Jaril Committed by GitHub

Add Replay integration for dev e2e tests (#40955)

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

@ijjk moving this here.
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 79a85b73
...@@ -405,9 +405,27 @@ jobs: ...@@ -405,9 +405,27 @@ jobs:
timeout-minutes: 5 timeout-minutes: 5
if: ${{needs.build.outputs.docsChange == 'nope'}} if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: NEXT_TEST_MODE=dev node run-tests.js --type e2e --timings -g ${{ matrix.group }}/3 - run: npx @replayio/playwright install chromium
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js --type e2e --timings -g ${{ matrix.group }}/3
name: Run test/e2e (dev) name: Run test/e2e (dev)
if: ${{needs.build.outputs.docsChange == 'nope'}} if: ${{needs.build.outputs.docsChange == 'nope'}}
env:
RECORD_REPLAY_METADATA_TEST_RUN_TITLE: testDevE2E / Group ${{ matrix.group }} / Node ${{ matrix.node }}
RECORD_ALL_CONTENT: 1
RECORD_REPLAY: 1
NEXT_TEST_MODE: dev
RECORD_REPLAY_TEST_METRICS: 1
RECORD_REPLAY_WEBHOOK_URL: ${{ secrets.RECORD_REPLAY_WEBHOOK_URL }}
# DEBUG: pw:browser*
- uses: replayio/action-upload@v0.4.5
if: always()
with:
api-key: rwk_iKsQnEoQwKd31WAJxgN9ARPFuAlyXlVrDH4uhYpRnti
public: true
filter: ${{ 'function($v) { $v.metadata.test.result = "failed" }' }}
- name: Upload test trace - name: Upload test trace
if: always() if: always()
......
const nextJest = require('next/jest')
const createJestConfig = nextJest()
// Any custom config you want to pass to Jest
const customJestConfig = {
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.tsx'],
setupFilesAfterEnv: ['<rootDir>/jest-setup-after-env.ts'],
verbose: true,
rootDir: 'test',
modulePaths: ['<rootDir>/lib'],
transformIgnorePatterns: ['/next[/\\\\]dist/', '/\\.next/'],
testTimeout: 60000,
testRunner: '@replayio/jest/runner',
}
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
...@@ -69,6 +69,8 @@ ...@@ -69,6 +69,8 @@
"@next/polyfill-module": "workspace:*", "@next/polyfill-module": "workspace:*",
"@next/polyfill-nomodule": "workspace:*", "@next/polyfill-nomodule": "workspace:*",
"@next/swc": "workspace:*", "@next/swc": "workspace:*",
"@replayio/jest": "27.5.1-alpha.4",
"@replayio/playwright": "0.2.26",
"@svgr/webpack": "5.5.0", "@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55", "@swc/cli": "0.1.55",
"@swc/core": "1.2.203", "@swc/core": "1.2.203",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -238,13 +238,19 @@ async function main() { ...@@ -238,13 +238,19 @@ async function main() {
`jest${process.platform === 'win32' ? '.CMD' : ''}` `jest${process.platform === 'win32' ? '.CMD' : ''}`
) )
const runTest = (test = '', isFinalRun) => const runTest = (test = '', isFinalRun, isRetry) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const start = new Date().getTime() const start = new Date().getTime()
let outputChunks = [] let outputChunks = []
const shouldRecordTestWithReplay = process.env.RECORD_REPLAY && isRetry
const child = spawn( const child = spawn(
jestPath, jestPath,
[ [
...(shouldRecordTestWithReplay
? [`--config=jest.replay.config.js`]
: []),
'--runInBand', '--runInBand',
'--forceExit', '--forceExit',
'--verbose', '--verbose',
...@@ -257,6 +263,7 @@ async function main() { ...@@ -257,6 +263,7 @@ async function main() {
stdio: ['ignore', 'pipe', 'pipe'], stdio: ['ignore', 'pipe', 'pipe'],
env: { env: {
...process.env, ...process.env,
RECORD_REPLAY: shouldRecordTestWithReplay,
// run tests in headless mode by default // run tests in headless mode by default
HEADLESS: 'true', HEADLESS: 'true',
TRACE_PLAYWRIGHT: 'true', TRACE_PLAYWRIGHT: 'true',
...@@ -336,7 +343,7 @@ async function main() { ...@@ -336,7 +343,7 @@ async function main() {
for (let i = 0; i < numRetries + 1; i++) { for (let i = 0; i < numRetries + 1; i++) {
try { try {
console.log(`Starting ${test} retry ${i}/${numRetries}`) console.log(`Starting ${test} retry ${i}/${numRetries}`)
const time = await runTest(test, i === numRetries) const time = await runTest(test, i === numRetries, i > 0)
timings.push({ timings.push({
file: test, file: test,
time, time,
......
...@@ -62,14 +62,21 @@ export class Playwright extends BrowserInterface { ...@@ -62,14 +62,21 @@ export class Playwright extends BrowserInterface {
} }
} }
browser = await this.launchBrowser(browserName, { headless })
context = await browser.newContext({ locale, ...device })
}
async launchBrowser(browserName: string, launchOptions: Record<string, any>) {
if (browserName === 'safari') { if (browserName === 'safari') {
browser = await webkit.launch({ headless }) return await webkit.launch(launchOptions)
} else if (browserName === 'firefox') { } else if (browserName === 'firefox') {
browser = await firefox.launch({ headless }) return await firefox.launch(launchOptions)
} else { } else {
browser = await chromium.launch({ headless, devtools: !headless }) return await chromium.launch({
devtools: !launchOptions.headless,
...launchOptions,
})
} }
context = await browser.newContext({ locale, ...device })
} }
async get(url: string): Promise<void> { async get(url: string): Promise<void> {
......
import { getExecutablePath } from '@replayio/playwright'
import { Playwright } from './playwright'
export { quit } from './playwright'
export class Replay extends Playwright {
async launchBrowser(browserName: string, launchOptions: Record<string, any>) {
const browser: any = browserName === 'chrome' ? 'chromium' : browserName
return super.launchBrowser(browserName, {
...launchOptions,
executablePath: getExecutablePath(browser) || undefined,
env: {
...process.env,
},
})
}
}
...@@ -84,6 +84,10 @@ export default async function webdriver( ...@@ -84,6 +84,10 @@ export default async function webdriver(
const { Selenium, quit } = await import('./browsers/selenium') const { Selenium, quit } = await import('./browsers/selenium')
CurrentInterface = Selenium CurrentInterface = Selenium
browserQuit = quit browserQuit = quit
} else if (process.env.RECORD_REPLAY === 'true') {
const { Replay, quit } = await require('./browsers/replay')
CurrentInterface = Replay
browserQuit = quit
} else { } else {
const { Playwright, quit } = await import('./browsers/playwright') const { Playwright, quit } = await import('./browsers/playwright')
CurrentInterface = Playwright CurrentInterface = Playwright
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment