Comparing version 0.0.61 to 0.1.0
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" | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
33187
6
179
1
1
+ Addedistanbul@^0.3.5
+ Addedabbrev@1.0.9(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedasync@1.5.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addedescodegen@1.7.1(transitive)
+ Addedesprima@1.2.52.5.04.0.1(transitive)
+ Addedestraverse@1.9.3(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@1.0.7(transitive)
+ Addedfileset@0.2.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedhandlebars@4.7.8(transitive)
+ Addedhas-flag@1.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedistanbul@0.3.22(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedlevn@0.2.5(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addednopt@3.0.6(transitive)
+ Addedoptionator@0.5.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedresolve@1.1.7(transitive)
+ Addedsource-map@0.2.00.6.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsupports-color@3.2.3(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwordwrap@0.0.31.0.0(transitive)
- Removedblanket@1.1.5
- Removedblanket@1.1.5(transitive)
- Removedesprima@1.0.4(transitive)
- Removedfalafel@0.1.6(transitive)
- Removedforeach@2.0.6(transitive)
- Removedindexof@0.0.1(transitive)
- Removedis@0.2.7(transitive)
- Removedis-object@0.1.2(transitive)
- Removedobject-keys@0.2.0(transitive)
- Removedxtend@2.0.6(transitive)