Skip to content

Commit

Permalink
test: use replay jest runner to add current test name to recording (#…
Browse files Browse the repository at this point in the history
…60438)

### What?

Adds the name of the test that's running when the browser is started to
the recording.

Also makes `RECORD_REPLAY=1` work without `run-tests.js`

Closes PACK-2206
  • Loading branch information
ForsakenHarmony authored Jan 10, 2024
1 parent c52cb5a commit 1e34f80
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const customJestConfig = {
},
}

if (process.env.RECORD_REPLAY) {
customJestConfig.testRunner = '@replayio/jest/runner'
}

// Check if the environment variable is set to enable test report,
// Insert a reporter to generate a junit report to upload.
//
Expand Down
9 changes: 8 additions & 1 deletion test/lib/browsers/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ export { quit } from './playwright'
export class Replay extends Playwright {
async launchBrowser(browserName: string, launchOptions: Record<string, any>) {
const browser: any = browserName === 'chrome' ? 'chromium' : browserName
const executablePath = getExecutablePath(browser)

if (!executablePath) {
throw new Error(`No replay.io executable for browser \`${browserName}\``)
}

return super.launchBrowser(browserName, {
...launchOptions,
executablePath: getExecutablePath(browser) || undefined,
executablePath,
env: {
...process.env,
RECORD_ALL_CONTENT: 1,
},
})
}
Expand Down
5 changes: 4 additions & 1 deletion test/lib/next-webdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export default async function webdriver(
const { Selenium, quit } = await import('./browsers/selenium')
CurrentInterface = Selenium
browserQuit = quit
} else if (process.env.RECORD_REPLAY === 'true') {
} else if (
process.env.RECORD_REPLAY === 'true' ||
process.env.RECORD_REPLAY === '1'
) {
const { Replay, quit } = await require('./browsers/replay')
CurrentInterface = Replay
browserQuit = quit
Expand Down

0 comments on commit 1e34f80

Please sign in to comment.