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

karma-parallel

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-parallel - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

12

lib/karma-parallelizer.js

@@ -5,8 +5,14 @@ 'use strict';

function initKarmaParallelizer(root, karma, shardIndexInfo) {
if (!shardIndexInfo || !shardIndexInfo.shouldShard) {
// console.log('Skipping sharding. Could not find index and count values');
function initKarmaParallelizer(root, karma, shardIndexInfoMap) {
var idParamExtractor = /(\?|&)id=(\d+)(&|$)/;
var matches = idParamExtractor.exec(parent.location.search);
var id = matches && matches[2] || null;
if (!id || !shardIndexInfoMap.hasOwnProperty(id) || !shardIndexInfoMap[id].shouldShard) {
/* eslint-disable-next-line no-console */
console.warn('Skipping sharding. Could not find karma-parallel initialization data.');
return;
}
var shardIndexInfo = shardIndexInfoMap[id];
var strategy = overrideSuiteStategy(getSpecSuiteStrategy(shardIndexInfo));

@@ -13,0 +19,0 @@ var fakeContextStatus = createFakeTestContext(root, strategy);

@@ -12,30 +12,23 @@ 'use strict';

const idParamExtractor = /\/\?id=(\d+)/;
const idCookieExtractor = /karmaParallelBrowser.id=(\d+)/;
function createKarmaSharderInfoMap(config) {
return JSON.stringify(Object
.keys(config.shardIndexMap)
.map((id) => [ id, {
shouldShard: !!id && config.shardIndexMap.hasOwnProperty(id),
shardIndex: config.shardIndexMap[id],
executors: config.executors,
shardStrategy: config.shardStrategy
} ])
.reduce((payloadMap, [ id, payload ]) => {
payloadMap[id.toString()] = payload;
function setBrowserIdCookie(log, request, response) {
if (request.url.indexOf('/?id=') === 0) {
const id = idParamExtractor.exec(request.url)[1];
const cookie = `karmaParallelBrowser.id=${id};`;
log.debug(`setting cookie "${cookie}"`);
response.setHeader('Set-Cookie', cookie);
}
return payloadMap;
}, { }));
}
function getBrowserIdCookie(request) {
const match = idCookieExtractor.exec(request.headers.cookie);
return match && match.length && match[1];
}
function writeKarmaSharderInfo(log, config, request, response) {
const id = getBrowserIdCookie(request);
const payload = JSON.stringify({
shouldShard: !!id && config.shardIndexMap.hasOwnProperty(id),
shardIndex: config.shardIndexMap[id],
executors: config.executors,
shardStrategy: config.shardStrategy
});
log.debug(`interpolating parallel shard data in script. Browser: ${id}. Data: ${payload}`);
function writeKarmaSharderInfoMap(log, config, response) {
const karmaSharderInfoMap = createKarmaSharderInfoMap(config);
log.debug(`interpolating parallel shard data map in script. Data: ${karmaSharderInfoMap}`);
response.writeHead(200, {'Content-Type': 'application/javascript'});
response.end(karmaParallelScript.replace('%KARMA_SHARD_INFO%', payload));
response.end(karmaParallelScript.replace('%KARMA_SHARD_INFO%', karmaSharderInfoMap));
}

@@ -73,8 +66,5 @@

return function (request, response, next) {
// Responsible for finding the id of the browser and saving it as a cookie so all future requests can access it
setBrowserIdCookie(log, request, response);
// Intercept the request for the actual sharding script so we can interpolate the browser-specific shard data in it
// Intercept the request for the actual sharding script so we can interpolate the shard data in it
if (request.url.indexOf(karmaParallelScriptName) !== -1) {
return writeKarmaSharderInfo(log, config, request, response);
return writeKarmaSharderInfoMap(log, config, response);
}

@@ -81,0 +71,0 @@

@@ -11,5 +11,8 @@ {

],
"peerDependencies": {
"karma": ">= 1.0.0"
},
"dependencies": {
"istanbul": "^0.4.5",
"lodash": "^4.17.5"
"lodash": "^4.17.11"
},

@@ -19,16 +22,16 @@ "description": "A Karma JS Framework to support sharding tests to run in parallel across multiple browsers",

"chai": "^4.1.2",
"eslint": "^4.9.0",
"eslint": "^5.6.0",
"eslint-plugin-security": "^1.4.0",
"jasmine": "^3.0.0",
"jasmine-core": "^2.8.0",
"karma": "^1.7.1",
"jasmine": "^3.2.0",
"jasmine-core": "^2.99.1",
"karma": "^3.0.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.4.1",
"karma-jasmine": "^1.1.1",
"karma-coverage": "^1.1.2",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-jasmine": "^1.1.2",
"karma-junit-reporter": "^1.2.0",
"karma-mocha": "^1.3.0",
"mocha": "^5.0.1",
"npm-run-all": "^4.1.2"
"mocha": "^5.2.0",
"npm-run-all": "^4.1.3"
},

@@ -79,5 +82,5 @@ "directories": {

"lint": "eslint --fix --config .eslintrc.json lib/\\*.js test/\\*.js index.js",
"test": "npm run lint && npm run karma"
"test": "run-p --aggregate-output lint karma"
},
"version": "0.2.9"
"version": "0.3.0"
}

@@ -39,3 +39,3 @@ # karma-parallel

### Basic
### Basic Installation

@@ -48,2 +48,14 @@ ```javascript

frameworks: ['parallel', 'mocha' /* or 'jasmine' */],
});
};
```
### Additional Configuration
```javascript
// karma.conf.js
module.exports = function(config) {
config.set({
// NOTE: 'parallel' must be the first framework in the list
frameworks: ['parallel', 'mocha' /* or 'jasmine' */],
plugins: [

@@ -120,3 +132,3 @@ // add karma-parallel to the plugins if you encounter something like "karma parallel No provider for framework:parallel"

* Requires the spec files to reside in separate files, meaning it is not compatible with bundlers such
as [`karma-webpack`](https://github.com/webpack-contrib/karma-webpack) or [`karma-browserify`](https://github.com/nikku/karma-browserify)
as [`karma-webpack`](https://github.com/webpack-contrib/karma-webpack) or [`karma-browserify`](https://github.com/nikku/karma-browserify) as used with most front end cli projects (e.g. @angular/cli)

@@ -123,0 +135,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