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 3.2.1 to 4.0.0

test/integration-test/test-files/submodule.js

2

CHANGELOG.md
# karma-electron changelog
4.0.0 - Added submodules support by using local `require` and documenting `useIframe` usage (now supported by `karma@1.1.0` for Electron)
3.2.1 - Added configuration info to submodules documentation

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

41

lib/node-integration-iframe.mustache.js
(function () {
// Based off of https://github.com/atom/electron/blob/v0.36.9/atom/common/lib/init.js#L34-L47
// Bind parent window's node integration to this closure
// DEV: Due to using an `iframe`, we lose the node integration inheritance =/
// DEV: We use a closure since `__filename`/`__dirname` and relative requires change based on file
// DEV: We skip error handlers so Karma can catch them
var __parentWindow = window.parent || {};
var module = __parentWindow.module ? __parentWindow.module : undefined;
// DEV: Ignore JSHint errors about unused variables
// jshint ignore:start
var process = __parentWindow.process ? __parentWindow.process : undefined;
var setImmediate = __parentWindow.setImmediate ? __parentWindow.setImmediate : undefined;
var clearImmediate = __parentWindow.clearImmediate ? __parentWindow.clearImmediate : undefined;
var global = __parentWindow.module ? window : undefined;
// jshint ignore:end
var __filename = __parentWindow.module ? '{{!filename}}' : undefined;
var __dirname = __parentWindow.module ? '{{!dirname}}' : undefined;
// Set up local filename and dirname
// DEV: `__filename` would be a path to Electron since we are loading an HTTP URL
// Once we perform a `require`, it will be using our `require's` context :+1:
// DEV: Ignore JSHint so we can override `__filename` in our closure
// DEV: We use `window.require` sniffing to prevent emulating a Node.js environment in a non-Node.js one
var __filename = window.require ? '{{!filename}}' : undefined; // jshint ignore:line
var __dirname = window.require ? '{{!dirname}}' : undefined;
// Set up local requires
var require;
if (__filename) {
// Save original require/require.resolve
var __require = __parentWindow.require;
// Save original require/require.resolve
if (window.require) {
var __require = window.require;
var __requireResolve = __require.resolve;

@@ -44,14 +33,12 @@

// Define our require/resolve.resolve
require = function (filepath) {
window.require = function (filepath) {
return __require(__requireFilepath(filepath));
};
require.resolve = function (filepath) {
window.require.resolve = function (filepath) {
return __requireResolve(__requireFilepath(filepath));
};
// jscs:disable
// DEV: Due to the Mustache content, we have to add a `jscs:disable` early
}
// Unset our `__parentWindow` to prevent leaks
// jscs:disable
__parentWindow = undefined;
// Inject our content

@@ -58,0 +45,0 @@ // jshint ignore:start

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

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

"jshint": "~2.5.10",
"karma": "~0.13.21",
"karma": "~1.1.0",
"karma-mocha": "~0.2.2",

@@ -58,0 +58,0 @@ "karma-phantomjs-launcher": "~1.0.0",

@@ -14,3 +14,2 @@ # 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)

- Support for Node.js integration in the renderer process (e.g. `process`, `require`, `__filename`)
- *Currently submodules (e.g. `require('./abc')`) don't receive the same `window` object. See [docs/submodules.md](docs/submodules.md) for workarounds.*
- Support for hidden browser windows

@@ -34,5 +33,11 @@ - Support for isolated test runs to prevent cookie/localStorage pollution

// If you would like Node integration support (e.g. `require`)
// then, you must include this in `preprocessors`
// then, you must include this in `preprocessors` and `client`
// DEV: preprocessors is for backfilling `__filename` and local `require` paths
preprocessors: {
'**/*.js': ['electron']
},
// 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
}

@@ -39,0 +44,0 @@ ```

@@ -54,2 +54,7 @@ // Karma configuration

browserNoActivityTimeout: 2000,
client: {
useIframe: false
},
// preprocess matching files before serving them to the browser

@@ -56,0 +61,0 @@ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor

@@ -7,3 +7,3 @@ // Load in our dependencies

// DEV: By using a `./` require here, we have verified that we support relative requires
var submodule = require('./submodule');
var submodule = require('./test-files/submodule');

@@ -48,8 +48,8 @@ // Start our tests

it('identify as a standalone module', function () {
assert(/test[\/\\]integration-test[\/\\]submodule\.js$/.test(submodule.filename),
'Expected "' + submodule.filename + '" to end with "test/integration-test/submodule.js"');
assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.filename),
'Expected "' + submodule.filename + '" to end with "test/integration-test/test-files/submodule.js"');
// Verify `hello` property of `module.exports`
assert.strictEqual(submodule.exports.hello, 'world');
assert(/test[\/\\]integration-test[\/\\]submodule\.js$/.test(submodule.id),
'Expected "' + submodule.id + '" to end with "test/integration-test/submodule.js"');
assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.id),
'Expected "' + submodule.id + '" to end with "test/integration-test/test-files/submodule.js"');
assert.strictEqual(submodule.loaded, true);

@@ -61,8 +61,12 @@ assert.strictEqual(submodule.parent, module);

// Example: /home/todd/github/karma-electron/test/integration-test/node-test.js
assert(/test[\/\\]integration-test[\/\\]submodule\.js$/.test(submodule.filename),
'Expected "' + submodule.filename + '" to end with "test/integration-test/submodule.js"');
assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.filename),
'Expected "' + submodule.filename + '" to end with "test/integration-test/test-files/submodule.js"');
// Example: /home/todd/github/karma-electron/test/integration-test
assert(/test[\/\\]integration-test$/.test(submodule.dirname),
'Expected "' + submodule.dirname + '" to end with "test/integration-test"');
assert(/test[\/\\]integration-test[\/\\]test-files$/.test(submodule.dirname),
'Expected "' + submodule.dirname + '" to end with "test/integration-test/test-files"');
});
it('has same window context as parent', function () {
assert.strictEqual(submodule.before, window.before);
});
});

@@ -69,0 +73,0 @@ });

@@ -18,4 +18,3 @@ // Define a helper for our asserts

assertUndefinedStr(typeof clearImmediate);
assertUndefinedStr(typeof global);
});
});

Sorry, the diff of this file is not supported yet

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