From 1568d251dc149f2a95de6f6819fccedbfb272893 Mon Sep 17 00:00:00 2001 From: Adam Gruber Date: Tue, 27 Jun 2017 16:11:23 -0400 Subject: [PATCH] remove dist from repo --- .gitignore | 3 +- dist/addContext.js | 130 ----------------------- dist/config.js | 48 --------- dist/mochawesome.js | 173 ------------------------------ dist/utils.js | 251 -------------------------------------------- 5 files changed, 2 insertions(+), 603 deletions(-) delete mode 100644 dist/addContext.js delete mode 100644 dist/config.js delete mode 100755 dist/mochawesome.js delete mode 100644 dist/utils.js diff --git a/.gitignore b/.gitignore index a76d046..fcd3faf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ mochawesome-reports/ mochawesome-report/ _site/ coverage/ -.nyc_output/ \ No newline at end of file +.nyc_output/ +dist/ diff --git a/dist/addContext.js b/dist/addContext.js deleted file mode 100644 index dc4d11c..0000000 --- a/dist/addContext.js +++ /dev/null @@ -1,130 +0,0 @@ -'use strict'; - -var _typeof2 = require('babel-runtime/helpers/typeof'); - -var _typeof3 = _interopRequireDefault(_typeof2); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var isObject = require('lodash/isObject'); -var isEmpty = require('lodash/isEmpty'); -var chalk = require('chalk'); -var stringify = require('json-stringify-safe'); - -var errorPrefix = 'Error adding context:'; -var ERRORS = { - INVALID_ARGS: errorPrefix + ' Invalid arguments.', - INVALID_TEST: errorPrefix + ' Invalid test object.', - INVALID_CONTEXT: function INVALID_CONTEXT(ctx) { - var expected = 'Expected a string or an object of shape { title: string, value: any } but saw:'; - return errorPrefix + ' ' + expected + '\n' + stringify(ctx, function (key, val) { - return val === undefined ? 'undefined' : val; - }, 2); - } -}; - -/** - * HELPER FUNCTIONS - */ - -/* istanbul ignore next */ -function log(msg, level) { - var logMethod = console[level] || console.log; - var out = msg; - if ((typeof msg === 'undefined' ? 'undefined' : (0, _typeof3.default)(msg)) === 'object') { - out = stringify(msg, null, 2); - } - logMethod('[' + chalk.gray('mochawesome') + '] ' + out + '\n'); -} - -function _isValidContext(ctx) { - /* - * Context is valid if any of the following are true: - * 1. Type is string and it is not empty - * 2. Type is object and it has properties `title` and `value` and `title` is not empty - */ - if (!ctx) return false; - return typeof ctx === 'string' && !isEmpty(ctx) || Object.hasOwnProperty.call(ctx, 'title') && !isEmpty(ctx.title) && Object.hasOwnProperty.call(ctx, 'value'); -} - -/** - * Add context to the test object so it can - * be displayed in the mochawesome report - * - * @param {Object} test object - * @param {String|Object} context to add - * If context is an object, it must have the shape: - * { - * title: string that is used as context title in the report - * value: the context that is to be added - * } - * - * Usage: - * - * it('should test something', function () { - * someFunctionThatTestsCode(); - * - * addContext(this, 'some context to add'); - * - * addContext(this, { - * title: 'Expected number of something' - * value: 42 - * }); - * - * assert('something'); - * }); - * - */ - -var addContext = function addContext() { - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - // Check args to see if we should bother continuing - if (args.length !== 2 || !isObject(args[0])) { - log(ERRORS.INVALID_ARGS, 'error'); - return; - } - - var ctx = args[1]; - - // Ensure that context meets the requirements - if (!_isValidContext(ctx)) { - log(ERRORS.INVALID_CONTEXT(ctx), 'error'); - return; - } - - /* Context is valid, now get the test object - * If `addContext` is called from inside a `beforeEach` or `afterEach` - * the test object will be `.currentTest`, otherwise just `.test` - */ - var test = args[0].currentTest || args[0].test; - - if (!test) { - log(ERRORS.INVALID_TEST, 'error'); - return; - } - - /* If context is an object, and value is `undefined` - * change it to 'undefined' so it can be displayed - * correctly in the report - */ - if (ctx.title && ctx.value === undefined) { - ctx.value = 'undefined'; - } - - // Test doesn't already have context -> set it - if (!test.context) { - test.context = ctx; - } else if (Array.isArray(test.context)) { - // Test has context and context is an array -> push new context - test.context.push(ctx); - } else { - // Test has context and it is not an array -> make it an array, then push new context - test.context = [test.context]; - test.context.push(ctx); - } -}; - -module.exports = addContext; \ No newline at end of file diff --git a/dist/config.js b/dist/config.js deleted file mode 100644 index 878250a..0000000 --- a/dist/config.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -var _assign = require('babel-runtime/core-js/object/assign'); - -var _assign2 = _interopRequireDefault(_assign); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var marge = require('mochawesome-report-generator'); - -// Grab shared base config from mochawesome-report-generator -var baseConfig = (0, _assign2.default)(marge.getBaseConfig(), { - reportFilename: 'mochawesome', - saveJson: true -}); - -var boolOpts = ['inlineAssets', 'autoOpen', 'enableCharts', 'enableCode', 'overwrite', 'quiet', 'dev']; - -function _getOption(optToGet, options, isBool) { - var envVar = 'MOCHAWESOME_' + optToGet.toUpperCase(); - // Order of precedence - // 1. Config option - // 2. Environment variable - // 3. Base config - if (options && typeof options[optToGet] !== 'undefined') { - return isBool && typeof options[optToGet] === 'string' ? options[optToGet] === 'true' : options[optToGet]; - } - if (typeof process.env[envVar] !== 'undefined') { - return isBool ? process.env[envVar] === 'true' : process.env[envVar]; - } - return baseConfig[optToGet]; -} - -module.exports = function (opts) { - var options = {}; - - // Added for compatibility. enableTestCode option is deprecated as of 2.0.3 - if (Object.hasOwnProperty.call(opts, 'enableTestCode')) { - opts.enableCode = opts.enableTestCode; - delete opts.enableTestCode; - } - - ['reportFilename', 'reportDir', 'reportTitle', 'reportPageTitle', 'inlineAssets', 'autoOpen', 'enableCharts', 'enableCode', 'timestamp', 'overwrite', 'quiet', 'dev'].forEach(function (optName) { - options[optName] = _getOption(optName, opts, boolOpts.indexOf(optName) >= 0); - }); - - return (0, _assign2.default)(baseConfig, options); -}; \ No newline at end of file diff --git a/dist/mochawesome.js b/dist/mochawesome.js deleted file mode 100755 index a152b5c..0000000 --- a/dist/mochawesome.js +++ /dev/null @@ -1,173 +0,0 @@ -'use strict'; - -var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); - -var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var mocha = require('mocha'); -var uuid = require('uuid'); -var stringify = require('json-stringify-safe'); -var conf = require('./config'); -var marge = require('mochawesome-report-generator'); -var utils = require('./utils'); - -// Import the utility functions -var log = utils.log, - getPercentClass = utils.getPercentClass, - cleanTest = utils.cleanTest, - traverseSuites = utils.traverseSuites; - -// Track the total number of tests registered - -var totalTestsRegistered = { total: 0 }; - -/** - * Done function gets called before mocha exits - * - * Creates and saves the report HTML and JSON files - * - * @param {Object} output - * @param {Object} config - * @param {Function} exit - * - * @return {Promise} Resolves with successful report creation - */ - -function done(output, config, failures, exit) { - return marge.create(output, config).then(function (_ref) { - var _ref2 = (0, _slicedToArray3.default)(_ref, 2), - htmlFile = _ref2[0], - jsonFile = _ref2[1]; - - log('Report JSON saved to ' + jsonFile, null, config); - log('Report HTML saved to ' + htmlFile, null, config); - }).catch(function (err) { - log(err, 'error', config); - }).then(function () { - exit && exit(failures); - }); -} - -/** - * Initialize a new reporter. - * - * @param {Runner} runner - * @api public - */ - -function Mochawesome(runner, options) { - var _this = this; - - // Done function will be called before mocha exits - // This is where we will save JSON and generate the HTML report - this.done = function (failures, exit) { - return done(_this.output, _this.config, failures, exit); - }; - - // Reset total tests counter - totalTestsRegistered.total = 0; - - // Create/Save necessary report dirs/files - var reporterOpts = options && options.reporterOptions || {}; - this.config = conf(reporterOpts); - - // Call the Base mocha reporter - mocha.reporters.Base.call(this, runner); - - // Show the Spec Reporter in the console - new mocha.reporters.Spec(runner); // eslint-disable-line - - var allTests = []; - var allPending = []; - var allFailures = []; - var allPasses = []; - var endCalled = false; - - // Add a unique identifier to each test/hook - runner.on('test', function (test) { - return test.uuid = uuid.v4(); - }); - runner.on('hook', function (hook) { - return hook.uuid = uuid.v4(); - }); - // Add test to array of all tests - runner.on('test end', function (test) { - return allTests.push(test); - }); - - // Add pending test to array of pending tests - runner.on('pending', function (test) { - test.uuid = uuid.v4(); - allPending.push(test); - }); - - // Add passing test to array of passing tests - runner.on('pass', function (test) { - return allPasses.push(test); - }); - - // Add failed test to array of failed tests - runner.on('fail', function (test) { - return allFailures.push(test); - }); - - // Process the full suite - runner.on('end', function () { - try { - /* istanbul ignore else */ - if (!endCalled) { - // end gets called more than once for some reason - // so we ensure the suite is processed only once - endCalled = true; - - var allSuites = _this.runner.suite; - - traverseSuites(allSuites, totalTestsRegistered); - - var obj = { - stats: _this.stats, - suites: allSuites, - allTests: allTests.map(cleanTest), - allPending: allPending.map(cleanTest), - allPasses: allPasses.map(cleanTest), - allFailures: allFailures.map(cleanTest), - copyrightYear: new Date().getFullYear() - }; - - obj.stats.testsRegistered = totalTestsRegistered.total; - - var _obj$stats = obj.stats, - passes = _obj$stats.passes, - failures = _obj$stats.failures, - pending = _obj$stats.pending, - tests = _obj$stats.tests, - testsRegistered = _obj$stats.testsRegistered; - - var passPercentage = Math.round(passes / (testsRegistered - pending) * 1000) / 10; - var pendingPercentage = Math.round(pending / testsRegistered * 1000) / 10; - - obj.stats.passPercent = passPercentage; - obj.stats.pendingPercent = pendingPercentage; - obj.stats.other = passes + failures + pending - tests; - obj.stats.hasOther = obj.stats.other > 0; - obj.stats.skipped = testsRegistered - tests; - obj.stats.hasSkipped = obj.stats.skipped > 0; - obj.stats.failures -= obj.stats.other; - obj.stats.passPercentClass = getPercentClass(passPercentage); - obj.stats.pendingPercentClass = getPercentClass(pendingPercentage); - - // Save the final output to be used in the done function - _this.output = stringify(obj, null, 2); - } - } catch (e) { - // required because thrown errors are not handled directly in the - // event emitter pattern and mocha does not have an "on error" - /* istanbul ignore next */ - log('Problem with mochawesome: ' + e.stack, 'error'); - } - }); -} - -module.exports = Mochawesome; \ No newline at end of file diff --git a/dist/utils.js b/dist/utils.js deleted file mode 100644 index bb3bad5..0000000 --- a/dist/utils.js +++ /dev/null @@ -1,251 +0,0 @@ -'use strict'; - -var _typeof2 = require('babel-runtime/helpers/typeof'); - -var _typeof3 = _interopRequireDefault(_typeof2); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var _ = require('lodash'); -var chalk = require('chalk'); -var uuid = require('uuid'); -var mochaUtils = require('mocha/lib/utils'); -var stringify = require('json-stringify-safe'); -var diff = require('diff'); - -/** - * Return a classname based on percentage - * - * @param {String} msg - message to log - * @param {String} level - log level [log, info, warn, error] - * @param {Object} config - configuration object - */ -function log(msg, level, config) { - // Don't log messages in quiet mode - if (config && config.quiet) return; - var logMethod = console[level] || console.log; - var out = msg; - if ((typeof msg === 'undefined' ? 'undefined' : (0, _typeof3.default)(msg)) === 'object') { - out = stringify(msg, null, 2); - } - logMethod('[' + chalk.gray('mochawesome') + '] ' + out + '\n'); -} - -/** - * Return a classname based on percentage - * - * @param {Integer} pct - percentage - * - * @return {String} classname - */ -function getPercentClass(pct) { - if (pct <= 50) { - return 'danger'; - } else if (pct > 50 && pct < 80) { - return 'warning'; - } else { - return 'success'; - } -} - -/** - * Remove all properties from an object except - * those that are in the propsToKeep array. - * - * @param {Object} obj - object to remove props from - * @param {Array} propsToKeep - properties to keep - */ -function removeAllPropsFromObjExcept(obj, propsToKeep) { - _.forOwn(obj, function (val, prop) { - if (propsToKeep.indexOf(prop) === -1) { - delete obj[prop]; - } - }); -} - -/** - * Strip the function definition from `str`, - * and re-indent for pre whitespace. - * - * @param {String} str - code in - * - * @return {String} cleaned code string - */ -function cleanCode(str) { - str = str.replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '').replace(/^function\s*\(.*\)\s*{|\(.*\)\s*=>\s*{?/, '').replace(/\s*\}$/, ''); - - var spaces = str.match(/^\n?( *)/)[1].length; - var tabs = str.match(/^\n?(\t*)/)[1].length; - /* istanbul ignore next */ - var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}', 'gm'); - - str = str.replace(re, ''); - str = str.replace(/^\s+|\s+$/g, ''); - return str; -} - -/** - * Return a plain-object representation of `test` - * free of cyclic properties etc. - * - * @param {Object} test - * - * @return {Object} cleaned test - */ -function cleanTest(test) { - /** - * Check that a / b have the same type. - */ - function sameType(a, b) { - var objToString = Object.prototype.toString; - return objToString.call(a) === objToString.call(b); - } - - /* istanbul ignore next: test.fn exists prior to mocha 2.4.0 */ - var code = test.fn ? test.fn.toString() : test.body; - var err = test.err || {}; - var actual = err.actual, - expected = err.expected, - showDiff = err.showDiff, - stack = err.stack; - - - if (code) { - code = cleanCode(code); - } - - if (stack) { - err.estack = err.stack; - } - - // Create diff for the error - if (showDiff !== false && sameType(actual, expected) && expected !== undefined) { - /* istanbul ignore if */ - if (!(_.isString(actual) && _.isString(expected))) { - err.actual = mochaUtils.stringify(actual); - err.expected = mochaUtils.stringify(expected); - } - err.diff = diff.createPatch('string', err.actual, err.expected).split('\n').splice(4).map(function (line) { - if (line.match(/@@/)) { - return null; - } - if (line.match(/\\ No newline/)) { - return null; - } - return line.replace(/^(-|\+)/, '$1 '); - }).filter(function (line) { - return typeof line !== 'undefined' && line !== null; - }).join('\n'); - } - - var cleaned = { - title: test.title, - fullTitle: _.isFunction(test.fullTitle) ? test.fullTitle() : /* istanbul ignore next */test.title, - timedOut: test.timedOut, - duration: test.duration || 0, - state: test.state, - speed: test.speed, - pass: test.state === 'passed', - fail: test.state === 'failed', - pending: test.pending, - context: stringify(test.context, null, 2), - code: code, - err: err, - isRoot: test.parent && test.parent.root, - uuid: test.uuid || /* istanbul ignore next: default */uuid.v4(), - parentUUID: test.parent && test.parent.uuid, - isHook: test.type === 'hook' - }; - - cleaned.skipped = !cleaned.pass && !cleaned.fail && !cleaned.pending && !cleaned.isHook; - - return cleaned; -} - -/** - * Mutates the suite object to add properties needed to render - * the template and remove unused properties. - * - * @param {Object} suite - * @param {Object} totalTestsRegistered - * @param {Integer} totalTestsRegistered.total - */ -function cleanSuite(suite, totalTestsRegistered) { - suite.uuid = uuid.v4(); - var beforeHooks = _.map([].concat(suite._beforeAll, suite._beforeEach), cleanTest); - var afterHooks = _.map([].concat(suite._afterAll, suite._afterEach), cleanTest); - var cleanTests = _.map(suite.tests, cleanTest); - var passingTests = _.filter(cleanTests, { state: 'passed' }); - var failingTests = _.filter(cleanTests, { state: 'failed' }); - var pendingTests = _.filter(cleanTests, { pending: true }); - var skippedTests = _.filter(cleanTests, { skipped: true }); - var duration = 0; - - _.each(cleanTests, function (test) { - duration += test.duration; - }); - - totalTestsRegistered.total += suite.tests.length; - - suite.beforeHooks = beforeHooks; - suite.afterHooks = afterHooks; - suite.tests = cleanTests; - suite.fullFile = suite.file || ''; - suite.file = suite.file ? suite.file.replace(process.cwd(), '') : ''; - suite.passes = passingTests; - suite.failures = failingTests; - suite.pending = pendingTests; - suite.skipped = skippedTests; - suite.hasBeforeHooks = suite.beforeHooks.length > 0; - suite.hasAfterHooks = suite.afterHooks.length > 0; - suite.hasTests = suite.tests.length > 0; - suite.hasSuites = suite.suites.length > 0; - suite.totalTests = suite.tests.length; - suite.totalPasses = passingTests.length; - suite.totalFailures = failingTests.length; - suite.totalPending = pendingTests.length; - suite.totalSkipped = skippedTests.length; - suite.hasPasses = passingTests.length > 0; - suite.hasFailures = failingTests.length > 0; - suite.hasPending = pendingTests.length > 0; - suite.hasSkipped = suite.skipped.length > 0; - suite.duration = duration; - suite.rootEmpty = suite.root && suite.totalTests === 0; - - removeAllPropsFromObjExcept(suite, ['title', 'fullFile', 'file', 'beforeHooks', 'afterHooks', 'tests', 'suites', 'passes', 'failures', 'pending', 'skipped', 'hasBeforeHooks', 'hasAfterHooks', 'hasTests', 'hasSuites', 'totalTests', 'totalPasses', 'totalFailures', 'totalPending', 'totalSkipped', 'hasPasses', 'hasFailures', 'hasPending', 'hasSkipped', 'root', 'uuid', 'duration', 'rootEmpty', '_timeout']); -} - -/** - * Do a breadth-first search to find - * and format all nested 'suite' objects. - * - * @param {Object} suite - * @param {Object} totalTestsRegistered - * @param {Integer} totalTestsRegistered.total - */ -function traverseSuites(suite, totalTestsRegistered) { - var queue = []; - var next = suite; - while (next) { - if (next.root) { - cleanSuite(next, totalTestsRegistered); - } - if (next.suites.length) { - _.each(next.suites, function (nextSuite, i) { - cleanSuite(nextSuite, totalTestsRegistered); - queue.push(nextSuite); - }); - } - next = queue.shift(); - } -} - -module.exports = { - log: log, - getPercentClass: getPercentClass, - removeAllPropsFromObjExcept: removeAllPropsFromObjExcept, - cleanCode: cleanCode, - cleanTest: cleanTest, - cleanSuite: cleanSuite, - traverseSuites: traverseSuites -}; \ No newline at end of file