UNPKG

find-node-modules

Version:

Return an array of all parent node_modules directories

1,953 lines (1,755 loc) 587 kB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ (function (process,global){ 'use strict'; /* eslint no-unused-vars: off */ /* eslint-env commonjs */ /** * Shim process.stdout. */ process.stdout = require('browser-stdout')({label: false}); var Mocha = require('./lib/mocha'); /** * Create a Mocha instance. * * @return {undefined} */ var mocha = new Mocha({reporter: 'html'}); /** * Save timer references to avoid Sinon interfering (see GH-237). */ var Date = global.Date; var setTimeout = global.setTimeout; var setInterval = global.setInterval; var clearTimeout = global.clearTimeout; var clearInterval = global.clearInterval; var uncaughtExceptionHandlers = []; var originalOnerrorHandler = global.onerror; /** * Remove uncaughtException listener. * Revert to original onerror handler if previously defined. */ process.removeListener = function(e, fn) { if (e === 'uncaughtException') { if (originalOnerrorHandler) { global.onerror = originalOnerrorHandler; } else { global.onerror = function() {}; } var i = uncaughtExceptionHandlers.indexOf(fn); if (i !== -1) { uncaughtExceptionHandlers.splice(i, 1); } } }; /** * Implements uncaughtException listener. */ process.on = function(e, fn) { if (e === 'uncaughtException') { global.onerror = function(err, url, line) { fn(new Error(err + ' (' + url + ':' + line + ')')); return !mocha.allowUncaught; }; uncaughtExceptionHandlers.push(fn); } }; // The BDD UI is registered by default, but no UI will be functional in the // browser without an explicit call to the overridden `mocha.ui` (see below). // Ensure that this default UI does not expose its methods to the global scope. mocha.suite.removeAllListeners('pre-require'); var immediateQueue = []; var immediateTimeout; function timeslice() { var immediateStart = new Date().getTime(); while (immediateQueue.length && new Date().getTime() - immediateStart < 100) { immediateQueue.shift()(); } if (immediateQueue.length) { immediateTimeout = setTimeout(timeslice, 0); } else { immediateTimeout = null; } } /** * High-performance override of Runner.immediately. */ Mocha.Runner.immediately = function(callback) { immediateQueue.push(callback); if (!immediateTimeout) { immediateTimeout = setTimeout(timeslice, 0); } }; /** * Function to allow assertion libraries to throw errors directly into mocha. * This is useful when running tests in a browser because window.onerror will * only receive the 'message' attribute of the Error. */ mocha.throwError = function(err) { uncaughtExceptionHandlers.forEach(function(fn) { fn(err); }); throw err; }; /** * Override ui to ensure that the ui functions are initialized. * Normally this would happen in Mocha.prototype.loadFiles. */ mocha.ui = function(ui) { Mocha.prototype.ui.call(this, ui); this.suite.emit('pre-require', global, null, this); return this; }; /** * Setup mocha with the given setting options. */ mocha.setup = function(opts) { if (typeof opts === 'string') { opts = {ui: opts}; } for (var opt in opts) { if (opts.hasOwnProperty(opt)) { this[opt](opts[opt]); } } return this; }; /** * Run mocha, returning the Runner. */ mocha.run = function(fn) { var options = mocha.options; mocha.globals('location'); var query = Mocha.utils.parseQuery(global.location.search || ''); if (query.grep) { mocha.grep(query.grep); } if (query.fgrep) { mocha.fgrep(query.fgrep); } if (query.invert) { mocha.invert(); } return Mocha.prototype.run.call(mocha, function(err) { // The DOM Document is not available in Web Workers. var document = global.document; if ( document && document.getElementById('mocha') && options.noHighlighting !== true ) { Mocha.utils.highlightTags('code'); } if (fn) { fn(err); } }); }; /** * Expose the process shim. * https://github.com/mochajs/mocha/pull/916 */ Mocha.process = process; /** * Expose mocha. */ global.Mocha = Mocha; global.mocha = mocha; // this allows test/acceptance/required-tokens.js to pass; thus, // you can now do `const describe = require('mocha').describe` in a // browser context (assuming browserification). should fix #880 module.exports = global; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./lib/mocha":14,"_process":69,"browser-stdout":41}],2:[function(require,module,exports){ (function (process,global){ 'use strict'; /** * Web Notifications module. * @module Growl */ /** * Save timer references to avoid Sinon interfering (see GH-237). */ var Date = global.Date; var setTimeout = global.setTimeout; var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END; /** * Checks if browser notification support exists. * * @public * @see {@link https://caniuse.com/#feat=notifications|Browser support (notifications)} * @see {@link https://caniuse.com/#feat=promises|Browser support (promises)} * @see {@link Mocha#growl} * @see {@link Mocha#isGrowlCapable} * @return {boolean} whether browser notification support exists */ exports.isCapable = function() { var hasNotificationSupport = 'Notification' in window; var hasPromiseSupport = typeof Promise === 'function'; return process.browser && hasNotificationSupport && hasPromiseSupport; }; /** * Implements browser notifications as a pseudo-reporter. * * @public * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/notification|Notification API} * @see {@link https://developers.google.com/web/fundamentals/push-notifications/display-a-notification|Displaying a Notification} * @see {@link Growl#isPermitted} * @see {@link Mocha#_growl} * @param {Runner} runner - Runner instance. */ exports.notify = function(runner) { var promise = isPermitted(); /** * Attempt notification. */ var sendNotification = function() { // If user hasn't responded yet... "No notification for you!" (Seinfeld) Promise.race([promise, Promise.resolve(undefined)]) .then(canNotify) .then(function() { display(runner); }) .catch(notPermitted); }; runner.once(EVENT_RUN_END, sendNotification); }; /** * Checks if browser notification is permitted by user. * * @private * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission|Notification.permission} * @see {@link Mocha#growl} * @see {@link Mocha#isGrowlPermitted} * @returns {Promise<boolean>} promise determining if browser notification * permissible when fulfilled. */ function isPermitted() { var permitted = { granted: function allow() { return Promise.resolve(true); }, denied: function deny() { return Promise.resolve(false); }, default: function ask() { return Notification.requestPermission().then(function(permission) { return permission === 'granted'; }); } }; return permitted[Notification.permission](); } /** * @summary * Determines if notification should proceed. * * @description * Notification shall <strong>not</strong> proceed unless `value` is true. * * `value` will equal one of: * <ul> * <li><code>true</code> (from `isPermitted`)</li> * <li><code>false</code> (from `isPermitted`)</li> * <li><code>undefined</code> (from `Promise.race`)</li> * </ul> * * @private * @param {boolean|undefined} value - Determines if notification permissible. * @returns {Promise<undefined>} Notification can proceed */ function canNotify(value) { if (!value) { var why = value === false ? 'blocked' : 'unacknowledged'; var reason = 'not permitted by user (' + why + ')'; return Promise.reject(new Error(reason)); } return Promise.resolve(); } /** * Displays the notification. * * @private * @param {Runner} runner - Runner instance. */ function display(runner) { var stats = runner.stats; var symbol = { cross: '\u274C', tick: '\u2705' }; var logo = require('../../package').notifyLogo; var _message; var message; var title; if (stats.failures) { _message = stats.failures + ' of ' + stats.tests + ' tests failed'; message = symbol.cross + ' ' + _message; title = 'Failed'; } else { _message = stats.passes + ' tests passed in ' + stats.duration + 'ms'; message = symbol.tick + ' ' + _message; title = 'Passed'; } // Send notification var options = { badge: logo, body: message, dir: 'ltr', icon: logo, lang: 'en-US', name: 'mocha', requireInteraction: false, timestamp: Date.now() }; var notification = new Notification(title, options); // Autoclose after brief delay (makes various browsers act same) var FORCE_DURATION = 4000; setTimeout(notification.close.bind(notification), FORCE_DURATION); } /** * As notifications are tangential to our purpose, just log the error. * * @private * @param {Error} err - Why notification didn't happen. */ function notPermitted(err) { console.error('notification error:', err.message); } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"../../package":90,"../runner":34,"_process":69}],3:[function(require,module,exports){ 'use strict'; /** * Expose `Progress`. */ module.exports = Progress; /** * Initialize a new `Progress` indicator. */ function Progress() { this.percent = 0; this.size(0); this.fontSize(11); this.font('helvetica, arial, sans-serif'); } /** * Set progress size to `size`. * * @public * @param {number} size * @return {Progress} Progress instance. */ Progress.prototype.size = function(size) { this._size = size; return this; }; /** * Set text to `text`. * * @public * @param {string} text * @return {Progress} Progress instance. */ Progress.prototype.text = function(text) { this._text = text; return this; }; /** * Set font size to `size`. * * @public * @param {number} size * @return {Progress} Progress instance. */ Progress.prototype.fontSize = function(size) { this._fontSize = size; return this; }; /** * Set font to `family`. * * @param {string} family * @return {Progress} Progress instance. */ Progress.prototype.font = function(family) { this._font = family; return this; }; /** * Update percentage to `n`. * * @param {number} n * @return {Progress} Progress instance. */ Progress.prototype.update = function(n) { this.percent = n; return this; }; /** * Draw on `ctx`. * * @param {CanvasRenderingContext2d} ctx * @return {Progress} Progress instance. */ Progress.prototype.draw = function(ctx) { try { var percent = Math.min(this.percent, 100); var size = this._size; var half = size / 2; var x = half; var y = half; var rad = half - 1; var fontSize = this._fontSize; ctx.font = fontSize + 'px ' + this._font; var angle = Math.PI * 2 * (percent / 100); ctx.clearRect(0, 0, size, size); // outer circle ctx.strokeStyle = '#9f9f9f'; ctx.beginPath(); ctx.arc(x, y, rad, 0, angle, false); ctx.stroke(); // inner circle ctx.strokeStyle = '#eee'; ctx.beginPath(); ctx.arc(x, y, rad - 1, 0, angle, true); ctx.stroke(); // text var text = this._text || (percent | 0) + '%'; var w = ctx.measureText(text).width; ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1); } catch (ignore) { // don't fail if we can't render progress } return this; }; },{}],4:[function(require,module,exports){ (function (global){ 'use strict'; exports.isatty = function isatty() { return true; }; exports.getWindowSize = function getWindowSize() { if ('innerHeight' in global) { return [global.innerHeight, global.innerWidth]; } // In a Web Worker, the DOM Window is not available. return [640, 480]; }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],5:[function(require,module,exports){ 'use strict'; /** * @module Context */ /** * Expose `Context`. */ module.exports = Context; /** * Initialize a new `Context`. * * @private */ function Context() {} /** * Set or get the context `Runnable` to `runnable`. * * @private * @param {Runnable} runnable * @return {Context} context */ Context.prototype.runnable = function(runnable) { if (!arguments.length) { return this._runnable; } this.test = this._runnable = runnable; return this; }; /** * Set or get test timeout `ms`. * * @private * @param {number} ms * @return {Context} self */ Context.prototype.timeout = function(ms) { if (!arguments.length) { return this.runnable().timeout(); } this.runnable().timeout(ms); return this; }; /** * Set test timeout `enabled`. * * @private * @param {boolean} enabled * @return {Context} self */ Context.prototype.enableTimeouts = function(enabled) { if (!arguments.length) { return this.runnable().enableTimeouts(); } this.runnable().enableTimeouts(enabled); return this; }; /** * Set or get test slowness threshold `ms`. * * @private * @param {number} ms * @return {Context} self */ Context.prototype.slow = function(ms) { if (!arguments.length) { return this.runnable().slow(); } this.runnable().slow(ms); return this; }; /** * Mark a test as skipped. * * @private * @throws Pending */ Context.prototype.skip = function() { this.runnable().skip(); }; /** * Set or get a number of allowed retries on failed tests * * @private * @param {number} n * @return {Context} self */ Context.prototype.retries = function(n) { if (!arguments.length) { return this.runnable().retries(); } this.runnable().retries(n); return this; }; },{}],6:[function(require,module,exports){ 'use strict'; /** * @module Errors */ /** * Factory functions to create throwable error objects */ /** * Creates an error object to be thrown when no files to be tested could be found using specified pattern. * * @public * @param {string} message - Error message to be displayed. * @param {string} pattern - User-specified argument value. * @returns {Error} instance detailing the error condition */ function createNoFilesMatchPatternError(message, pattern) { var err = new Error(message); err.code = 'ERR_MOCHA_NO_FILES_MATCH_PATTERN'; err.pattern = pattern; return err; } /** * Creates an error object to be thrown when the reporter specified in the options was not found. * * @public * @param {string} message - Error message to be displayed. * @param {string} reporter - User-specified reporter value. * @returns {Error} instance detailing the error condition */ function createInvalidReporterError(message, reporter) { var err = new TypeError(message); err.code = 'ERR_MOCHA_INVALID_REPORTER'; err.reporter = reporter; return err; } /** * Creates an error object to be thrown when the interface specified in the options was not found. * * @public * @param {string} message - Error message to be displayed. * @param {string} ui - User-specified interface value. * @returns {Error} instance detailing the error condition */ function createInvalidInterfaceError(message, ui) { var err = new Error(message); err.code = 'ERR_MOCHA_INVALID_INTERFACE'; err.interface = ui; return err; } /** * Creates an error object to be thrown when a behavior, option, or parameter is unsupported. * * @public * @param {string} message - Error message to be displayed. * @returns {Error} instance detailing the error condition */ function createUnsupportedError(message) { var err = new Error(message); err.code = 'ERR_MOCHA_UNSUPPORTED'; return err; } /** * Creates an error object to be thrown when an argument is missing. * * @public * @param {string} message - Error message to be displayed. * @param {string} argument - Argument name. * @param {string} expected - Expected argument datatype. * @returns {Error} instance detailing the error condition */ function createMissingArgumentError(message, argument, expected) { return createInvalidArgumentTypeError(message, argument, expected); } /** * Creates an error object to be thrown when an argument did not use the supported type * * @public * @param {string} message - Error message to be displayed. * @param {string} argument - Argument name. * @param {string} expected - Expected argument datatype. * @returns {Error} instance detailing the error condition */ function createInvalidArgumentTypeError(message, argument, expected) { var err = new TypeError(message); err.code = 'ERR_MOCHA_INVALID_ARG_TYPE'; err.argument = argument; err.expected = expected; err.actual = typeof argument; return err; } /** * Creates an error object to be thrown when an argument did not use the supported value * * @public * @param {string} message - Error message to be displayed. * @param {string} argument - Argument name. * @param {string} value - Argument value. * @param {string} [reason] - Why value is invalid. * @returns {Error} instance detailing the error condition */ function createInvalidArgumentValueError(message, argument, value, reason) { var err = new TypeError(message); err.code = 'ERR_MOCHA_INVALID_ARG_VALUE'; err.argument = argument; err.value = value; err.reason = typeof reason !== 'undefined' ? reason : 'is invalid'; return err; } /** * Creates an error object to be thrown when an exception was caught, but the `Error` is falsy or undefined. * * @public * @param {string} message - Error message to be displayed. * @returns {Error} instance detailing the error condition */ function createInvalidExceptionError(message, value) { var err = new Error(message); err.code = 'ERR_MOCHA_INVALID_EXCEPTION'; err.valueType = typeof value; err.value = value; return err; } module.exports = { createInvalidArgumentTypeError: createInvalidArgumentTypeError, createInvalidArgumentValueError: createInvalidArgumentValueError, createInvalidExceptionError: createInvalidExceptionError, createInvalidInterfaceError: createInvalidInterfaceError, createInvalidReporterError: createInvalidReporterError, createMissingArgumentError: createMissingArgumentError, createNoFilesMatchPatternError: createNoFilesMatchPatternError, createUnsupportedError: createUnsupportedError }; },{}],7:[function(require,module,exports){ 'use strict'; var Runnable = require('./runnable'); var inherits = require('./utils').inherits; /** * Expose `Hook`. */ module.exports = Hook; /** * Initialize a new `Hook` with the given `title` and callback `fn` * * @class * @extends Runnable * @param {String} title * @param {Function} fn */ function Hook(title, fn) { Runnable.call(this, title, fn); this.type = 'hook'; } /** * Inherit from `Runnable.prototype`. */ inherits(Hook, Runnable); /** * Get or set the test `err`. * * @memberof Hook * @public * @param {Error} err * @return {Error} */ Hook.prototype.error = function(err) { if (!arguments.length) { err = this._error; this._error = null; return err; } this._error = err; }; },{"./runnable":33,"./utils":38}],8:[function(require,module,exports){ 'use strict'; var Test = require('../test'); var EVENT_FILE_PRE_REQUIRE = require('../suite').constants .EVENT_FILE_PRE_REQUIRE; /** * BDD-style interface: * * describe('Array', function() { * describe('#indexOf()', function() { * it('should return -1 when not present', function() { * // ... * }); * * it('should return the index when present', function() { * // ... * }); * }); * }); * * @param {Suite} suite Root suite. */ module.exports = function bddInterface(suite) { var suites = [suite]; suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) { var common = require('./common')(suites, context, mocha); context.before = common.before; context.after = common.after; context.beforeEach = common.beforeEach; context.afterEach = common.afterEach; context.run = mocha.options.delay && common.runWithSuite(suite); /** * Describe a "suite" with the given `title` * and callback `fn` containing nested suites * and/or tests. */ context.describe = context.context = function(title, fn) { return common.suite.create({ title: title, file: file, fn: fn }); }; /** * Pending describe. */ context.xdescribe = context.xcontext = context.describe.skip = function( title, fn ) { return common.suite.skip({ title: title, file: file, fn: fn }); }; /** * Exclusive suite. */ context.describe.only = function(title, fn) { return common.suite.only({ title: title, file: file, fn: fn }); }; /** * Describe a specification or test-case * with the given `title` and callback `fn` * acting as a thunk. */ context.it = context.specify = function(title, fn) { var suite = suites[0]; if (suite.isPending()) { fn = null; } var test = new Test(title, fn); test.file = file; suite.addTest(test); return test; }; /** * Exclusive test-case. */ context.it.only = function(title, fn) { return common.test.only(mocha, context.it(title, fn)); }; /** * Pending test case. */ context.xit = context.xspecify = context.it.skip = function(title) { return context.it(title); }; /** * Number of attempts to retry. */ context.it.retries = function(n) { context.retries(n); }; }); }; module.exports.description = 'BDD or RSpec style [default]'; },{"../suite":36,"../test":37,"./common":9}],9:[function(require,module,exports){ 'use strict'; var Suite = require('../suite'); var errors = require('../errors'); var createMissingArgumentError = errors.createMissingArgumentError; /** * Functions common to more than one interface. * * @param {Suite[]} suites * @param {Context} context * @param {Mocha} mocha * @return {Object} An object containing common functions. */ module.exports = function(suites, context, mocha) { /** * Check if the suite should be tested. * * @private * @param {Suite} suite - suite to check * @returns {boolean} */ function shouldBeTested(suite) { return ( !mocha.options.grep || (mocha.options.grep && mocha.options.grep.test(suite.fullTitle()) && !mocha.options.invert) ); } return { /** * This is only present if flag --delay is passed into Mocha. It triggers * root suite execution. * * @param {Suite} suite The root suite. * @return {Function} A function which runs the root suite */ runWithSuite: function runWithSuite(suite) { return function run() { suite.run(); }; }, /** * Execute before running tests. * * @param {string} name * @param {Function} fn */ before: function(name, fn) { suites[0].beforeAll(name, fn); }, /** * Execute after running tests. * * @param {string} name * @param {Function} fn */ after: function(name, fn) { suites[0].afterAll(name, fn); }, /** * Execute before each test case. * * @param {string} name * @param {Function} fn */ beforeEach: function(name, fn) { suites[0].beforeEach(name, fn); }, /** * Execute after each test case. * * @param {string} name * @param {Function} fn */ afterEach: function(name, fn) { suites[0].afterEach(name, fn); }, suite: { /** * Create an exclusive Suite; convenience function * See docstring for create() below. * * @param {Object} opts * @returns {Suite} */ only: function only(opts) { opts.isOnly = true; return this.create(opts); }, /** * Create a Suite, but skip it; convenience function * See docstring for create() below. * * @param {Object} opts * @returns {Suite} */ skip: function skip(opts) { opts.pending = true; return this.create(opts); }, /** * Creates a suite. * * @param {Object} opts Options * @param {string} opts.title Title of Suite * @param {Function} [opts.fn] Suite Function (not always applicable) * @param {boolean} [opts.pending] Is Suite pending? * @param {string} [opts.file] Filepath where this Suite resides * @param {boolean} [opts.isOnly] Is Suite exclusive? * @returns {Suite} */ create: function create(opts) { var suite = Suite.create(suites[0], opts.title); suite.pending = Boolean(opts.pending); suite.file = opts.file; suites.unshift(suite); if (opts.isOnly) { if (mocha.options.forbidOnly && shouldBeTested(suite)) { throw new Error('`.only` forbidden'); } suite.parent.appendOnlySuite(suite); } if (suite.pending) { if (mocha.options.forbidPending && shouldBeTested(suite)) { throw new Error('Pending test forbidden'); } } if (typeof opts.fn === 'function') { opts.fn.call(suite); suites.shift(); } else if (typeof opts.fn === 'undefined' && !suite.pending) { throw createMissingArgumentError( 'Suite "' + suite.fullTitle() + '" was defined but no callback was supplied. ' + 'Supply a callback or explicitly skip the suite.', 'callback', 'function' ); } else if (!opts.fn && suite.pending) { suites.shift(); } return suite; } }, test: { /** * Exclusive test-case. * * @param {Object} mocha * @param {Function} test * @returns {*} */ only: function(mocha, test) { test.parent.appendOnlyTest(test); return test; }, /** * Pending test case. * * @param {string} title */ skip: function(title) { context.test(title); }, /** * Number of retry attempts * * @param {number} n */ retries: function(n) { context.retries(n); } } }; }; },{"../errors":6,"../suite":36}],10:[function(require,module,exports){ 'use strict'; var Suite = require('../suite'); var Test = require('../test'); /** * Exports-style (as Node.js module) interface: * * exports.Array = { * '#indexOf()': { * 'should return -1 when the value is not present': function() { * * }, * * 'should return the correct index when the value is present': function() { * * } * } * }; * * @param {Suite} suite Root suite. */ module.exports = function(suite) { var suites = [suite]; suite.on(Suite.constants.EVENT_FILE_REQUIRE, visit); function visit(obj, file) { var suite; for (var key in obj) { if (typeof obj[key] === 'function') { var fn = obj[key]; switch (key) { case 'before': suites[0].beforeAll(fn); break; case 'after': suites[0].afterAll(fn); break; case 'beforeEach': suites[0].beforeEach(fn); break; case 'afterEach': suites[0].afterEach(fn); break; default: var test = new Test(key, fn); test.file = file; suites[0].addTest(test); } } else { suite = Suite.create(suites[0], key); suites.unshift(suite); visit(obj[key], file); suites.shift(); } } } }; module.exports.description = 'Node.js module ("exports") style'; },{"../suite":36,"../test":37}],11:[function(require,module,exports){ 'use strict'; exports.bdd = require('./bdd'); exports.tdd = require('./tdd'); exports.qunit = require('./qunit'); exports.exports = require('./exports'); },{"./bdd":8,"./exports":10,"./qunit":12,"./tdd":13}],12:[function(require,module,exports){ 'use strict'; var Test = require('../test'); var EVENT_FILE_PRE_REQUIRE = require('../suite').constants .EVENT_FILE_PRE_REQUIRE; /** * QUnit-style interface: * * suite('Array'); * * test('#length', function() { * var arr = [1,2,3]; * ok(arr.length == 3); * }); * * test('#indexOf()', function() { * var arr = [1,2,3]; * ok(arr.indexOf(1) == 0); * ok(arr.indexOf(2) == 1); * ok(arr.indexOf(3) == 2); * }); * * suite('String'); * * test('#length', function() { * ok('foo'.length == 3); * }); * * @param {Suite} suite Root suite. */ module.exports = function qUnitInterface(suite) { var suites = [suite]; suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) { var common = require('./common')(suites, context, mocha); context.before = common.before; context.after = common.after; context.beforeEach = common.beforeEach; context.afterEach = common.afterEach; context.run = mocha.options.delay && common.runWithSuite(suite); /** * Describe a "suite" with the given `title`. */ context.suite = function(title) { if (suites.length > 1) { suites.shift(); } return common.suite.create({ title: title, file: file, fn: false }); }; /** * Exclusive Suite. */ context.suite.only = function(title) { if (suites.length > 1) { suites.shift(); } return common.suite.only({ title: title, file: file, fn: false }); }; /** * Describe a specification or test-case * with the given `title` and callback `fn` * acting as a thunk. */ context.test = function(title, fn) { var test = new Test(title, fn); test.file = file; suites[0].addTest(test); return test; }; /** * Exclusive test-case. */ context.test.only = function(title, fn) { return common.test.only(mocha, context.test(title, fn)); }; context.test.skip = common.test.skip; context.test.retries = common.test.retries; }); }; module.exports.description = 'QUnit style'; },{"../suite":36,"../test":37,"./common":9}],13:[function(require,module,exports){ 'use strict'; var Test = require('../test'); var EVENT_FILE_PRE_REQUIRE = require('../suite').constants .EVENT_FILE_PRE_REQUIRE; /** * TDD-style interface: * * suite('Array', function() { * suite('#indexOf()', function() { * suiteSetup(function() { * * }); * * test('should return -1 when not present', function() { * * }); * * test('should return the index when present', function() { * * }); * * suiteTeardown(function() { * * }); * }); * }); * * @param {Suite} suite Root suite. */ module.exports = function(suite) { var suites = [suite]; suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) { var common = require('./common')(suites, context, mocha); context.setup = common.beforeEach; context.teardown = common.afterEach; context.suiteSetup = common.before; context.suiteTeardown = common.after; context.run = mocha.options.delay && common.runWithSuite(suite); /** * Describe a "suite" with the given `title` and callback `fn` containing * nested suites and/or tests. */ context.suite = function(title, fn) { return common.suite.create({ title: title, file: file, fn: fn }); }; /** * Pending suite. */ context.suite.skip = function(title, fn) { return common.suite.skip({ title: title, file: file, fn: fn }); }; /** * Exclusive test-case. */ context.suite.only = function(title, fn) { return common.suite.only({ title: title, file: file, fn: fn }); }; /** * Describe a specification or test-case with the given `title` and * callback `fn` acting as a thunk. */ context.test = function(title, fn) { var suite = suites[0]; if (suite.isPending()) { fn = null; } var test = new Test(title, fn); test.file = file; suite.addTest(test); return test; }; /** * Exclusive test-case. */ context.test.only = function(title, fn) { return common.test.only(mocha, context.test(title, fn)); }; context.test.skip = common.test.skip; context.test.retries = common.test.retries; }); }; module.exports.description = 'traditional "suite"/"test" instead of BDD\'s "describe"/"it"'; },{"../suite":36,"../test":37,"./common":9}],14:[function(require,module,exports){ (function (process,global){ 'use strict'; /*! * mocha * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca> * MIT Licensed */ var escapeRe = require('escape-string-regexp'); var path = require('path'); var builtinReporters = require('./reporters'); var growl = require('./growl'); var utils = require('./utils'); var mocharc = require('./mocharc.json'); var errors = require('./errors'); var Suite = require('./suite'); var createStatsCollector = require('./stats-collector'); var createInvalidReporterError = errors.createInvalidReporterError; var createInvalidInterfaceError = errors.createInvalidInterfaceError; var EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE; var EVENT_FILE_POST_REQUIRE = Suite.constants.EVENT_FILE_POST_REQUIRE; var EVENT_FILE_REQUIRE = Suite.constants.EVENT_FILE_REQUIRE; var sQuote = utils.sQuote; exports = module.exports = Mocha; /** * To require local UIs and reporters when running in node. */ if (!process.browser) { var cwd = process.cwd(); module.paths.push(cwd, path.join(cwd, 'node_modules')); } /** * Expose internals. */ /** * @public * @class utils * @memberof Mocha */ exports.utils = utils; exports.interfaces = require('./interfaces'); /** * @public * @memberof Mocha */ exports.reporters = builtinReporters; exports.Runnable = require('./runnable'); exports.Context = require('./context'); /** * * @memberof Mocha */ exports.Runner = require('./runner'); exports.Suite = Suite; exports.Hook = require('./hook'); exports.Test = require('./test'); /** * Constructs a new Mocha instance with `options`. * * @public * @class Mocha * @param {Object} [options] - Settings object. * @param {boolean} [options.allowUncaught] - Propagate uncaught errors? * @param {boolean} [options.asyncOnly] - Force `done` callback or promise? * @param {boolean} [options.bail] - Bail after first test failure? * @param {boolean} [options.checkLeaks] - If true, check leaks. * @param {boolean} [options.delay] - Delay root suite execution? * @param {boolean} [options.enableTimeouts] - Enable timeouts? * @param {string} [options.fgrep] - Test filter given string. * @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite? * @param {boolean} [options.forbidPending] - Pending tests fail the suite? * @param {boolean} [options.fullStackTrace] - Full stacktrace upon failure? * @param {string[]} [options.global] - Variables expected in global scope. * @param {RegExp|string} [options.grep] - Test filter given regular expression. * @param {boolean} [options.growl] - Enable desktop notifications? * @param {boolean} [options.hideDiff] - Suppress diffs from failures? * @param {boolean} [options.ignoreLeaks] - Ignore global leaks? * @param {boolean} [options.invert] - Invert test filter matches? * @param {boolean} [options.noHighlighting] - Disable syntax highlighting? * @param {string} [options.reporter] - Reporter name. * @param {Object} [options.reporterOption] - Reporter settings object. * @param {number} [options.retries] - Number of times to retry failed tests. * @param {number} [options.slow] - Slow threshold value. * @param {number|string} [options.timeout] - Timeout threshold value. * @param {string} [options.ui] - Interface name. * @param {boolean} [options.color] - Color TTY output from reporter? * @param {boolean} [options.useInlineDiffs] - Use inline diffs? */ function Mocha(options) { options = utils.assign({}, mocharc, options || {}); this.files = []; this.options = options; // root suite this.suite = new exports.Suite('', new exports.Context(), true); if ('useColors' in options) { utils.deprecate( 'useColors is DEPRECATED and will be removed from a future version of Mocha. Instead, use the "color" option' ); options.color = 'color' in options ? options.color : options.useColors; } // Globals are passed in as options.global, with options.globals for backward compatibility. options.globals = options.global || options.globals || []; delete options.global; this.grep(options.grep) .fgrep(options.fgrep) .ui(options.ui) .bail(options.bail) .reporter(options.reporter, options.reporterOptions) .useColors(options.color) .slow(options.slow) .useInlineDiffs(options.inlineDiffs) .globals(options.globals); if ('enableTimeouts' in options) { utils.deprecate( 'enableTimeouts is DEPRECATED and will be removed from a future version of Mocha. Instead, use "timeout: false" to disable timeouts.' ); if (options.enableTimeouts === false) { this.timeout(0); } } // this guard exists because Suite#timeout does not consider `undefined` to be valid input if (typeof options.timeout !== 'undefined') { this.timeout(options.timeout === false ? 0 : options.timeout); } if ('retries' in options) { this.retries(options.retries); } if ('diff' in options) { this.hideDiff(!options.diff); } [ 'allowUncaught', 'asyncOnly', 'checkLeaks', 'delay', 'forbidOnly', 'forbidPending', 'fullTrace', 'growl', 'invert' ].forEach(function(opt) { if (options[opt]) { this[opt](); } }, this); } /** * Enables or disables bailing on the first failure. * * @public * @see {@link https://mochajs.org/#-b---bail|CLI option} * @param {boolean} [bail=true] - Whether to bail on first error. * @returns {Mocha} this * @chainable */ Mocha.prototype.bail = function(bail) { if (!arguments.length) { bail = true; } this.suite.bail(bail); return this; }; /** * @summary * Adds `file` to be loaded for execution. * * @description * Useful for generic setup code that must be included within test suite. * * @public * @see {@link https://mochajs.org/#--file-file|CLI option} * @param {string} file - Pathname of file to be loaded. * @returns {Mocha} this * @chainable */ Mocha.prototype.addFile = function(file) { this.files.push(file); return this; }; /** * Sets reporter to `reporter`, defaults to "spec". * * @public * @see {@link https://mochajs.org/#-r---reporter-name|CLI option} * @see {@link https://mochajs.org/#reporters|Reporters} * @param {String|Function} reporter - Reporter name or constructor. * @param {Object} [reporterOptions] - Options used to configure the reporter. * @returns {Mocha} this * @chainable * @throws {Error} if requested reporter cannot be loaded * @example * * // Use XUnit reporter and direct its output to file * mocha.reporter('xunit', { output: '/path/to/testspec.xunit.xml' }); */ Mocha.prototype.reporter = function(reporter, reporterOptions) { if (typeof reporter === 'function') { this._reporter = reporter; } else { reporter = reporter || 'spec'; var _reporter; // Try to load a built-in reporter. if (builtinReporters[reporter]) { _reporter = builtinReporters[reporter]; } // Try to load reporters from process.cwd() and node_modules if (!_reporter) { try { _reporter = require(reporter); } catch (err) { if ( err.code !== 'MODULE_NOT_FOUND' || err.message.indexOf('Cannot find module') !== -1 ) { // Try to load reporters from a path (absolute or relative) try { _reporter = require(path.resolve(process.cwd(), reporter)); } catch (_err) { _err.code !== 'MODULE_NOT_FOUND' || _err.message.indexOf('Cannot find module') !== -1 ? console.warn(sQuote(reporter) + ' reporter not found') : console.warn( sQuote(reporter) + ' reporter blew up with error:\n' + err.stack ); } } else { console.warn( sQuote(reporter) + ' reporter blew up with error:\n' + err.stack ); } } } if (!_reporter) { throw createInvalidReporterError( 'invalid reporter ' + sQuote(reporter), reporter ); } this._reporter = _reporter; } this.options.reporterOptions = reporterOptions; return this; }; /** * Sets test UI `name`, defaults to "bdd". * * @public * @see {@link https://mochajs.org/#-u---ui-name|CLI option} * @see {@link https://mochajs.org/#interfaces|Interface DSLs} * @param {string|Function} [ui=bdd] - Interface name or class. * @returns {Mocha} this * @chainable * @throws {Error} if requested interface cannot be loaded */ Mocha.prototype.ui = function(ui) { var bindInterface; if (typeof ui === 'function') { bindInterface = ui; } else { ui = ui || 'bdd'; bindInterface = exports.interfaces[ui]; if (!bindInterface) { try { bindInterface = require(ui); } catch (err) { throw createInvalidInterfaceError( 'invalid interface ' + sQuote(ui), ui ); } } } bindInterface(this.suite); this.suite.on(EVENT_FILE_PRE_REQUIRE, function(context) { exports.afterEach = context.afterEach || context.teardown; exports.after = context.after || context.suiteTeardown; exports.beforeEach = context.beforeEach || context.setup; exports.before = context.before || context.suiteSetup; exports.describe = context.describe || context.suite; exports.it = context.it || context.test; exports.xit = context.xit || (context.test && context.test.skip); exports.setup = context.setup || context.beforeEach; exports.suiteSetup = context.suiteSetup || context.before; exports.suiteTeardown = context.suiteTeardown || context.after; exports.suite = context.suite || context.describe; exports.teardown = context.teardown || context.afterEach; exports.test = context.test || context.it; exports.run = context.run; }); return this; }; /** * Loads `files` prior to execution. * * @description * The implementation relies on Node's `require` to execute * the test interface functions and will be subject to its cache. * * @private * @see {@link Mocha#addFile} * @see {@link Mocha#run} * @see {@link Mocha#unloadFiles} * @param {Function} [fn] - Callback invoked upon completion. */ Mocha.prototype.loadFiles = function(fn) { var self = this; var suite = this.suite; this.files.forEach(function(file) { file = path.resolve(file); suite.emit(EVENT_FILE_PRE_REQUIRE, global, file, self); suite.emit(EVENT_FILE_REQUIRE, require(file), file, self); suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self); }); fn && fn(); }; /** * Removes a previously loaded file from Node's `require` cache. * * @private * @static * @see {@link Mocha#unloadFiles} * @param {string} file - Pathname of file to be unloaded. */ Mocha.unloadFile = function(file) { delete require.cache[require.resolve(file)]; }; /** * Unloads `files` from Node's `require` cache. * * @description * This allows files to be "freshly" reloaded, providing the ability * to reuse a Mocha instance programmatically. * * <strong>Intended for consumers &mdash; not used internally</strong> * * @public * @see {@link Mocha.unloadFile} * @see {@link Mocha#loadFiles} * @see {@link Mocha#run} * @returns {Mocha} this * @chainable */ Mocha.prototype.unloadFiles = function() { this.files.forEach(Mocha.unloadFile); return this; }; /** * Sets `grep` filter after escaping RegExp special characters. * * @public * @see {@link Mocha#grep} * @param {string} str - Value to be converted to a regexp. * @returns {Mocha} this * @chainable * @example * * // Select tests whose full title begins with `"foo"` followed by a period * mocha.fgrep('foo.'); */ Mocha.prototype.fgrep = function(str) { if (!str) { return this; } return this.grep(new RegExp(escapeRe(str))); }; /** * @summary * Sets `grep` filter used to select specific tests for execution. * * @description * If `re` is a regexp-like string, it will be converted to regexp. * The regexp is tested against the full title of each test (i.e., the * name of the test preceded by titles of each its ancestral suites). * As such, using an <em>exact-match</em> fixed pattern against the * test name itself will not yield any matches. * <br> * <strong>Previous filter value will be overwritten on each call!</strong> * * @public * @see {@link https://mochajs.org/#-g---grep-pattern|CLI option} * @see {@link Mocha#fgrep} * @see {@link Mocha#invert} * @param {RegExp|String} re - Regular expression used to select tests. * @return {Mocha} this * @chainable * @example * * // Select tests whose full title contains `"match"`, ignoring case * mocha.grep(/match/i); * @example * * // Same as above but with regexp-like string argument * mocha.grep('/match/i'); * @example * * // ## Anti-example * // Given embedded test `it('only-this-test')`... * mocha.grep('/^only-this-test$/'); // NO! Use `.only()` to do this! */ Mocha.prototype.grep = function(re) { if (utils.isString(re)) { // extract args if it's regex-like, i.e: [string, pattern, flag] var arg = re.match(/^\/(.*)\/(g|i|)$|.*/); this.options.grep = new RegExp(arg[1] || arg[0], arg[2]); } else { this.options.grep = re; } return this; }; /** * Inverts `grep` matches. * * @public * @see {@link Mocha#grep} * @return {Mocha} this * @chainable * @example * * // Select tests whose full title does *not* contain `"match"`, ignoring case * mocha.grep(/match/i).invert(); */ Mocha.prototype.invert = function() { this.options.invert = true; return this; }; /** * Enables or disables ignoring global leaks. * * @public * @see {@link Mocha#checkLeaks} * @param {boolean} ignoreLeaks - Whether to ignore global leaks. * @return {Mocha} this * @chainable * @example * * // Ignore global leaks * mocha.ignoreLeaks(true); */ Mocha.prototype.ignoreLeaks = function(ignoreLeaks) { this.options.ignoreLeaks = Boolean(ignoreLeaks); return this; }; /** * Enables checking for global variables leaked while running tests. * * @public * @see {@link https://mochajs.org/#--check-leaks|CLI option} * @see {@link Mocha#ignoreLeaks} * @return {Mocha} this * @chainable */ Mocha.prototype.checkLeaks = function() { this.options.ignoreLeaks = false; return this; }; /** * Displays full stack trace upon test failure. * * @public * @return {Mocha} this * @chainable */ Mocha.prototype.fullTrace = function() { this.options.fullStackTrace = true; return this; }; /** * Enables desktop notification support if prerequisite software installed. * * @public * @see {@link Mocha#isGrowlCapable} * @see {@link Mocha#_growl} * @return {Mocha} this * @chainable */ Mocha.prototype.growl = function() { this.options.growl = this.isGrowlCapable(); if (!this.options.growl) { var detail = process.browser ? 'notification support not available in this browser...' : 'notification support prerequisites not installed...'; console.error(detail + ' cannot enable!'); } return this; }; /** * @summary * Determines if Growl support seems likely. * * @description * <strong>Not available when run in browser.</strong> * * @private * @see {@link Growl#isCapable} * @see {@link Mocha#growl} * @return {boolean} whether Growl support can be expected */ Mocha.prototype.isGrowlCapable = growl.isCapable; /** * Implements desktop notifications using a pseudo-reporter. * * @private * @see {@link Mocha#growl} * @see {@link Growl#notify} * @param {Runner} runner - Runner instance. */ Mocha.prototype._growl = growl.notify; /** * Specifies whitelist of variable names to be expected in global scope. * * @public * @see {@link https://mochajs.org/#-global-variable-name|CLI option} * @see {@link Mocha#checkLeaks} * @param {String[]|String} globals - Accepted global variable name(s). * @return {Mocha} this * @chainable * @example * * // Specify variables to be expected in global scope * mocha.globals(['jQuery', 'MyLib']); */ Mocha.prototype.globals = function(globals) { this.options.globals = this.options.globals .c