karma-electron
Advanced tools
Comparing version 6.3.4 to 7.0.0
# karma-electron changelog | ||
7.0.0 - Added `BrowserWindow#webPreferences.nativeWindowOpen: true` as default for Electron@12 non-Node.js support (more #50) | ||
6.3.4 - Upgraded to Electron@12 in `devDependencies` and documented `contextIsolation` for #50 | ||
@@ -3,0 +5,0 @@ |
@@ -86,3 +86,7 @@ // When we run into an uncaught exception, fail hard | ||
show: false | ||
}, program.browserWindowOptions); | ||
}, program.browserWindowOptions, { | ||
webPreferences: Object.assign({ | ||
nativeWindowOpen: true | ||
}, (program.browserWindowOptions || {}).webPreferences) | ||
}); | ||
if (program.show !== undefined) { | ||
@@ -89,0 +93,0 @@ browserWindowOptions.show = !!program.show; |
{ | ||
"name": "karma-electron", | ||
"description": "Karma launcher and preprocessor for Electron", | ||
"version": "6.3.4", | ||
"version": "7.0.0", | ||
"homepage": "https://github.com/twolfson/karma-electron", | ||
@@ -6,0 +6,0 @@ "author": { |
117
README.md
@@ -29,2 +29,9 @@ # karma-electron [![Build status](https://travis-ci.org/twolfson/karma-electron.svg?branch=master)](https://travis-ci.org/twolfson/karma-electron) [![Build status](https://ci.appveyor.com/api/projects/status/urgpvcip7kl9q2ih/branch/master?svg=true)](https://ci.appveyor.com/project/twolfson/karma-electron-launcher/branch/master) | ||
## Breaking changes with Electron@12 | ||
`contextIsolation` has been set to `true` by default, which limits interaction with `require` and `postMessage` | ||
To resolve these issues, please see the latest [Getting Started](#getting-started) instructions | ||
For more information, see https://github.com/twolfson/karma-electron/issues/50 | ||
## Breaking changes in 5.0.0 | ||
@@ -48,4 +55,9 @@ We have corrected inaccuracies with `file://` behavior from Electron. For example: | ||
Then, configure the module: | ||
Then, configure the module with the following: | ||
### No Node.js integration | ||
**Note:** Due to `electron@12` `postMessage` limitations, we set `BrowserWindow#webPreferences.nativeWindowOpen` to `true` by default (see [#50][] for more info) | ||
[#50]: https://github.com/twolfson/karma-electron/issues/50 | ||
```js | ||
@@ -55,4 +67,47 @@ // Inside `karma.conf.js` | ||
// If you would like Node.js integration support (e.g. `require`) | ||
// then, you must include this in `preprocessors` and `client` | ||
// DEV: `useIframe: false` is for launching a new window instead of using an iframe | ||
// In Electron, iframes don't get `nodeIntegration` priveleges yet windows do | ||
client: { | ||
useIframe: false | ||
} | ||
``` | ||
Then, we can run Karma: | ||
```bash | ||
karma start | ||
``` | ||
### Node.js/custom integration | ||
By default, we try to use the minimal Electron configuration to avoid any assumptions about your repo | ||
As a result, we need to define a custom launcher to match your Electron configuration | ||
To add Node.js integration support (e.g. `require`), use the following: | ||
```js | ||
// Inside `karma.conf.js` | ||
// Define our custom launcher for Node.js support | ||
customLaunchers: { | ||
CustomElectron: { | ||
base: 'Electron', | ||
browserWindowOptions: { | ||
// DEV: More preferentially, should link your own `webPreferences` from your Electron app instead | ||
webPreferences: { | ||
// Preferred `preload` mechanism to expose `require` | ||
preload: __dirname + '/path/to/preload.js' | ||
// Alternative non-preload mechanism to expose `require` | ||
// nodeIntegration: true, | ||
// contextIsolation: false | ||
// nativeWindowOpen is set to `true` by default by `karma-electron` as well, see #50 | ||
} | ||
} | ||
} | ||
} | ||
// Use our custom launcher | ||
browsers: ['CustomElectron'] | ||
// DEV: preprocessors is for backfilling `__filename` and local `require` paths | ||
@@ -62,2 +117,3 @@ preprocessors: { | ||
}, | ||
// DEV: `useIframe: false` is for launching a new window instead of using an iframe | ||
@@ -101,2 +157,3 @@ // In Electron, iframes don't get `nodeIntegration` priveleges yet windows do | ||
```js | ||
// Inside `karma.conf.js` | ||
module.exports = function (config) { | ||
@@ -135,2 +192,3 @@ config.set({ | ||
```js | ||
// Inside `karma.conf.js` | ||
module.exports = function (config) { | ||
@@ -148,2 +206,3 @@ config.set({ | ||
show: true | ||
// nativeWindowOpen is set to `true` by default by `karma-electron` as well, see #50 | ||
}, | ||
@@ -157,54 +216,2 @@ require: __dirname + '/main-fixtures.js' | ||
## Examples | ||
### Using `preload` with `BrowserWindow` | ||
We can add our `preload` location via a custom launcher: | ||
```js | ||
module.exports = function (config) { | ||
config.set({ | ||
// Specify usage of our custom launcher | ||
browsers: ['CustomElectron'], | ||
// Define a custom launcher which inherits from `Electron` | ||
customLaunchers: { | ||
CustomElectron: { | ||
base: 'Electron', | ||
browserWindowOptions: { | ||
webPreferences: { | ||
preload: __dirname + '/path/to/preload.js' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
``` | ||
### Forcing `nodeIntegration` and `contextIsolation` support | ||
If we're upgrading to Electron@5 or later, then we might run into missing `nodeIntegration` and `contextIsolation` support (e.g. `require is not defined`). | ||
While it's advised to use `preload`, here's a workaround for now: | ||
```js | ||
module.exports = function (config) { | ||
config.set({ | ||
// Specify usage of our custom launcher | ||
browsers: ['CustomElectron'], | ||
// Define a custom launcher which inherits from `Electron` | ||
customLaunchers: { | ||
CustomElectron: { | ||
base: 'Electron', | ||
browserWindowOptions: { | ||
webPreferences: { | ||
nodeIntegration: true, | ||
contextIsolation: false | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
``` | ||
## Contributing | ||
@@ -211,0 +218,0 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via `npm run lint` and test via `npm test`. |
@@ -93,3 +93,3 @@ // Karma configuration | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
contextIsolation: false | ||
} | ||
@@ -103,3 +103,3 @@ } | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
contextIsolation: false | ||
} | ||
@@ -115,3 +115,3 @@ }, | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
contextIsolation: false | ||
} | ||
@@ -118,0 +118,0 @@ } |
68309
966
226