diff --git a/package.json b/package.json index ff6937c..95822d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "testcafe-browser-provider-electron", - "version": "0.0.12", + "version": "0.0.13", "description": "TestCafe browser provider plugin for testing applications built with Electron.", "repository": "https://github.com/DevExpress/testcafe-browser-provider-electron", "homepage": "https://github.com/DevExpress/testcafe-browser-provider-electron", @@ -51,12 +51,12 @@ "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-env": "^1.6.0", "del": "^2.0.0", - "electron": "^6.0.0", + "electron": "^7.1.2", "gulp": "^4.0.0", "gulp-babel": "^7.0.0", "gulp-eslint": "^3.0.1", "publish-please": "^5.4.3", - "testcafe": "1.4.0", + "testcafe": "*", "tmp": "0.0.28" }, "types": "./ts-defs/index.d.ts" diff --git a/src/index.js b/src/index.js index 321b386..9ff41d2 100644 --- a/src/index.js +++ b/src/index.js @@ -24,7 +24,7 @@ function startElectron (config, ports) { if (OS.mac && statSync(config.electronPath).isDirectory()) { cmd = 'open'; - args = ['-naW', `"${config.electronPath}"`, '--args'].concat(debugPortsArgs, extraArgs); + args = ['-nW', '-a', config.electronPath, '--args'].concat(debugPortsArgs, extraArgs); } else { cmd = config.electronPath; diff --git a/src/injectable/electron-mocks.js b/src/injectable/electron-mocks.js index 04af3c9..87f3735 100644 --- a/src/injectable/electron-mocks.js +++ b/src/injectable/electron-mocks.js @@ -61,11 +61,11 @@ module.exports = function install (config, testPageUrl) { var WebContents; if ( process.atomBinding ) { - // < electron 6 + // NOTE: < Electron 6 WebContents = process.atomBinding('web_contents').WebContents; } else { - // electron 6+ + // NOTE: >= Electron 6 WebContents = process.electronBinding('web_contents').WebContents; } diff --git a/src/injectable/index.js b/src/injectable/index.js index 4ca5804..f8b48fe 100644 --- a/src/injectable/index.js +++ b/src/injectable/index.js @@ -1,10 +1,25 @@ +import { sep } from 'path'; + + +const ELECTRON_BROWSER_INIT_PATHS = [ + 'electron/js2c/browser_init', // NOTE: >= Electron v7.0.0 + ['electron.asar', 'browser', 'init.js'].join(sep) // NOTE: <= Electron v6.1.5 +]; + +function isBrowserInitModule (path) { + return ELECTRON_BROWSER_INIT_PATHS.some(initPath => path.endsWith(initPath)); +} + module.exports = function (config, testPageUrl) { var Module = require('module'); var origModuleLoad = Module._load; Module._load = function (...args) { - if (args[2]) { + const isMain = args[2]; + const isNotBrowserInitMainModule = isMain && !isBrowserInitModule(args[0]); + + if (isNotBrowserInitMainModule) { if (config.appPath) { config.appEntryPoint = require.resolve(config.appPath); diff --git a/src/node-inspect.js b/src/node-inspect.js index aaf0a88..dd73082 100644 --- a/src/node-inspect.js +++ b/src/node-inspect.js @@ -31,7 +31,9 @@ export default class NodeInspect { } async _setupRemoteInterface () { - this.client.Debugger.enable(); + this.client.Debugger.enable().then(async () => { + return this.client.Debugger.setBreakpointByUrl({ lineNumber: 16, url: 'internal/main/run_main_module\.js' }); + }); var pausedEvent = promisifyEvent(this.client, 'Debugger.paused'); diff --git a/templates/hook.js.mustache b/templates/hook.js.mustache index 8a0f31b..63e27fe 100644 --- a/templates/hook.js.mustache +++ b/templates/hook.js.mustache @@ -1,4 +1,3 @@ (function () { - require({{{INJECTABLE_PATH}}})({{{CONFIG}}}, {{{TEST_PAGE_URL}}}) + require('module')._load({{{INJECTABLE_PATH}}})({{{CONFIG}}}, {{{TEST_PAGE_URL}}}) })(); -