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

affogato

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

affogato - npm Package Compare versions

Comparing version 0.0.61 to 0.1.0

.npmignore

144

main.js

@@ -6,2 +6,3 @@ var sinon = require('sinon');

chai.use(require("sinon-chai"));
var istanbul = require('istanbul');

@@ -16,10 +17,101 @@ var jsdom = require("jsdom");

/**
* @param {array} testFiles List of mocha test files
* @param {function} done Mocha's done() callback
* @param {array} appJS raw javascript sources to initialize the jsdom window
* @param {function} setup function to run
* @param {string} code to inject at the top of every test
* @param {Object} config Contains configuration options with the following:
* {array.<string>} testFiles
* {object} mochaOpts
* {object} codeCoverage
* {boolean} active
* {array} reportType
* {string} dir
* {object} appSource
* {array} prefix
* {object} app
* {array} suffix
* {function(object)} setup
* {function()} done
* {string} injection
* {string} buildDir
* {string} url
* {object} doneMessage
**/
exports.runTests = function(testFiles, done, appJS, setup, injection, buildDir, mochaOpts, url) {
exports.runTests = function(config) {
/**
* Array of filepaths to the testFiles
* @type {array.<string>}
*/
var testFiles = config.testFiles;
/**
* Options for the Mocha test runner
* @type {object}
*/
var mochaOpts = {
timeout: config.mochaOpts.timeout || 3000,
reporter: config.mochaOpts.reporter || 'dot',
spec: config.mochaOpts.spec || 'bdd',
};
/**
* Code coverage reporting options
* active - turn code coverage on or off
* reportType - 'clover','cobertura','html','json','json-summary','lcov',
* 'lcovonly','none','teamcity','text','text-summary'
* dir - where to save code coverage report, defaults to runtime directory
* @type {object}
*/
var codeCoverage = {
active: config.codeCoverage.active || false,
reportType: config.codeCoverage.reportType || [],
dir: config.codeCoverage.dir || buildDir
};
/**
* Raw sources of javascript to load into the dom upon initialization
* prefix {array} - scripts to load before app JS
* app {object} - application scripts, will be instrumented if code coverage is turned on
* { 'reference_to_code': 'script' }
* suffix {array} - scripts to load after app JS
* @type {object}
*/
var appSource = config.appSource;
/**
* Setup function for the window
* @type {function(object)}
*/
var setup = config.setup;
/**
* `done` callback for Mocha test runner
* @type {function()}
*/
var done = config.done;
/**
* Raw javascript to inject into each test file
* @type {string}
*/
var injection = config.injection;
/**
* Build directory
* @type {string}
*/
var buildDir = config.buildDir;
/**
* URL for JSDom
* @type {string}
*/
var url = config.url;
/**
* Custom console message for each report type with key as report type, value
* as the message (report types: 'clover','cobertura','html','json','json-summary',
* 'lcov','lcovonly','none','teamcity','text','text-summary')
* @type {Object}
*/
var doneMessage = config.doneMessage;
/**
* DOMContentLoaded isn't fired by JSDom properly. Fire it manually.

@@ -34,9 +126,28 @@ * From: http://stackoverflow.com/questions/9153314/manually-dispatchevent-domcontentloaded

};
if (codeCoverage.active) {
var instrumenter = new istanbul.Instrumenter();
var collector = new istanbul.Collector();
var reporter = new istanbul.Reporter(false, codeCoverage.dir);
var instrumentedAppCode = [];
for (var key in appSource.app) {
fs.writeFileSync(buildDir + '/' + key + '.js', appSource.app[key]);
instrumentedAppCode.push(instrumenter.instrumentSync(appSource.app[key], buildDir + '/' + key + '.js'));
}
} else {
// Transform source code into an array
var nonInstrumentedAppCode = [];
for (var key in appSource.app) {
nonInstrumentedAppCode.push(appSource.app[key]);
}
}
appSource.app = codeCoverage.active ? instrumentedAppCode : nonInstrumentedAppCode;
var sourceJs = appSource.prefix.concat(appSource.app,appSource.suffix);
jsdom.env({
url: url,
html: "<div></div>",
src: appJS,
done: function (errors, window) {
mochaOpts = mochaOpts || {};
src: sourceJs,
done: function(errors, window) {
setup(window);

@@ -66,2 +177,17 @@ global.sinon = sinon;

done(errs === 0);
if (codeCoverage.active) {
collector.add(window.__coverage__);
for (var i = 0; i < codeCoverage.reportType.length; i++) {
reporter.add(codeCoverage.reportType[i]);
}
reporter.write(collector, true, function () {
for (var key in doneMessage) {
if (codeCoverage.reportType.indexOf(key) > -1) {
console.log(doneMessage[key]);
}
}
});
}
testFiles.forEach(function(file) {

@@ -68,0 +194,0 @@ try {

{
"name": "affogato",
"version": "0.0.61",
"version": "0.1.0",
"description": "Support for mocha tests under jsdom.",
"repository": "N/A",
"repository": {
"type": "git",
"url": "https://github.com/N/A"
},
"engines": {

@@ -14,11 +17,14 @@ "node": ">=0.8.0"

},
"contributors": [{
"contributors": [
{
"name": "Kelei Xu",
"email": "kelei@pinterest.com"
}, {
},
{
"name": "Jessica Chan",
"email": "jessicachanstudios@gmail.com"
}],
}
],
"dependencies": {
"blanket": "1.1.5",
"istanbul": "^0.3.5",
"es6-promise": "2.0.1",

@@ -32,3 +38,32 @@ "chai": "1.9.1",

"sinon-chai": "2.5.0"
}
},
"bugs": {
"url": "https://github.com/N/A/issues"
},
"homepage": "https://github.com/N/A",
"_id": "affogato@0.0.61",
"scripts": {},
"_shasum": "7ae2d76202d98458e726271e964be278ed359c9e",
"_from": "affogato@",
"_npmVersion": "2.0.0",
"_npmUser": {
"name": "dwest-pinterest",
"email": "dwest@pinterest.com"
},
"maintainers": [
{
"name": "dwest-pinterest",
"email": "dwest@pinterest.com"
},
{
"name": "Jessica Chan",
"email": "jessicachanstudios@gmail.com"
}
],
"dist": {
"shasum": "7ae2d76202d98458e726271e964be278ed359c9e",
"tarball": "http://registry.npmjs.org/affogato/-/affogato-0.0.61.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/affogato/-/affogato-0.0.61.tgz"
}
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