Skip to content

Commit

Permalink
fix onBeforeRun callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjduffy committed Jul 25, 2023
1 parent df561f0 commit 53101ef
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,21 @@ function warn(...lines: string[]) {
console.warn("\n%s\n", "".padEnd(terminalWidth, "="));
}

function getAuthKey(config: Cypress.PluginConfigOptions): string | undefined {
function getAuthKey<T extends { env?: { [key: string]: any } }>(config: T): string | undefined {
return (
// migrating away from `RECORD_REPLAY_` to `REPLAY_`
config.env.REPLAY_API_KEY ||
config.env.RECORD_REPLAY_API_KEY ||
config.env?.REPLAY_API_KEY ||
config.env?.RECORD_REPLAY_API_KEY ||
process.env.REPLAY_API_KEY ||
process.env.RECORD_REPLAY_API_KEY
);
}

function onBeforeRun(config: Cypress.PluginConfigOptions) {
async () => {
const authKey = getAuthKey(config);
if (authKey) {
await cypressReporter.authenticate(authKey);
}
};
async function onBeforeRun(details: Cypress.BeforeRunDetails) {
const authKey = getAuthKey(details.config);
if (authKey) {
await cypressReporter.authenticate(authKey);
}
}

function onBeforeBrowserLaunch(
Expand Down Expand Up @@ -135,7 +133,7 @@ function onReplayTask(value: any) {
const plugin: Cypress.PluginConfig = (on, config) => {
cypressReporter = new CypressReporter(config, debug);

on("before:run", () => onBeforeRun(config));
on("before:run", onBeforeRun);
on("before:browser:launch", (browser, launchOptions) =>
onBeforeBrowserLaunch(config, browser, launchOptions)
);
Expand Down

0 comments on commit 53101ef

Please sign in to comment.