Skip to content

Restore just-in-time require/require splitting in cypress.js #21236

@flotwig

Description

@flotwig

See #21174 for context.

We should remove these lines:

// We require project-base here, as waiting to require it in
// the Electron process for the first time can cause the process
// to hang during smoke test execution. This occurs with Electron
// version v15.4.0 and after.
//
// TODO: Investigate need/removal of this with future major versions
// of Electron when upgraded: https://github.com/cypress-io/cypress/pull/19090
require('@packages/server/lib/project-base')

Because cypress.js should not be slowed down by unused code:

// we are not requiring everything up front
// to optimize how quickly electron boots while
// in dev or linux production. the reasoning is
// that we likely may need to spawn a new child process
// and its a huge waste of time (about 1.5secs) of
// synchronous requires the first go around just to
// essentially do it all again when we boot the correct
// mode.

Or, remove the need for cypress.js to ever run in node.

Once cypress.js's JIT requires are restored, we can clean up these areas:

  • No longer will need to JIT require here, since we will no longer be requiring makeDataContext outside of electron:
    },
    showItemInFolder (folder: string) {
    require('electron').shell.showItemInFolder(folder)
    },
    showOpenDialog (props: OpenDialogOptions) {
    return require('electron').dialog.showOpenDialog(props)
    },
    showSaveDialog (window: BrowserWindow, props: SaveDialogOptions) {
    return require('electron').dialog.showSaveDialog(window, props)
    },
    copyTextToClipboard (text: string) {
    require('electron').clipboard.writeText(text)
    },
    isMainWindowFocused () {
    return Windows.isMainWindowFocused()
    },
    focusMainWindow () {
    return Windows.focusMainWindow()
    },
  • Any other areas where we currently have to JIT require to avoid triggering errors related to electron not being available.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions