Skip to content

Commit

Permalink
Merge pull request #72 from chromaui/steven/electron-interactive-mode
Browse files Browse the repository at this point in the history
Cypress: Electron can be used in interactive mode
  • Loading branch information
skitterm authored Jan 20, 2024
2 parents 10f97cb + ff0c477 commit 20dc6df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
20 changes: 17 additions & 3 deletions packages/cypress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ export const onBeforeBrowserLaunch = (
// we don't use the browser parameter but we're keeping it here in case we'd ever need to read from it
// (this way users wouldn't have to change their cypress.config file as it's already passed to us)
browser: Cypress.Browser,
launchOptions: Cypress.BeforeBrowserLaunchOptions
launchOptions: Cypress.BeforeBrowserLaunchOptions,
config: Cypress.PluginConfigOptions
) => {
// when Cypress is in interactive mode, we won't be snapshotting.
// Thus we don't need them to pass the ELECTRON_EXTRA_LAUNCH_ARGS for this command,
// or set up CDP or anything like that
if (config.isInteractive) {
return launchOptions;
}

const hostArg = launchOptions.args.find((arg) => arg.startsWith('--remote-debugging-address='));
host = hostArg ? hostArg.split('=')[1] : '127.0.0.1';

Expand All @@ -166,10 +174,16 @@ export const onBeforeBrowserLaunch = (
return launchOptions;
};

export const installPlugin = (on: any) => {
export const installPlugin = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
// these events are run on the server (in Node)
on('task', {
prepareArchives,
});
on('before:browser:launch', onBeforeBrowserLaunch);

on(
'before:browser:launch',
(browser: Cypress.Browser, launchOptions: Cypress.BeforeBrowserLaunchOptions) => {
onBeforeBrowserLaunch(browser, launchOptions, config);
}
);
};
9 changes: 8 additions & 1 deletion packages/cypress/src/support.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { snapshot } from 'rrweb-snapshot';
import './commands';

const shouldTakeSnapshot = () => {
return !Cypress.env('disableAutoSnapshot') && !Cypress.config('isInteractive');
};

// these client-side lifecycle hooks will be added to the user's Cypress suite
beforeEach(() => {
if (!shouldTakeSnapshot()) {
return;
}
// this "manualSnapshots" variable will be available before, during, and after the test,
// then cleaned up before the next test is run
// (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases)
Expand All @@ -14,7 +21,7 @@ beforeEach(() => {
});

afterEach(() => {
if (Cypress.env('disableAutoSnapshot')) {
if (!shouldTakeSnapshot()) {
return;
}
// can we be sure this always fires after all the requests are back?
Expand Down
2 changes: 1 addition & 1 deletion packages/cypress/tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
setupNodeEvents(on, config) {
installPlugin(on);
installPlugin(on, config);
},
},
});

0 comments on commit 20dc6df

Please sign in to comment.