Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

karma-electron

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-electron - npm Package Compare versions

Comparing version 6.1.1 to 6.2.0

2

CHANGELOG.md
# karma-electron changelog
6.2.0 - Added `browserWindowOptions` and `loadURLOptions` support for Electron@5. Fixes #38
6.1.1 - Updated support to Node.js >= 8 to fix Travis CI

@@ -3,0 +5,0 @@

66

lib/electron-launcher.js

@@ -17,3 +17,4 @@ // When we run into an uncaught exception, fail hard

program.option('--user-data-dir [dir]', 'Directory to store user data');
program.option('--show', 'Boolean to make the window visible', false);
program.option('--show', 'Boolean to make the window visible');
program.option('--stdin-options', 'Load additional options via `stdin`');
program.option('--default-user-agent', 'Boolean when spefified uses default user agent');

@@ -47,19 +48,52 @@ program.option('--url [url]', 'URL to load page at');

app.on('ready', function handleReady () {
// Create our browser window
var browserWindow = new BrowserWindow({
show: !!program.show
});
// If we have `stdin` options, then load them in
// https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_stdin
// DEV: We perform this after `app.on('ready')` as we want to handle all those actions synchrously
if (program.stdinOptions) {
var stdinContent = '';
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function handleReadable () {
// Use a loop to make sure we read all available data.
while (true) {
var stdinChunk = process.stdin.read();
if (stdinChunk === null) {
break;
}
stdinContent += stdinChunk;
}
});
process.stdin.on('end', function handleEnd () {
var stdinOptions = JSON.parse(stdinContent);
Object.assign(program, stdinOptions);
launchBrowserWindow();
});
// Otherwise, launch our browser window
} else {
// DEV: We run `launchBrowserWindow` asynchronously to match async behavior in both cases
process.nextTick(launchBrowserWindow);
}
var loadUrlParams = {};
if (program.defaultUserAgent !== true) {
// Set a custom User-Agent for better logging
// https://github.com/atom/electron/blob/v0.36.9/docs/api/browser-window.md#winloadurlurl-options
// https://github.com/atom/electron/blob/v0.36.9/docs/api/web-contents.md#webcontentsloadurlurl-options
// DEV: Default would be "Chrome 47.0.2526 (Linux 0.0.0)"
// https://github.com/karma-runner/karma/blob/v0.13.21/lib/browser.js#L25
// https://github.com/karma-runner/karma/blob/v0.13.21/lib/helper.js#L7-L11
// Example: Electron 0.36.9 (Node.js 5.1.1)
loadUrlParams.userAgent = 'Electron ' + process.versions.electron + ' (Node ' + process.versions.node + ')';
function launchBrowserWindow() { /* jshint ignore:line */
// Create our browser window
var browserWindowOptions = Object.assign({
show: false
}, program.browserWindowOptions);
if (program.show !== undefined) {
browserWindowOptions.show = !!program.show;
}
var browserWindow = new BrowserWindow(browserWindowOptions);
var loadURLOptions = Object.assign({}, program.loadURLOptions);
if (program.defaultUserAgent !== true) {
// Set a custom User-Agent for better logging
// https://github.com/atom/electron/blob/v0.36.9/docs/api/browser-window.md#winloadurlurl-options
// https://github.com/atom/electron/blob/v0.36.9/docs/api/web-contents.md#webcontentsloadurlurl-options
// DEV: Default would be "Chrome 47.0.2526 (Linux 0.0.0)"
// https://github.com/karma-runner/karma/blob/v0.13.21/lib/browser.js#L25
// https://github.com/karma-runner/karma/blob/v0.13.21/lib/helper.js#L7-L11
// Example: Electron 0.36.9 (Node.js 5.1.1)
loadURLOptions.userAgent = 'Electron ' + process.versions.electron + ' (Node ' + process.versions.node + ')';
}
browserWindow.loadURL(program.url, loadURLOptions);
}
browserWindow.loadURL(program.url, loadUrlParams);
});

@@ -29,11 +29,28 @@ // Load in our dependencies

// Show depreciation warning for `--show`
if (flags.indexOf('--show') !== -1) {
console.log('karma-electron: `--show` is now deprecated. Please use `browserWindowOptions.show` instead');
}
// Set up app to use a custom user data directory to prevent crossover in tests
this._getOptions = function (url) {
this._stdinOptions = {};
var retArr = [__dirname + '/electron-launcher.js'].concat(flags, [
'--user-data-dir', userDataDir,
'--url', url
'--url', url,
'--stdin-options'
]);
if (args.require) { retArr = retArr.concat(['--require', args.require]); }
if (args.browserWindowOptions) { this._stdinOptions.browserWindowOptions = args.browserWindowOptions; }
if (args.loadURLOptions) { this._stdinOptions.loadURLOptions = args.loadURLOptions; }
return retArr;
};
// Wrap `_execCommand` to pass through `stdin-options`
var originalExecCommand = this._execCommand;
this._execCommand = function (/*cmd, args*/) {
var retArr = originalExecCommand.apply(this, arguments);
this._process.stdin.end(JSON.stringify(this._stdinOptions));
return retArr;
};
}

@@ -40,0 +57,0 @@ ElectronBrowser.prototype = {

{
"name": "karma-electron",
"description": "Karma launcher and preprocessor for Electron",
"version": "6.1.1",
"version": "6.2.0",
"homepage": "https://github.com/twolfson/karma-electron",

@@ -28,3 +28,3 @@ "author": {

"test": "npm run test-karma-all && npm run lint",
"test-karma-all": "npm run test-karma-single-run && npm run test-karma-failure && npm run test-karma-uncaught-exception && npm run test-karma-karma && npm run test-karma-phantomjs && npm run test-karma-eof-comment && npm run test-karma-source-map && npm run test-karma-node-require && npm run test-karma-custom-context-file && npm run test-karma-filename-override && npm run test-karma-main-require",
"test-karma-all": "npm run test-karma-single-run && npm run test-karma-failure && npm run test-karma-uncaught-exception && npm run test-karma-karma && npm run test-karma-phantomjs && npm run test-karma-eof-comment && npm run test-karma-source-map && npm run test-karma-node-require && npm run test-karma-custom-context-file && npm run test-karma-filename-override && npm run test-karma-main-require && npm run test-karma-no-node-integration",
"test-karma-continuous": "karma start test/integration-test/karma.conf.js --no-single-run",

@@ -39,2 +39,3 @@ "test-karma-custom-context-file-comment": "# DEV: We need to manually test custom debug file support since it's designed for debugging, not testing",

"test-karma-main-require": "cross-env TEST_TYPE=MAIN_REQUIRE karma start test/integration-test/karma.conf.js --single-run --browsers ElectronMainRequire",
"test-karma-no-node-integration": "cross-env TEST_TYPE=NO_NODE_INTEGRATION karma start test/integration-test/karma.conf.js --single-run --browsers Electron",
"test-karma-node-require": "cross-env TEST_TYPE=NODE_REQUIRE karma start test/integration-test/karma.conf.js --single-run",

@@ -58,3 +59,3 @@ "test-karma-phantomjs": "cross-env TEST_TYPE=PHANTOMJS karma start test/integration-test/karma.conf.js --single-run --browsers PhantomJS",

"cross-env": "~1.0.7",
"electron": "~1.8.4",
"electron": "~5.0.3",
"foundry": "~4.0.3",

@@ -61,0 +62,0 @@ "foundry-release-git": "~2.0.2",

@@ -119,6 +119,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)

- https://github.com/atom/electron/blob/v0.36.9/docs/api/chrome-command-line-switches.md
- We added support for a `--show` to allow making the Karma window visible
- userDataDir `String` - Directory to store cookies/localStorage information
- By default, this is a random directory generated by Karma (e.g. `/tmp/karma-5355024`)
- require `String` - Path to a main Electron process file to require before calling `app.on('ready')`
- browserWindowOptions `Object` - Parameters to pass to `new BrowserWindow`
- This will be serialized to JSON so any functions or other live data will be lost
- loadURLOptions `Object` - Parameters to pass to `BrowserWindow.loadURL`
- This will be serialized to JSON so any functions or other live data will be lost

@@ -138,3 +141,5 @@ **Example:**

userDataDir: __dirname + '/.electron',
flags: ['--show'],
browswerWindowOptions: {
show: true
},
require: __dirname + '/main-fixtures.js'

@@ -147,2 +152,51 @@ }

## 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',
browswerWindowOptions: {
webPreferences: {
preload: __dirname + '/path/to/preload.js'
}
}
}
}
});
};
```
### Forcing `nodeIntegration` support
If we're upgrading to Electron@5 or later, then we might run into missing `nodeIntegration` support. While it's advised to use `preload`, here's a workaround until the transition to `preload` is complete
```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',
browswerWindowOptions: {
webPreferences: {
nodeIntegration: true
}
}
}
}
});
};
```
## Contributing

@@ -149,0 +203,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`.

@@ -5,11 +5,12 @@ // Karma configuration

// Disable security warnings
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = '1';
module.exports = function (config) {
// Set up default files to test against
var karmaTest = 'karma-test.js';
var successTest = 'success-test.js';
var phantomJsTest = 'phantomjs-test.js';
var customContextFileTest = 'custom-context-file-test.js';
var eofCommentTest = 'eof-comment-test.js';
var failureTest = 'failure-test.js';
var sourceMapTest = 'source-map-test.js';
var uncaughtExceptionTest = 'uncaught-exception-test.js';
var filenameOverrideTest = 'filename-override-test.js';
var karmaTest = 'karma-test.js';
var mainRequireTest = 'main-require-test.js';

@@ -19,14 +20,24 @@ var nodeCommonTest = 'node-common-test.js';

var nodeScriptSrcTest = 'node-script-src-test.js';
var customContextFileTest = 'custom-context-file-test.js';
var filenameOverrideTest = 'filename-override-test.js';
var phantomJsTest = 'phantomjs-test.js';
var sourceMapTest = 'source-map-test.js';
var successTest = 'success-test.js';
var uncaughtExceptionTest = 'uncaught-exception-test.js';
var testFiles = ['*-test.js'];
var excludeFiles = new Set([
customContextFileTest, failureTest, filenameOverrideTest, karmaTest,
nodeRequireTest, phantomJsTest, sourceMapTest, uncaughtExceptionTest,
mainRequireTest]);
customContextFileTest,
failureTest,
filenameOverrideTest,
karmaTest,
mainRequireTest,
nodeRequireTest,
phantomJsTest,
sourceMapTest,
uncaughtExceptionTest
]);
// If we are testing uncaught exceptions, then update our tests
if (process.env.TEST_TYPE === 'UNCAUGHT_EXCEPTION') {
testFiles = [uncaughtExceptionTest];
excludeFiles.delete(uncaughtExceptionTest);
if (process.env.TEST_TYPE === 'CUSTOM_CONTEXT_FILE') {
testFiles = [customContextFileTest];
excludeFiles.delete(customContextFileTest);
} else if (process.env.TEST_TYPE === 'EOF_COMMENT') {

@@ -38,20 +49,14 @@ testFiles = [eofCommentTest];

excludeFiles.delete(failureTest);
} else if (process.env.TEST_TYPE === 'FILENAME_OVERRIDE') {
testFiles = [filenameOverrideTest];
excludeFiles.delete(filenameOverrideTest);
} else if (process.env.TEST_TYPE === 'KARMA') {
testFiles = [karmaTest];
excludeFiles.delete(karmaTest);
} else if (process.env.TEST_TYPE === 'PHANTOMJS') {
testFiles = [successTest, phantomJsTest];
excludeFiles = new Set();
} else if (process.env.TEST_TYPE === 'SOURCE_MAP') {
testFiles = [sourceMapTest];
excludeFiles.delete(sourceMapTest);
} else if (process.env.TEST_TYPE === 'CUSTOM_CONTEXT_FILE') {
testFiles = [customContextFileTest];
excludeFiles.delete(customContextFileTest);
} else if (process.env.TEST_TYPE === 'FILENAME_OVERRIDE') {
testFiles = [filenameOverrideTest];
excludeFiles.delete(filenameOverrideTest);
} else if (process.env.TEST_TYPE === 'MAIN_REQUIRE') {
testFiles = [mainRequireTest];
excludeFiles.delete(mainRequireTest);
} else if (process.env.TEST_TYPE === 'NO_NODE_INTEGRATION') {
testFiles = [successTest, phantomJsTest];
excludeFiles = new Set();
} else if (process.env.TEST_TYPE === 'NODE_REQUIRE') {

@@ -61,2 +66,12 @@ testFiles = [nodeCommonTest, nodeRequireTest];

excludeFiles.delete(nodeRequireTest);
} else if (process.env.TEST_TYPE === 'PHANTOMJS') {
testFiles = [successTest, phantomJsTest];
excludeFiles = new Set();
} else if (process.env.TEST_TYPE === 'SOURCE_MAP') {
testFiles = [sourceMapTest];
excludeFiles.delete(sourceMapTest);
} else if (process.env.TEST_TYPE === 'UNCAUGHT_EXCEPTION') {
testFiles = [uncaughtExceptionTest];
excludeFiles.delete(uncaughtExceptionTest);
// DEV: Note that we do have scenarios where there is no `TEST_TYPE` specified at all
} else if (process.env.TEST_TYPE) {

@@ -77,4 +92,17 @@ throw new Error('Unrecognized test type "' + process.env.TEST_TYPE + '"');

customLaunchers: {
ElectronWithNodeIntegration: {
base: 'Electron',
browserWindowOptions: {
webPreferences: {
nodeIntegration: true
}
}
},
ElectronMainRequire: {
base: 'Electron',
browserWindowOptions: {
webPreferences: {
nodeIntegration: true
}
},
require: __dirname + '/test-files/main-require.js'

@@ -84,2 +112,7 @@ },

base: 'Electron',
browserWindowOptions: {
webPreferences: {
nodeIntegration: true
}
},
flags: ['--show']

@@ -134,3 +167,3 @@ }

// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Electron'],
browsers: ['ElectronWithNodeIntegration'],

@@ -137,0 +170,0 @@ // Continuous Integration mode

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc