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.2.2 to 6.3.0

.github/FUNDING.yml

2

CHANGELOG.md
# karma-electron changelog
6.3.0 - Fixed Windows support via removing `process.stdin` usage and encoding URLs
6.2.2 - Fixed Travis CI settings

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

105

lib/electron-launcher.js

@@ -9,4 +9,6 @@ // When we run into an uncaught exception, fail hard

var assert = require('assert');
var fs = require('fs');
var path = require('path');
var app = require('electron').app;
var async = require('async');
var BrowserWindow = require('electron').BrowserWindow;

@@ -19,5 +21,7 @@ var program = require('commander');

program.option('--show', 'Boolean to make the window visible');
program.option('--stdin-options', 'Load additional options via `stdin`');
program.option('--extended-options [filepath]', 'Load extended options from file');
program.option('--default-user-agent', 'Boolean when spefified uses default user agent');
program.option('--url [url]', 'URL to load page at');
// DEV: We need to encode our URL to avoid issues with Electron on Windows
// https://ci.appveyor.com/project/twolfson/karma-electron-launcher/builds/25358540/job/k8q6ugas6ha0s7n5
program.option('--encoded-url [url]', 'URL to load page at');
program.option('--require [filepath]', 'Path to main process file to require');

@@ -29,3 +33,3 @@ program.allowUnknownOption();

assert(program.userDataDir, 'Expected `--user-data-dir` to be provided but it was not.');
assert(program.url, 'Expected `--url` to be provided but it was not.');
assert(program.encodedUrl, 'Expected `--encoded-url` to be provided but it was not.');

@@ -48,54 +52,57 @@ // When all windows are closed, exit out

// When Electron is done loading, launch our applicaiton
app.on('ready', function handleReady () {
// 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;
// In parallel
async.parallel([
function loadExtendedOptions (cb) {
// If we have extended options, then load them in
if (program.extendedOptions) {
fs.readFile(program.extendedOptions, 'utf8', function handleReadFile (err, extendedOptionsStr) {
// If we have an error, callback with it
if (err) { return cb(err); }
// Otherwise, load in our options
var extendedOptions;
try {
extendedOptions = JSON.parse(extendedOptionsStr);
} catch (err) {
console.error('Error loading extended options: ' + extendedOptionsStr);
return cb(err);
}
stdinContent += stdinChunk;
}
Object.assign(program, extendedOptions);
cb(null);
});
// Otherwise, callback in an async behavior (to match `if` case)
} else {
process.nextTick(cb);
}
},
function waitForAppReady (cb) {
app.on('ready', function handleReady (evt) {
cb(null);
});
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);
}
], function handleParallelLoad (err) {
// If we received an error, throw it
if (err) { throw err; }
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);
// 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);
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(decodeURIComponent(program.encodedUrl), loadURLOptions);
});
// Load in our dependencies
// DEV: We use `require`/`assert` instead of `peerDependencies` to make floating dependencies easier
var electronPrebuilt;
var fs = require('fs');
var path = require('path');
try {

@@ -29,2 +31,16 @@ electronPrebuilt = require('electron');

// Prepare to relocate extended options into temporary file
// DEV: Electron on Windows doesn't support `stdin` reading
// https://github.com/electron/electron/issues/4218
// DEV: We write options out now as `_getOptions` is re-run on every start (e.g. crash occurs)
var extendedOptions;
if (args.browserWindowOptions) {
extendedOptions = extendedOptions || {};
extendedOptions.browserWindowOptions = args.browserWindowOptions;
}
if (args.loadURLOptions) {
extendedOptions = extendedOptions || {};
extendedOptions.loadURLOptions = args.loadURLOptions;
}
// Show depreciation warning for `--show`

@@ -37,21 +53,17 @@ if (flags.indexOf('--show') !== -1) {

this._getOptions = function (url) {
this._stdinOptions = {};
var retArr = [__dirname + '/electron-launcher.js'].concat(flags, [
'--user-data-dir', userDataDir,
'--url', url,
'--stdin-options'
'--encoded-url', encodeURIComponent(url)
]);
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; }
if (extendedOptions) {
// Use temporary directory provided by karma
// https://github.com/karma-runner/karma/blob/v4.1.0/lib/launchers/process.js#L15
// DEV: File will automatically be removed by Karma which is nice
var extendedOptionsFilepath = path.join(this._tempDir, 'karma-electron-options.json');
fs.writeFileSync(extendedOptionsFilepath, JSON.stringify(extendedOptions));
retArr = retArr.concat(['--extended-options', extendedOptionsFilepath]);
}
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;
};
}

@@ -58,0 +70,0 @@ ElectronBrowser.prototype = {

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

@@ -47,2 +47,3 @@ "author": {

"dependencies": {
"async": "~3.0.1",
"combine-source-map": "~0.8.0",

@@ -49,0 +50,0 @@ "commander": "~2.9.0",

@@ -108,7 +108,7 @@ // Karma configuration

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

@@ -115,0 +115,0 @@ },

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