Muthu Kumar
6 years ago
37 changed files with 5213 additions and 3927 deletions
@ -1 +1 @@ |
|||||
module.exports = require('./src/runner'); |
module.exports = require('./src/Runner'); |
||||
|
File diff suppressed because it is too large
@ -0,0 +1,129 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
||||
|
|
||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
||||
|
|
||||
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
||||
|
|
||||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
||||
|
|
||||
|
var _require = require('./util'), |
||||
|
arrayOrPush = _require.arrayOrPush; |
||||
|
|
||||
|
var caller = require('./lib/caller'); |
||||
|
|
||||
|
var emitter = require('./lib/emitter'); |
||||
|
|
||||
|
var reporters = require('./reporters'); |
||||
|
|
||||
|
var testrunner = require('./lib/testrunner'); |
||||
|
|
||||
|
var symbols = require('./util/symbols'); |
||||
|
|
||||
|
var Gunner = |
||||
|
/*#__PURE__*/ |
||||
|
function () { |
||||
|
function Gunner(name) { |
||||
|
var _beforeHooks, _afterHooks; |
||||
|
|
||||
|
_classCallCheck(this, Gunner); |
||||
|
|
||||
|
this.name = name; |
||||
|
this.__suite__ = { |
||||
|
tests: [], |
||||
|
beforeHooks: (_beforeHooks = {}, _defineProperty(_beforeHooks, symbols.Start, []), _defineProperty(_beforeHooks, symbols.End, []), _defineProperty(_beforeHooks, '*', []), _beforeHooks), |
||||
|
afterHooks: (_afterHooks = {}, _defineProperty(_afterHooks, symbols.Start, []), _defineProperty(_afterHooks, symbols.End, []), _defineProperty(_afterHooks, '*', []), _afterHooks) |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
_createClass(Gunner, [{ |
||||
|
key: "test", |
||||
|
value: function test(description, _test) { |
||||
|
var existing = this.__suite__.tests.find(function (x) { |
||||
|
return x.description === description; |
||||
|
}); |
||||
|
|
||||
|
if (existing) throw new Error("Test '".concat(description, "' already exists!")); |
||||
|
var unit = { |
||||
|
description: description, |
||||
|
type: 'test', |
||||
|
run: function run(state) { |
||||
|
return caller(_test, state); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
this.__suite__.tests.push(unit); |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
}, { |
||||
|
key: "before", |
||||
|
value: function before(description, _run, label) { |
||||
|
var unit = { |
||||
|
description: description, |
||||
|
label: label, |
||||
|
type: 'hook', |
||||
|
run: function run(state) { |
||||
|
return caller(_run, state); |
||||
|
} |
||||
|
}; |
||||
|
arrayOrPush(this.__suite__.beforeHooks, description, unit); |
||||
|
return this; |
||||
|
} |
||||
|
}, { |
||||
|
key: "after", |
||||
|
value: function after(description, _run2, label) { |
||||
|
var unit = { |
||||
|
description: description, |
||||
|
label: label, |
||||
|
type: 'hook', |
||||
|
run: function run(state) { |
||||
|
return caller(_run2, state); |
||||
|
} |
||||
|
}; |
||||
|
arrayOrPush(this.__suite__.afterHooks, description, unit); |
||||
|
return this; |
||||
|
} |
||||
|
}, { |
||||
|
key: "run", |
||||
|
value: function run() { |
||||
|
var _this = this; |
||||
|
|
||||
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
||||
|
if (options.reporter === true) reporters.default(emitter, options);else if (typeof options.reporter === 'function') options.reporter(emitter, options);else if (reporters[options.reporter]) reporters[options.reporter](emitter, options); |
||||
|
emitter.emit('start'); |
||||
|
return testrunner(this, options).then(function (results) { |
||||
|
var _ref; |
||||
|
|
||||
|
results.count = results.length; |
||||
|
results.success = results.filter(function (r) { |
||||
|
return r.status === 'ok'; |
||||
|
}); |
||||
|
results.failures = results.filter(function (r) { |
||||
|
return r.status === 'notOk'; |
||||
|
}); |
||||
|
results.skipped = results.filter(function (r) { |
||||
|
return r.status === 'skip'; |
||||
|
}); |
||||
|
results.successPercent = Math.floor(results.success.length / results.length * 100); |
||||
|
results.name = _this.name; |
||||
|
if (results.successPercent !== 100 && typeof process !== 'undefined') process.exitCode = 1; |
||||
|
emitter.emit('test end', results); |
||||
|
emitter.emit('end', results); |
||||
|
return options.request ? (_ref = {}, _defineProperty(_ref, options.request, reporters[options.request].convert(results)), _defineProperty(_ref, "default", results), _ref) : results; |
||||
|
}); |
||||
|
} |
||||
|
}]); |
||||
|
|
||||
|
return Gunner; |
||||
|
}(); |
||||
|
|
||||
|
var expect = require('./lib/expect'); |
||||
|
|
||||
|
module.exports = Gunner; |
||||
|
module.exports.expect = expect; |
||||
|
module.exports.expectMany = expect.expectMany; |
||||
|
module.exports.Start = symbols.Start; |
||||
|
module.exports.End = symbols.End; |
||||
|
module.exports.Gunner = module.exports; |
@ -1,548 +1,40 @@ |
|||||
"use strict"; |
"use strict"; |
||||
|
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; |
|
||||
|
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
|
||||
|
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
||||
|
|
||||
(function (f) { |
var reporters = require('./reporters'); |
||||
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") { |
|
||||
module.exports = f(); |
|
||||
} else if (typeof define === "function" && define.amd) { |
|
||||
define([], f); |
|
||||
} else { |
|
||||
var g;if (typeof window !== "undefined") { |
|
||||
g = window; |
|
||||
} else if (typeof global !== "undefined") { |
|
||||
g = global; |
|
||||
} else if (typeof self !== "undefined") { |
|
||||
g = self; |
|
||||
} else { |
|
||||
g = this; |
|
||||
}g.Runner = f(); |
|
||||
} |
|
||||
})(function () { |
|
||||
var define, module, exports;return 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) { |
|
||||
module.exports = require('./src/runner'); |
|
||||
}, { "./src/runner": 9 }], 2: [function (require, module, exports) { |
|
||||
//copyright Ryan Day 2010 <http://ryanday.org>, Joscha Feth 2013 <http://www.feth.com> [MIT Licensed]
|
|
||||
|
|
||||
var element_start_char = "a-zA-Z_\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FFF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD"; |
|
||||
var element_non_start_char = "-.0-9\xB7\u0300-\u036F\u203F\u2040"; |
|
||||
var element_replace = new RegExp("^([^" + element_start_char + "])|^((x|X)(m|M)(l|L))|([^" + element_start_char + element_non_start_char + "])", "g"); |
|
||||
var not_safe_in_xml = /[^\x09\x0A\x0D\x20-\xFF\x85\xA0-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm; |
|
||||
|
|
||||
var process_to_xml = function process_to_xml(node_data, options) { |
|
||||
|
|
||||
var makeNode = function makeNode(name, content, attributes, level, hasSubNodes) { |
|
||||
|
|
||||
var indent_value = options.indent !== undefined ? options.indent : "\t"; |
|
||||
var indent = options.prettyPrint ? '\n' + new Array(level).join(indent_value) : ''; |
|
||||
if (options.removeIllegalNameCharacters) { |
|
||||
name = name.replace(element_replace, '_'); |
|
||||
} |
|
||||
|
|
||||
var node = [indent, '<', name, attributes || '']; |
|
||||
if (content && content.length > 0 || options.html) { |
|
||||
node.push('>'); |
|
||||
node.push(content); |
|
||||
hasSubNodes && node.push(indent); |
|
||||
node.push('</'); |
|
||||
node.push(name); |
|
||||
node.push('>'); |
|
||||
} else { |
|
||||
node.push('/>'); |
|
||||
} |
|
||||
return node.join(''); |
|
||||
}; |
|
||||
|
|
||||
return function fn(node_data, node_descriptor, level) { |
|
||||
var type = typeof node_data === "undefined" ? "undefined" : _typeof(node_data); |
|
||||
if (Array.isArray ? Array.isArray(node_data) : node_data instanceof Array) { |
|
||||
type = 'array'; |
|
||||
} else if (node_data instanceof Date) { |
|
||||
type = 'date'; |
|
||||
} |
|
||||
|
|
||||
switch (type) { |
|
||||
//if value is an array create child nodes from values
|
|
||||
case 'array': |
|
||||
var ret = []; |
|
||||
node_data.map(function (v) { |
|
||||
ret.push(fn(v, 1, level + 1)); |
|
||||
//entries that are values of an array are the only ones that can be special node descriptors
|
|
||||
}); |
|
||||
options.prettyPrint && ret.push('\n'); |
|
||||
return ret.join(''); |
|
||||
break; |
|
||||
|
|
||||
case 'date': |
|
||||
// cast dates to ISO 8601 date (soap likes it)
|
|
||||
return node_data.toJSON ? node_data.toJSON() : node_data + ''; |
|
||||
break; |
|
||||
|
|
||||
case 'object': |
|
||||
if (node_descriptor == 1 && node_data.name) { |
|
||||
var content = [], |
|
||||
attributes = []; |
|
||||
|
|
||||
if (node_data.attrs) { |
|
||||
if (_typeof(node_data.attrs) != 'object') { |
|
||||
// attrs is a string, etc. - just use it as an attribute
|
|
||||
attributes.push(' '); |
|
||||
attributes.push(node_data.attrs); |
|
||||
} else { |
|
||||
for (var key in node_data.attrs) { |
|
||||
var value = node_data.attrs[key]; |
|
||||
attributes.push(' '); |
|
||||
attributes.push(key); |
|
||||
attributes.push('="'); |
|
||||
attributes.push(options.escape ? esc(value) : value); |
|
||||
attributes.push('"'); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
//later attributes can be added here
|
|
||||
if (typeof node_data.value != 'undefined') { |
|
||||
var c = '' + node_data.value; |
|
||||
content.push(options.escape && !node_data.noescape ? esc(c) : c); |
|
||||
} else if (typeof node_data.text != 'undefined') { |
|
||||
var c = '' + node_data.text; |
|
||||
content.push(options.escape && !node_data.noescape ? esc(c) : c); |
|
||||
} |
|
||||
|
|
||||
if (node_data.children) { |
|
||||
content.push(fn(node_data.children, 0, level + 1)); |
|
||||
} |
|
||||
|
|
||||
return makeNode(node_data.name, content.join(''), attributes.join(''), level, !!node_data.children); |
|
||||
} else { |
|
||||
var nodes = []; |
|
||||
for (var name in node_data) { |
|
||||
nodes.push(makeNode(name, fn(node_data[name], 0, level + 1), null, level + 1)); |
|
||||
} |
|
||||
options.prettyPrint && nodes.length > 0 && nodes.push('\n'); |
|
||||
return nodes.join(''); |
|
||||
} |
|
||||
break; |
|
||||
|
|
||||
case 'function': |
|
||||
return node_data(); |
|
||||
break; |
|
||||
|
|
||||
default: |
|
||||
return options.escape ? esc(node_data) : '' + node_data; |
|
||||
} |
|
||||
}(node_data, 0, 0); |
|
||||
}; |
|
||||
|
|
||||
var xml_header = function xml_header(standalone) { |
|
||||
var ret = ['<?xml version="1.0" encoding="utf-8"']; |
|
||||
|
|
||||
if (standalone) { |
|
||||
ret.push(' standalone="yes"'); |
|
||||
} |
|
||||
|
|
||||
ret.push('?>'); |
|
||||
|
|
||||
return ret.join(''); |
|
||||
}; |
|
||||
|
|
||||
module.exports = function (obj, options) { |
|
||||
|
|
||||
var Buffer = this.Buffer || function Buffer() {}; |
|
||||
|
|
||||
if (typeof obj == 'string' || obj instanceof Buffer) { |
|
||||
try { |
|
||||
obj = JSON.parse(obj.toString()); |
|
||||
} catch (e) { |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var xmlheader = ''; |
|
||||
var docType = ''; |
|
||||
if (options) { |
|
||||
if ((typeof options === "undefined" ? "undefined" : _typeof(options)) == 'object') { |
|
||||
// our config is an object
|
|
||||
|
|
||||
if (options.xmlHeader) { |
|
||||
// the user wants an xml header
|
|
||||
xmlheader = xml_header(!!options.xmlHeader.standalone); |
|
||||
} |
|
||||
|
|
||||
if (typeof options.docType != 'undefined') { |
|
||||
docType = '<!DOCTYPE ' + options.docType + '>'; |
|
||||
} |
|
||||
} else { |
|
||||
// our config is a boolean value, so just add xml header
|
|
||||
xmlheader = xml_header(); |
|
||||
} |
|
||||
} |
|
||||
options = options || {}; |
|
||||
|
|
||||
var ret = [xmlheader, options.prettyPrint && docType ? '\n' : '', docType, process_to_xml(obj, options)]; |
|
||||
|
|
||||
return ret.join(''); |
|
||||
}; |
|
||||
|
|
||||
module.exports.json_to_xml = module.exports.obj_to_xml = module.exports; |
|
||||
|
|
||||
module.exports.escape = esc; |
|
||||
|
|
||||
function esc(str) { |
|
||||
return ('' + str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, ''').replace(/"/g, '"').replace(not_safe_in_xml, ''); |
|
||||
} |
|
||||
|
|
||||
module.exports.cdata = cdata; |
|
||||
|
|
||||
function cdata(str) { |
|
||||
if (str) return "<![CDATA[" + str.replace(/]]>/g, '') + ']]>'; |
|
||||
return "<![CDATA[]]>"; |
|
||||
}; |
|
||||
}, {}], 3: [function (require, module, exports) { |
|
||||
exports.endianness = function () { |
|
||||
return 'LE'; |
|
||||
}; |
|
||||
|
|
||||
exports.hostname = function () { |
|
||||
if (typeof location !== 'undefined') { |
|
||||
return location.hostname; |
|
||||
} else return ''; |
|
||||
}; |
|
||||
|
|
||||
exports.loadavg = function () { |
|
||||
return []; |
|
||||
}; |
|
||||
|
|
||||
exports.uptime = function () { |
|
||||
return 0; |
|
||||
}; |
|
||||
|
|
||||
exports.freemem = function () { |
|
||||
return Number.MAX_VALUE; |
|
||||
}; |
|
||||
|
|
||||
exports.totalmem = function () { |
|
||||
return Number.MAX_VALUE; |
|
||||
}; |
|
||||
|
|
||||
exports.cpus = function () { |
|
||||
return []; |
|
||||
}; |
|
||||
|
|
||||
exports.type = function () { |
|
||||
return 'Browser'; |
|
||||
}; |
|
||||
|
|
||||
exports.release = function () { |
|
||||
if (typeof navigator !== 'undefined') { |
|
||||
return navigator.appVersion; |
|
||||
} |
|
||||
return ''; |
|
||||
}; |
|
||||
|
|
||||
exports.networkInterfaces = exports.getNetworkInterfaces = function () { |
|
||||
return {}; |
|
||||
}; |
|
||||
|
|
||||
exports.arch = function () { |
|
||||
return 'javascript'; |
|
||||
}; |
|
||||
|
|
||||
exports.platform = function () { |
|
||||
return 'browser'; |
|
||||
}; |
|
||||
|
|
||||
exports.tmpdir = exports.tmpDir = function () { |
|
||||
return '/tmp'; |
|
||||
}; |
|
||||
|
|
||||
exports.EOL = '\n'; |
|
||||
|
|
||||
exports.homedir = function () { |
|
||||
return '/'; |
|
||||
}; |
|
||||
}, {}], 4: [function (require, module, exports) { |
|
||||
var statusMap = { |
|
||||
|
|
||||
'ok': ['ok', '✅'], |
|
||||
'notOk': ['notOk', '❌'], |
|
||||
'skip': ['skip', '⚠️'] |
|
||||
|
|
||||
}; |
|
||||
|
|
||||
var convert = function convert(x) { |
|
||||
return x; |
|
||||
}; |
|
||||
|
|
||||
var Default = function Default(runner, options) { |
|
||||
|
|
||||
runner.on('start', function () { |
|
||||
return console.log('Started tests'); |
|
||||
}); |
|
||||
|
|
||||
runner.on('test end', function (results) { |
|
||||
|
|
||||
results.forEach(function (x) { |
var isBrowser = new Function("try { return this === window } catch (e) { return false }"); |
||||
|
|
||||
var s = statusMap[x.status]; |
var Runner = function Runner(instances) { |
||||
|
|
||||
console.log('>', s[0], s[1], x.description); |
|
||||
options.trace && x.reason && console.log('\n---\n\n', x.reason, '\n\n---\n'); |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
runner.on('end', function (results) { |
|
||||
|
|
||||
console.log(results.success.length, 'tests of', results.length, 'passed'); |
|
||||
console.log('Success ratio:', results.successPercent, '%'); |
|
||||
}); |
|
||||
}; |
|
||||
|
|
||||
module.exports = Default; |
|
||||
module.exports.convert = convert; |
|
||||
}, {}], 5: [function (require, module, exports) { |
|
||||
var def = require('./default'); |
|
||||
var tap = require('./tap'); |
|
||||
var xunit = require('./xunit'); |
|
||||
var min = require('./min'); |
|
||||
|
|
||||
module.exports = { |
|
||||
default: def, |
|
||||
tap: tap, |
|
||||
xunit: xunit, |
|
||||
min: min |
|
||||
}; |
|
||||
}, { "./default": 4, "./min": 6, "./tap": 7, "./xunit": 8 }], 6: [function (require, module, exports) { |
|
||||
var _require = require('../util/constants'), |
|
||||
eventMap = _require.eventMap, |
|
||||
eventVerbs = _require.eventVerbs; |
|
||||
|
|
||||
var _require2 = require('../util/nodeutils'), |
|
||||
clear = _require2.clear; |
|
||||
|
|
||||
var convert = function convert(x) { |
|
||||
return x; |
|
||||
}; |
|
||||
|
|
||||
var count = { |
|
||||
pass: 0, |
|
||||
fail: 0, |
|
||||
skip: 0, |
|
||||
collapse: function collapse() { |
|
||||
return this.pass + this.fail + this.skip; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var doneHandler = function doneHandler(event) { |
|
||||
|
|
||||
clear(); |
|
||||
var mapEvent = eventMap[event.status]; |
|
||||
count[mapEvent]++; |
|
||||
console.log(count[mapEvent] + " tests " + eventVerbs[mapEvent][2] + (" (total: " + count.collapse() + ")")); |
|
||||
}; |
|
||||
|
|
||||
var Min = function Min(runner) { |
|
||||
|
|
||||
runner.on('start', function () { |
|
||||
return console.log('Started tests'); |
|
||||
}); |
|
||||
|
|
||||
runner.on('pass', doneHandler); |
|
||||
runner.on('fail', doneHandler); |
|
||||
runner.on('skip', doneHandler); |
|
||||
|
|
||||
runner.on('end', function (results) { |
|
||||
|
|
||||
clear(); |
|
||||
console.log("Test suite " + results.name + " has done running."); |
|
||||
console.log('Success ratio:', results.successPercent, '%'); |
|
||||
}); |
|
||||
}; |
|
||||
|
|
||||
module.exports = Min; |
|
||||
module.exports.convert = convert; |
|
||||
}, { "../util/constants": 10, "../util/nodeutils": 11 }], 7: [function (require, module, exports) { |
|
||||
var statusMap = { |
|
||||
|
|
||||
'ok': 'ok', |
|
||||
'notOk': 'not ok', |
|
||||
'skip': 'skip' |
|
||||
|
|
||||
}; |
|
||||
|
|
||||
var convert = function convert(results, options) { |
|
||||
return "\nTAP version 13\n" + (results.length ? '1' : 0) + ".." + results.length + "\n" + results.map(function (r, i) { |
|
||||
|
|
||||
var status = statusMap[r.status]; |
|
||||
var message = options.trace && r.reason && (r.reason.stack ? r.reason.stack : r.reason) || ''; |
|
||||
return status + " " + (i + 1) + " - " + r.description + (message && '\n ---\n message: |\n ' + message + '\n ---\n'); |
|
||||
}).join('\n') + "\n"; |
|
||||
}; |
|
||||
|
|
||||
var TAP = function TAP(runner, options) { |
|
||||
|
|
||||
runner.on('end', function (results) { |
|
||||
return console.log(convert(results, options)); |
|
||||
}); |
|
||||
}; |
|
||||
|
|
||||
module.exports = TAP; |
|
||||
module.exports.convert = convert; |
|
||||
}, {}], 8: [function (require, module, exports) { |
|
||||
var toXML = require('jsontoxml'); |
|
||||
|
|
||||
var _require3 = require('../util/nodeutils'), |
|
||||
clear = _require3.clear; |
|
||||
|
|
||||
var toJSON = function toJSON(resultsArray) { |
|
||||
|
|
||||
return { |
|
||||
testsuites: resultsArray.map(function (results) { |
|
||||
var name = results.name, |
|
||||
count = results.count, |
|
||||
success = results.success, |
|
||||
failures = results.failures, |
|
||||
skipped = results.skipped; |
|
||||
|
|
||||
|
|
||||
return { |
|
||||
name: 'testsuite', |
|
||||
attrs: { |
|
||||
name: name, |
|
||||
tests: count, |
|
||||
success: success.length, |
|
||||
failures: failures.length, |
|
||||
skipped: skipped.length, |
|
||||
timestamp: new Date().toUTCString(), |
|
||||
time: results.duration / 1000 || 0 |
|
||||
}, |
|
||||
children: results.reduce(function (acc, r) { |
|
||||
var content = r.status !== 'ok' && (r.status === 'skip' ? 'skipped' : { |
|
||||
name: 'failure', |
|
||||
text: r.reason ? r.reason && r.reason.stack : '' |
|
||||
}); |
|
||||
acc.push(_extends({ |
|
||||
name: 'testcase', |
|
||||
attrs: { |
|
||||
name: r.description, |
|
||||
time: r.duration / 1000 || 0 |
|
||||
} |
|
||||
}, (typeof content === "undefined" ? "undefined" : _typeof(content)) === 'object' && { text: content && content.stack }, (typeof content === "undefined" ? "undefined" : _typeof(content)) === 'object' && { children: [content] })); |
|
||||
return acc; |
|
||||
}, []) |
|
||||
}; |
|
||||
}) |
|
||||
}; |
|
||||
}; |
|
||||
|
|
||||
var convert = function convert(results) { |
|
||||
return toXML(toJSON(results), { xmlHeader: { standalone: true } }); |
|
||||
}; |
|
||||
|
|
||||
var xunit = function xunit(runner) { |
|
||||
return runner.on("end", function (results) { |
|
||||
return clear(), console.log(convert([results])); |
|
||||
}); |
|
||||
}; |
|
||||
|
|
||||
module.exports = xunit; |
|
||||
module.exports.convert = convert; |
|
||||
}, { "../util/nodeutils": 11, "jsontoxml": 2 }], 9: [function (require, module, exports) { |
|
||||
var reporters = require('../reporters'); |
|
||||
|
|
||||
var isBrowser = new Function("try { return this === window } catch (e) { return false }"); |
|
||||
|
|
||||
var runner = function runner(instances) { |
|
||||
return function () { |
return function () { |
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
||||
|
|
||||
|
|
||||
if (isBrowser()) throw new Error('Runner is not adapted for browsers yet.' + ' Use regular Gunner'); |
if (isBrowser()) throw new Error('Runner is not adapted for browsers yet.' + ' Use regular Gunner'); |
||||
|
|
||||
instances = Array.isArray(instances) ? instances : [instances]; |
instances = Array.isArray(instances) ? instances : [instances]; |
||||
|
|
||||
if (!instances.length) throw new Error("No instances were passed to Gunner Runner"); |
if (!instances.length) throw new Error("No instances were passed to Gunner Runner"); |
||||
|
|
||||
var type = instances[0].__proto__.constructor.name; |
var type = instances[0].__proto__.constructor.name; |
||||
|
if (type !== "Gunner" && type !== "Strategy") throw new Error("Runner ".concat(type, " is not one of Gunner or Strategy")); |
||||
if (type !== "Gunner" && type !== "Strategy") throw new Error("Runner " + type + " is not one of Gunner or Strategy"); |
|
||||
|
|
||||
var RunInstances = instances.filter(function (i) { |
var RunInstances = instances.filter(function (i) { |
||||
return i.__proto__.constructor.name === type; |
return i.__proto__.constructor.name === type; |
||||
}); |
}); |
||||
|
if (RunInstances.length !== instances.length) throw new Error("Not all instances were of type ".concat(type)); |
||||
if (RunInstances.length !== instances.length) throw new Error("Not all instances were of type " + type); |
var perf = { |
||||
|
start: new Date() |
||||
var perf = { start: new Date() }; |
}; |
||||
|
|
||||
return Promise.all(RunInstances.map(function (instance) { |
return Promise.all(RunInstances.map(function (instance) { |
||||
return instance.run({ reporter: 'min' }); |
return instance.run({ |
||||
|
reporter: 'min' |
||||
|
}); |
||||
})).then(function (results) { |
})).then(function (results) { |
||||
perf.end = new Date(); |
perf.end = new Date(); |
||||
results.start = perf.start.toUTCString(); |
results.start = perf.start.toUTCString(); |
||||
results.end = perf.end.toUTCString(); |
results.end = perf.end.toUTCString(); |
||||
results.duration = perf.end - perf.start; |
results.duration = perf.end - perf.start; |
||||
|
|
||||
return options.request ? _defineProperty({ |
return options.request ? _defineProperty({ |
||||
default: results |
default: results |
||||
}, options.request, reporters[options.request].convert(results)) : results; |
}, options.request, reporters[options.request].convert(results)) : results; |
||||
}); |
}); |
||||
}; |
}; |
||||
}; |
}; |
||||
|
|
||||
module.exports = runner; |
|
||||
}, { "../reporters": 5 }], 10: [function (require, module, exports) { |
|
||||
var _require4 = require('os'), |
|
||||
EOL = _require4.EOL; |
|
||||
|
|
||||
module.exports = { |
|
||||
EOL: EOL, |
|
||||
eventMap: { |
|
||||
'ok': 'pass', |
|
||||
'notOk': 'fail', |
|
||||
'skip': 'skip' |
|
||||
}, |
|
||||
eventVerbs: { |
|
||||
pass: ['pass', 'passing', 'passed'], |
|
||||
fail: ['fail', 'failing', 'failed'], |
|
||||
skip: ['skip', 'skipping', 'skipped'] |
|
||||
} |
|
||||
}; |
|
||||
}, { "os": 3 }], 11: [function (require, module, exports) { |
|
||||
(function (global) { |
|
||||
module.exports = { |
|
||||
|
|
||||
clear: function clear() { |
|
||||
|
|
||||
if (typeof global === 'undefined' || typeof global.process === 'undefined' || typeof global.process.stdout === 'undefined') return; |
module.exports = Runner; |
||||
|
|
||||
var process = global.process; |
|
||||
|
|
||||
// clear screen
|
|
||||
process.stdout.write("\x1B[2J"); |
|
||||
// set cursor position to top
|
|
||||
process.stdout.write("\x1B[1;1H"); |
|
||||
} |
|
||||
|
|
||||
}; |
|
||||
}).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); |
|
||||
}, {}] }, {}, [1])(1); |
|
||||
}); |
|
File diff suppressed because it is too large
@ -0,0 +1,44 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } |
||||
|
|
||||
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } |
||||
|
|
||||
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } |
||||
|
|
||||
|
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } |
||||
|
|
||||
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } |
||||
|
|
||||
|
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } |
||||
|
|
||||
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } |
||||
|
|
||||
|
var _require = require('../util'), |
||||
|
isPromise = _require.isPromise; |
||||
|
|
||||
|
var createRejectionStatement = function createRejectionStatement(statement) { |
||||
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
||||
|
args[_key - 1] = arguments[_key]; |
||||
|
} |
||||
|
|
||||
|
return Promise.reject(statement ? statement.apply(void 0, args) : ''); |
||||
|
}; |
||||
|
|
||||
|
var assertPromise = function assertPromise(bool, statementTuple) { |
||||
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
||||
|
|
||||
|
var _statementTuple = _toArray(statementTuple), |
||||
|
statement = _statementTuple[0], |
||||
|
args = _statementTuple.slice(1); |
||||
|
|
||||
|
statement = options.skipStatement ? function () { |
||||
|
return options.skipStatement; |
||||
|
} : statement; |
||||
|
if (isPromise(bool)) return bool.catch(function () { |
||||
|
return createRejectionStatement.apply(void 0, [statement].concat(_toConsumableArray(args))); |
||||
|
}); |
||||
|
return bool ? Promise.resolve() : createRejectionStatement.apply(void 0, [statement].concat(_toConsumableArray(args))); |
||||
|
}; |
||||
|
|
||||
|
module.exports = assertPromise; |
@ -0,0 +1,303 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _templateObject17() { |
||||
|
var data = _taggedTemplateLiteral(["'", "' is greater than ", ""]); |
||||
|
|
||||
|
_templateObject17 = function _templateObject17() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject16() { |
||||
|
var data = _taggedTemplateLiteral(["'", "' is less than ", ""]); |
||||
|
|
||||
|
_templateObject16 = function _templateObject16() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject15() { |
||||
|
var data = _taggedTemplateLiteral(["'", "' is not less than ", ""]); |
||||
|
|
||||
|
_templateObject15 = function _templateObject15() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject14() { |
||||
|
var data = _taggedTemplateLiteral(["'", "' is not greater than ", ""]); |
||||
|
|
||||
|
_templateObject14 = function _templateObject14() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject13() { |
||||
|
var data = _taggedTemplateLiteral(["'", "' is not of type '", "'"]); |
||||
|
|
||||
|
_templateObject13 = function _templateObject13() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject12() { |
||||
|
var data = _taggedTemplateLiteral(["'", "' does not resolve to '", "'"]); |
||||
|
|
||||
|
_templateObject12 = function _templateObject12() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject11() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not a promise"]); |
||||
|
|
||||
|
_templateObject11 = function _templateObject11() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject10() { |
||||
|
var data = _taggedTemplateLiteral(["", " does not exist in ", ""]); |
||||
|
|
||||
|
_templateObject10 = function _templateObject10() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject9() { |
||||
|
var data = _taggedTemplateLiteral(["", " does not have property '", "'"]); |
||||
|
|
||||
|
_templateObject9 = function _templateObject9() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject8() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not false"]); |
||||
|
|
||||
|
_templateObject8 = function _templateObject8() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject7() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not true"]); |
||||
|
|
||||
|
_templateObject7 = function _templateObject7() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject6() { |
||||
|
var data = _taggedTemplateLiteral(["", " does not contain ", ""]); |
||||
|
|
||||
|
_templateObject6 = function _templateObject6() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject5() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not deeply equal to ", ""]); |
||||
|
|
||||
|
_templateObject5 = function _templateObject5() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject4() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not equal to ", ""]); |
||||
|
|
||||
|
_templateObject4 = function _templateObject4() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject3() { |
||||
|
var data = _taggedTemplateLiteral(["", " doesn't have length ", ""]); |
||||
|
|
||||
|
_templateObject3 = function _templateObject3() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _templateObject2() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not an object"]); |
||||
|
|
||||
|
_templateObject2 = function _templateObject2() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
||||
|
|
||||
|
function _templateObject() { |
||||
|
var data = _taggedTemplateLiteral(["", " is not an array"]); |
||||
|
|
||||
|
_templateObject = function _templateObject() { |
||||
|
return data; |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } |
||||
|
|
||||
|
var isEq = require('@codefeathers/iseq'); |
||||
|
|
||||
|
var U = require('../util'); |
||||
|
|
||||
|
var _ = U.taggedStringify; |
||||
|
module.exports.done = [function () { |
||||
|
return true; |
||||
|
}, function () { |
||||
|
return null; |
||||
|
}]; |
||||
|
module.exports.fail = [function () { |
||||
|
return false; |
||||
|
}, function (_, rejection) { |
||||
|
return rejection; |
||||
|
}]; |
||||
|
module.exports.exists = [function (val) { |
||||
|
return typeof val !== 'undefined'; |
||||
|
}, function () { |
||||
|
return "Value is undefined"; |
||||
|
}]; |
||||
|
module.exports.isArray = [function (val) { |
||||
|
return Array.isArray(val); |
||||
|
}, function (val) { |
||||
|
return _(_templateObject(), val); |
||||
|
}]; |
||||
|
module.exports.isObject = [function (val) { |
||||
|
return _typeof(val) === 'object' && val !== null; |
||||
|
}, function (val) { |
||||
|
return _(_templateObject2(), val); |
||||
|
}]; |
||||
|
module.exports.hasLength = [function (val, l) { |
||||
|
return val.length === l; |
||||
|
}, function (val, l) { |
||||
|
return _(_templateObject3(), val, l); |
||||
|
}]; |
||||
|
module.exports.equals = [function (val, thing) { |
||||
|
return val === thing; |
||||
|
}, function (val, thing) { |
||||
|
return _(_templateObject4(), val, thing); |
||||
|
}]; |
||||
|
module.exports.deepEquals = [function (val, match) { |
||||
|
return isEq(val, match); |
||||
|
}, function (val, match) { |
||||
|
return _(_templateObject5(), val, match); |
||||
|
}]; |
||||
|
module.exports.contains = [function (val, match) { |
||||
|
return isEq(val, match, Object.keys(match)); |
||||
|
}, function (val, match) { |
||||
|
return _(_templateObject6(), val, match); |
||||
|
}]; |
||||
|
module.exports.isTrue = [function (val) { |
||||
|
return val === true; |
||||
|
}, function (val) { |
||||
|
return _(_templateObject7(), val); |
||||
|
}]; |
||||
|
module.exports.isFalse = [function (val) { |
||||
|
return val === false; |
||||
|
}, function (val) { |
||||
|
return _(_templateObject8(), val); |
||||
|
}]; |
||||
|
module.exports.hasProp = [function (val, prop) { |
||||
|
return val.hasOwnProperty(prop); |
||||
|
}, function (val, prop) { |
||||
|
return _(_templateObject9(), val, prop); |
||||
|
}]; |
||||
|
module.exports.hasPair = [function (val) { |
||||
|
for (var _len = arguments.length, pair = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
||||
|
pair[_key - 1] = arguments[_key]; |
||||
|
} |
||||
|
|
||||
|
return isEq(val[pair[0]], pair[1]); |
||||
|
}, function (val) { |
||||
|
for (var _len2 = arguments.length, pair = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
||||
|
pair[_key2 - 1] = arguments[_key2]; |
||||
|
} |
||||
|
|
||||
|
return _(_templateObject10(), pair, val); |
||||
|
}]; |
||||
|
module.exports.isPromise = [function (val) { |
||||
|
return U.isPromise(val); |
||||
|
}, function (val) { |
||||
|
return _(_templateObject11(), val); |
||||
|
}, { |
||||
|
shouldCatch: true |
||||
|
}]; |
||||
|
module.exports.resolvesTo = [function (val, thing) { |
||||
|
return U.isPromise(val) ? val.then(function (x) { |
||||
|
return x === thing ? Promise.resolve() : Promise.reject(); |
||||
|
}) : Promise.reject("".concat(val, " was not a Promise")); |
||||
|
}, function (val, thing) { |
||||
|
return _(_templateObject12(), val, thing); |
||||
|
}]; |
||||
|
module.exports.isType = [function (val, type) { |
||||
|
return type === 'nil' && (val === 'null' || val === 'undefined') || _typeof(val) === type || Array.isArray(val) && type === "array" && val === null && type !== 'object'; |
||||
|
}, function (val, type) { |
||||
|
return _(_templateObject13(), val, type); |
||||
|
}]; |
||||
|
module.exports.greaterThan = [function (val, compare) { |
||||
|
return val > compare; |
||||
|
}, function (val, compare) { |
||||
|
return _(_templateObject14(), val, compare); |
||||
|
}]; |
||||
|
module.exports.lessThan = [function (val, compare) { |
||||
|
return val < compare; |
||||
|
}, function (val, compare) { |
||||
|
return _(_templateObject15(), val, compare); |
||||
|
}]; |
||||
|
module.exports.gte = [function (val, compare) { |
||||
|
return val >= compare; |
||||
|
}, function (val, compare) { |
||||
|
return _(_templateObject16(), val, compare); |
||||
|
}]; |
||||
|
module.exports.lte = [function (val, compare) { |
||||
|
return val <= compare; |
||||
|
}, function (val, compare) { |
||||
|
return _(_templateObject17(), val, compare); |
||||
|
}]; |
||||
|
/* Convenience aliases */ |
||||
|
|
||||
|
module.exports.success = module.exports.done; |
||||
|
module.exports.succeed = module.exports.done; |
||||
|
module.exports.failure = module.exports.fail; |
||||
|
module.exports.equal = module.exports.equals; |
||||
|
module.exports.deepEqual = module.exports.deepEquals; |
||||
|
module.exports.match = module.exports.deepEquals; |
||||
|
module.exports.greaterThanOrEqualTo = module.exports.gte; |
||||
|
module.exports.lessThanOrEqualTo = module.exports.lte; |
@ -0,0 +1,38 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
// Only imported for JSDoc
|
||||
|
|
||||
|
/* eslint-disable-next-line */ |
||||
|
var Gunner = require('../Gunner'); |
||||
|
|
||||
|
var symbols = require('../util/symbols'); |
||||
|
|
||||
|
var wrap = function wrap(type) { |
||||
|
return function (unit) { |
||||
|
return { |
||||
|
type: type, |
||||
|
unit: unit |
||||
|
}; |
||||
|
}; |
||||
|
}; |
||||
|
/** |
||||
|
* runs the test suite |
||||
|
* @param {Gunner} instance |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
var buildTestTree = function buildTestTree(instance) { |
||||
|
var testQueue = []; |
||||
|
Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks[symbols.Start].map(wrap('@start'))); |
||||
|
testQueue.push.apply(instance.__suite__.afterHooks[symbols.Start].map(wrap('@start'))); |
||||
|
|
||||
|
instance.__suite__.tests.forEach(function (test) { |
||||
|
return Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks['*'].map(wrap('@every'))), Array.prototype.push.apply(testQueue, (instance.__suite__.beforeHooks[test.description] || []).map(wrap('@this'))), testQueue.push(wrap('@test')(test)), Array.prototype.push.apply(testQueue, (instance.__suite__.afterHooks[test.description] || []).map(wrap('@afterTest'))), Array.prototype.push.apply(testQueue, instance.__suite__.afterHooks['*'].map(wrap('@afterEvery'))); |
||||
|
}); |
||||
|
|
||||
|
Array.prototype.push.apply(testQueue, instance.__suite__.beforeHooks[symbols.End].map(wrap('@beforeend'))); |
||||
|
Array.prototype.push.apply(testQueue, instance.__suite__.afterHooks[symbols.End].map(wrap('@end'))); |
||||
|
return testQueue; |
||||
|
}; |
||||
|
|
||||
|
module.exports = buildTestTree; |
@ -0,0 +1,59 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } |
||||
|
|
||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
||||
|
|
||||
|
var _require = require('../util'), |
||||
|
isPromise = _require.isPromise; |
||||
|
|
||||
|
var caller = function caller(test, state) { |
||||
|
var perf = { |
||||
|
start: 0, |
||||
|
end: 0 |
||||
|
}; |
||||
|
var value, error, errored; |
||||
|
|
||||
|
try { |
||||
|
perf.start = new Date(); |
||||
|
value = test(state); |
||||
|
perf.end = new Date(); |
||||
|
} catch (e) { |
||||
|
perf.end = new Date(); |
||||
|
errored = true; |
||||
|
error = e; |
||||
|
} |
||||
|
|
||||
|
var promise = isPromise(value); |
||||
|
|
||||
|
if (promise) { |
||||
|
return value.then(function (res) { |
||||
|
return { |
||||
|
duration: new Date() - perf.start, |
||||
|
status: 'ok', |
||||
|
resolve: res, |
||||
|
promise: true |
||||
|
}; |
||||
|
}).catch(function (rej) { |
||||
|
return { |
||||
|
duration: new Date() - perf.start, |
||||
|
status: 'notOk', |
||||
|
rejection: rej, |
||||
|
promise: true |
||||
|
}; |
||||
|
}); |
||||
|
} else { |
||||
|
return Promise.resolve(_objectSpread({ |
||||
|
duration: perf.end - perf.start, |
||||
|
status: errored ? 'notOk' : 'ok' |
||||
|
}, !errored && { |
||||
|
value: value |
||||
|
}, errored && { |
||||
|
error: error |
||||
|
}, { |
||||
|
promise: false |
||||
|
})); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
module.exports = caller; |
@ -0,0 +1,33 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
||||
|
|
||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
||||
|
|
||||
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } |
||||
|
|
||||
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } |
||||
|
|
||||
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } |
||||
|
|
||||
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
||||
|
|
||||
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
||||
|
|
||||
|
var EventEmitter = require('events'); |
||||
|
|
||||
|
var GunnerEmitter = |
||||
|
/*#__PURE__*/ |
||||
|
function (_EventEmitter) { |
||||
|
_inherits(GunnerEmitter, _EventEmitter); |
||||
|
|
||||
|
function GunnerEmitter() { |
||||
|
_classCallCheck(this, GunnerEmitter); |
||||
|
|
||||
|
return _possibleConstructorReturn(this, _getPrototypeOf(GunnerEmitter).apply(this, arguments)); |
||||
|
} |
||||
|
|
||||
|
return GunnerEmitter; |
||||
|
}(EventEmitter); |
||||
|
|
||||
|
module.exports = new GunnerEmitter(); |
@ -0,0 +1,82 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } |
||||
|
|
||||
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } |
||||
|
|
||||
|
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } |
||||
|
|
||||
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } |
||||
|
|
||||
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } |
||||
|
|
||||
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } |
||||
|
|
||||
|
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } |
||||
|
|
||||
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } |
||||
|
|
||||
|
var _require = require('../util'), |
||||
|
liftPromise = _require.liftPromise, |
||||
|
lowerCaseFirstLetter = _require.lowerCaseFirstLetter; |
||||
|
|
||||
|
var library = require('./assertionsLibrary'); |
||||
|
|
||||
|
var assertPromise = require('./assertPromise'); |
||||
|
|
||||
|
var expectPromise = function expectPromise(pred, statement) { |
||||
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
||||
|
return function (toTest) { |
||||
|
return function () { |
||||
|
for (var _len = arguments.length, testValues = new Array(_len), _key = 0; _key < _len; _key++) { |
||||
|
testValues[_key] = arguments[_key]; |
||||
|
} |
||||
|
|
||||
|
return liftPromise(function (resolvedValue) { |
||||
|
return assertPromise(pred.apply(void 0, [toTest].concat(testValues)), [statement, resolvedValue].concat(testValues)); |
||||
|
}, toTest).catch(function (rejectedValue) { |
||||
|
return options.shouldCatch ? assertPromise(pred.apply(void 0, [toTest].concat(testValues)), [statement, rejectedValue].concat(testValues), { |
||||
|
skipStatement: rejectedValue |
||||
|
}) : Promise.reject(rejectedValue); |
||||
|
}); |
||||
|
}; |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
var expects = Object.keys(library).reduce(function (acc, e) { |
||||
|
var _library$e = _slicedToArray(library[e], 3), |
||||
|
pred = _library$e[0], |
||||
|
statement = _library$e[1], |
||||
|
options = _library$e[2]; |
||||
|
|
||||
|
acc[e] = expectPromise(pred, statement, options); |
||||
|
return acc; |
||||
|
}, {}); |
||||
|
|
||||
|
var negateP = function negateP(prom) { |
||||
|
return prom.then(Promise.reject, Promise.resolve); |
||||
|
}; |
||||
|
|
||||
|
var expect = function expect(thing, args) { |
||||
|
return new Proxy({}, { |
||||
|
get: function get(obj, prop) { |
||||
|
var toCheck = args ? thing.apply(void 0, _toConsumableArray(args)) : thing; |
||||
|
if (expects.hasOwnProperty(prop)) return function () { |
||||
|
return expects[prop](toCheck).apply(void 0, arguments); |
||||
|
};else if (prop.slice(0, 3) === 'not') return function () { |
||||
|
return negateP(expects[lowerCaseFirstLetter(prop.slice(3))](toCheck).apply(void 0, arguments)); |
||||
|
};else throw new Error('Unknown assertion method', prop); |
||||
|
} |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
var expectMany = function expectMany() { |
||||
|
for (var _len2 = arguments.length, expects = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { |
||||
|
expects[_key2] = arguments[_key2]; |
||||
|
} |
||||
|
|
||||
|
return Promise.all(expects); |
||||
|
}; |
||||
|
|
||||
|
module.exports = expect; |
||||
|
module.exports.expectMany = expectMany; |
@ -0,0 +1,20 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var snipStack = function snipStack(e) { |
||||
|
if (e.stack) e.stack = e.stack.split('\n').reduceRight(function (acc, x) { |
||||
|
return ( |
||||
|
/* eslint-disable-next-line */ |
||||
|
acc.done ? acc.cur : x.match(/at Object\.test.*\/src\/gunner\.js/) ? { |
||||
|
cur: x, |
||||
|
done: true |
||||
|
} : { |
||||
|
cur: [x, acc.cur].join('\n') |
||||
|
} |
||||
|
); |
||||
|
}, { |
||||
|
cur: '' |
||||
|
}).cur.trim(); |
||||
|
return e; |
||||
|
}; |
||||
|
|
||||
|
module.exports = snipStack; |
@ -0,0 +1,130 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } |
||||
|
|
||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
||||
|
|
||||
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } |
||||
|
|
||||
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } |
||||
|
|
||||
|
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } |
||||
|
|
||||
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } |
||||
|
|
||||
|
// Only imported for JSDoc
|
||||
|
|
||||
|
/* eslint-disable-next-line */ |
||||
|
var Gunner = require('../Gunner'); |
||||
|
|
||||
|
Promise.object = require('@codefeathers/promise.object'); |
||||
|
|
||||
|
var _require = require('../util'), |
||||
|
last = _require.last, |
||||
|
pipe = _require.pipe, |
||||
|
pick = _require.pick, |
||||
|
assignToObject = _require.assignToObject; |
||||
|
|
||||
|
var _require2 = require('../util/constants'), |
||||
|
eventMap = _require2.eventMap; |
||||
|
|
||||
|
var emitter = require('./emitter'); |
||||
|
|
||||
|
var buildTestQueue = require('./buildTestQueue'); |
||||
|
|
||||
|
var findSkip = function findSkip(skip, unit) { |
||||
|
var startFailed = skip.findIndex(function (x) { |
||||
|
return x.type === '@start'; |
||||
|
}); |
||||
|
var everyFailed = skip.findIndex(function (x) { |
||||
|
return x.type === '@every'; |
||||
|
}); |
||||
|
var beforeFailed = skip.findIndex(function (x) { |
||||
|
return x.description === unit.description; |
||||
|
}); |
||||
|
return startFailed !== -1 && 'A start hook failed\n' + skip[startFailed].error || everyFailed !== -1 && 'An every hook failed\n' + skip[everyFailed].error || beforeFailed !== -1 && 'A before test hook failed\n' + skip[beforeFailed].error; |
||||
|
}; |
||||
|
|
||||
|
var reduceQueue = function reduceQueue(queue) { |
||||
|
return queue.reduce(function (acc, item) { |
||||
|
return Promise.resolve(acc).then(function (acc) { |
||||
|
return Promise.all([last(acc.results), Promise.object(acc.state)]).then(function (_ref) { |
||||
|
var _ref2 = _slicedToArray(_ref, 2), |
||||
|
state = _ref2[1]; |
||||
|
|
||||
|
var toSkip = findSkip(acc.skip, item.unit); |
||||
|
return [toSkip, state]; |
||||
|
}).then(function (_ref3) { |
||||
|
var _ref4 = _slicedToArray(_ref3, 2), |
||||
|
toSkip = _ref4[0], |
||||
|
state = _ref4[1]; |
||||
|
|
||||
|
return toSkip ? { |
||||
|
status: 'skip', |
||||
|
description: toSkip |
||||
|
} : item.unit.run(state); |
||||
|
}).then(function (result) { |
||||
|
var status = result.status, |
||||
|
duration = result.duration; |
||||
|
|
||||
|
if (item.type === '@test') { |
||||
|
var resultObject = _objectSpread({ |
||||
|
status: status, |
||||
|
duration: duration, |
||||
|
description: item.unit.description |
||||
|
}, (status === 'notOk' || status === 'skip') && { |
||||
|
reason: result.error || result.rejection || result.description |
||||
|
}); |
||||
|
|
||||
|
emitter.emit(eventMap[status], resultObject); |
||||
|
acc.results.push(resultObject); |
||||
|
} else { |
||||
|
var identifier = item.unit.label || queue.filter(function (i) { |
||||
|
return i.type === item.type; |
||||
|
}).filter(function (i) { |
||||
|
return i.unit.description === item.unit.description; |
||||
|
}).length; |
||||
|
var stateAddition = |
||||
|
/* eslint-disable-next-line */ |
||||
|
status === 'ok' ? result.promise ? result.resolve : result.value : null; |
||||
|
if (identifier && stateAddition) assignToObject(acc.state, item.type)(identifier, stateAddition); |
||||
|
} |
||||
|
|
||||
|
if (status === 'notOk') { |
||||
|
acc.skip.push({ |
||||
|
type: item.type, |
||||
|
description: item.unit.description, |
||||
|
error: result.promise ? result.rejection : result.error |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
return acc; |
||||
|
}); |
||||
|
}); |
||||
|
}, { |
||||
|
results: [], |
||||
|
state: {}, |
||||
|
skip: [] |
||||
|
}); |
||||
|
}; |
||||
|
/** |
||||
|
* runs the test suite |
||||
|
* @param {Gunner} instance |
||||
|
* @param {object} options |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
var testrunner = function testrunner(instance) { |
||||
|
var perf = { |
||||
|
start: new Date() |
||||
|
}; |
||||
|
return Promise.object(pipe(buildTestQueue, reduceQueue, pick('results'))(instance)).then(function (results) { |
||||
|
perf.end = new Date(); |
||||
|
results.end = perf.end.toUTCString(); |
||||
|
results.start = perf.start.toUTCString(); |
||||
|
results.duration = perf.end - perf.start; |
||||
|
return results; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
module.exports = testrunner; |
@ -0,0 +1,31 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var statusMap = { |
||||
|
'ok': ['ok', '✅'], |
||||
|
'notOk': ['notOk', '❌'], |
||||
|
'skip': ['skip', '⚠️'] |
||||
|
}; |
||||
|
|
||||
|
var convert = function convert(x) { |
||||
|
return x; |
||||
|
}; |
||||
|
|
||||
|
var Default = function Default(runner, options) { |
||||
|
runner.on('start', function () { |
||||
|
return console.log('Started tests'); |
||||
|
}); |
||||
|
runner.on('test end', function (results) { |
||||
|
results.forEach(function (x) { |
||||
|
var s = statusMap[x.status]; |
||||
|
console.log('>', s[0], s[1], x.description); |
||||
|
options.trace && x.reason && console.log('\n---\n\n', x.reason, '\n\n---\n'); |
||||
|
}); |
||||
|
}); |
||||
|
runner.on('end', function (results) { |
||||
|
console.log(results.success.length, 'tests of', results.length, 'passed'); |
||||
|
console.log('Success ratio:', results.successPercent, '%'); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
module.exports = Default; |
||||
|
module.exports.convert = convert; |
@ -0,0 +1,16 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var def = require('./default'); |
||||
|
|
||||
|
var tap = require('./tap'); |
||||
|
|
||||
|
var xunit = require('./xunit'); |
||||
|
|
||||
|
var min = require('./min'); |
||||
|
|
||||
|
module.exports = { |
||||
|
default: def, |
||||
|
tap: tap, |
||||
|
xunit: xunit, |
||||
|
min: min |
||||
|
}; |
@ -0,0 +1,45 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var _require = require('../util/constants'), |
||||
|
eventMap = _require.eventMap, |
||||
|
eventVerbs = _require.eventVerbs; |
||||
|
|
||||
|
var _require2 = require('../util/nodeutils'), |
||||
|
clear = _require2.clear; |
||||
|
|
||||
|
var convert = function convert(x) { |
||||
|
return x; |
||||
|
}; |
||||
|
|
||||
|
var count = { |
||||
|
pass: 0, |
||||
|
fail: 0, |
||||
|
skip: 0, |
||||
|
collapse: function collapse() { |
||||
|
return this.pass + this.fail + this.skip; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
var doneHandler = function doneHandler(event) { |
||||
|
clear(); |
||||
|
var mapEvent = eventMap[event.status]; |
||||
|
count[mapEvent]++; |
||||
|
console.log("".concat(count[mapEvent], " tests ").concat(eventVerbs[mapEvent][2]) + " (total: ".concat(count.collapse(), ")")); |
||||
|
}; |
||||
|
|
||||
|
var Min = function Min(runner) { |
||||
|
runner.on('start', function () { |
||||
|
return console.log('Started tests'); |
||||
|
}); |
||||
|
runner.on('pass', doneHandler); |
||||
|
runner.on('fail', doneHandler); |
||||
|
runner.on('skip', doneHandler); |
||||
|
runner.on('end', function (results) { |
||||
|
clear(); |
||||
|
console.log("Test suite ".concat(results.name, " has done running.")); |
||||
|
console.log('Success ratio:', results.successPercent, '%'); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
module.exports = Min; |
||||
|
module.exports.convert = convert; |
@ -0,0 +1,24 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var statusMap = { |
||||
|
'ok': 'ok', |
||||
|
'notOk': 'not ok', |
||||
|
'skip': 'skip' |
||||
|
}; |
||||
|
|
||||
|
var convert = function convert(results, options) { |
||||
|
return "\nTAP version 13\n".concat(results.length ? '1' : 0, "..").concat(results.length, "\n").concat(results.map(function (r, i) { |
||||
|
var status = statusMap[r.status]; |
||||
|
var message = options.trace && r.reason && (r.reason.stack ? r.reason.stack : r.reason) || ''; |
||||
|
return "".concat(status, " ").concat(i + 1, " - ").concat(r.description) + (message && '\n ---\n message: |\n ' + message + '\n ---\n'); |
||||
|
}).join('\n'), "\n"); |
||||
|
}; |
||||
|
|
||||
|
var TAP = function TAP(runner, options) { |
||||
|
runner.on('end', function (results) { |
||||
|
return console.log(convert(results, options)); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
module.exports = TAP; |
||||
|
module.exports.convert = convert; |
@ -0,0 +1,71 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
||||
|
|
||||
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } |
||||
|
|
||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
||||
|
|
||||
|
var toXML = require('jsontoxml'); |
||||
|
|
||||
|
var _require = require('../util/nodeutils'), |
||||
|
clear = _require.clear; |
||||
|
|
||||
|
var toJSON = function toJSON(resultsArray) { |
||||
|
return { |
||||
|
testsuites: resultsArray.map(function (results) { |
||||
|
var name = results.name, |
||||
|
count = results.count, |
||||
|
success = results.success, |
||||
|
failures = results.failures, |
||||
|
skipped = results.skipped; |
||||
|
return { |
||||
|
name: 'testsuite', |
||||
|
attrs: { |
||||
|
name: name, |
||||
|
tests: count, |
||||
|
success: success.length, |
||||
|
failures: failures.length, |
||||
|
skipped: skipped.length, |
||||
|
timestamp: new Date().toUTCString(), |
||||
|
time: results.duration / 1000 || 0 |
||||
|
}, |
||||
|
children: results.reduce(function (acc, r) { |
||||
|
var content = r.status !== 'ok' && (r.status === 'skip' ? 'skipped' : { |
||||
|
name: 'failure', |
||||
|
text: r.reason ? r.reason && r.reason.stack : '' |
||||
|
}); |
||||
|
acc.push(_objectSpread({ |
||||
|
name: 'testcase', |
||||
|
attrs: { |
||||
|
name: r.description, |
||||
|
time: r.duration / 1000 || 0 |
||||
|
} |
||||
|
}, _typeof(content) === 'object' && { |
||||
|
text: content && content.stack |
||||
|
}, _typeof(content) === 'object' && { |
||||
|
children: [content] |
||||
|
})); |
||||
|
return acc; |
||||
|
}, []) |
||||
|
}; |
||||
|
}) |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
var convert = function convert(results) { |
||||
|
return toXML(toJSON(results), { |
||||
|
xmlHeader: { |
||||
|
standalone: true |
||||
|
} |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
var xunit = function xunit(runner) { |
||||
|
return runner.on("end", function (results) { |
||||
|
return clear(), console.log(convert([results])); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
module.exports = xunit; |
||||
|
module.exports.convert = convert; |
@ -0,0 +1,97 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
||||
|
|
||||
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
||||
|
|
||||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
||||
|
|
||||
|
var requireDeep = require('../util/requireDeep'); |
||||
|
|
||||
|
var Strategy = |
||||
|
/*#__PURE__*/ |
||||
|
function () { |
||||
|
/** |
||||
|
* @param {string} name name for the Strategy |
||||
|
* @param {Array<Function>} resources array of resource creators |
||||
|
* @param {Function} compiler spec compiler for this Strategy |
||||
|
* @param {Object} runTimeOptions options to use when running Gunner |
||||
|
*/ |
||||
|
function Strategy(name, resources, compiler, runTimeOptions) { |
||||
|
_classCallCheck(this, Strategy); |
||||
|
|
||||
|
this.name = name; |
||||
|
this.__resourceCreators = resources; |
||||
|
this.__runTimeOptions = runTimeOptions; |
||||
|
this.compiler = compiler; |
||||
|
this.__await__ = []; |
||||
|
this.__gunnerInstances = []; |
||||
|
this.resources = {}; |
||||
|
this.specs = []; |
||||
|
} |
||||
|
/** |
||||
|
* Creates a single resource |
||||
|
* @param {string} name |
||||
|
* @param {Object} resource |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
_createClass(Strategy, [{ |
||||
|
key: "createResource", |
||||
|
value: function createResource(name, resource) { |
||||
|
return this.__resourceCreators[name](resource); |
||||
|
} |
||||
|
/** |
||||
|
* Fetches all specs that match provided options |
||||
|
* @param {Object} options |
||||
|
* @param {string} options.plans |
||||
|
* @param {Array<string>=} options.exclude |
||||
|
* @param {string|Array<string>=} options.pattern |
||||
|
*/ |
||||
|
|
||||
|
}, { |
||||
|
key: "fetchSpecs", |
||||
|
value: function fetchSpecs(options) { |
||||
|
var _this = this; |
||||
|
|
||||
|
this.__await__.push(requireDeep(options).then(function (required) { |
||||
|
return required.map(function (each) { |
||||
|
return _this.__gunnerInstances = _this.compiler(_this)(each); |
||||
|
}); |
||||
|
})); |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
/** |
||||
|
* Adds a single spec to the strategy instance |
||||
|
* @param {Object} spec spec to add |
||||
|
*/ |
||||
|
|
||||
|
}, { |
||||
|
key: "addSpec", |
||||
|
value: function addSpec(spec) { |
||||
|
this.__gunnerInstances.push(this.compiler(this)(spec)); |
||||
|
|
||||
|
return this; |
||||
|
} |
||||
|
/** |
||||
|
* Starts running the gunner instances with the given options |
||||
|
* @param {Object=} options |
||||
|
*/ |
||||
|
|
||||
|
}, { |
||||
|
key: "run", |
||||
|
value: function run(options) { |
||||
|
var _this2 = this; |
||||
|
|
||||
|
var runOptions = options || this.__runTimeOptions; |
||||
|
return Promise.all(this.__await__).then(function () { |
||||
|
return _this2.__gunnerInstances.run(runOptions); |
||||
|
}); |
||||
|
} |
||||
|
}]); |
||||
|
|
||||
|
return Strategy; |
||||
|
}(); |
||||
|
|
||||
|
module.exports = Strategy; |
@ -0,0 +1,18 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var _require = require('os'), |
||||
|
EOL = _require.EOL; |
||||
|
|
||||
|
module.exports = { |
||||
|
EOL: EOL, |
||||
|
eventMap: { |
||||
|
'ok': 'pass', |
||||
|
'notOk': 'fail', |
||||
|
'skip': 'skip' |
||||
|
}, |
||||
|
eventVerbs: { |
||||
|
pass: ['pass', 'passing', 'passed'], |
||||
|
fail: ['fail', 'failing', 'failed'], |
||||
|
skip: ['skip', 'skipping', 'skipped'] |
||||
|
} |
||||
|
}; |
@ -0,0 +1,220 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
||||
|
|
||||
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } |
||||
|
|
||||
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } |
||||
|
|
||||
|
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } |
||||
|
|
||||
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } |
||||
|
|
||||
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
||||
|
|
||||
|
var _stringify = require('json-stringify-safe'); |
||||
|
|
||||
|
var isObject = function isObject(x) { |
||||
|
return x && _typeof(x) === 'object'; |
||||
|
}; |
||||
|
|
||||
|
var stringify = function stringify(obj) { |
||||
|
return isObject(obj) ? obj.stack || _stringify(obj) : obj; |
||||
|
}; |
||||
|
|
||||
|
var deepFlatten = function deepFlatten(arr) { |
||||
|
var _ref; |
||||
|
|
||||
|
return (_ref = []).concat.apply(_ref, _toConsumableArray(arr.map(function (v) { |
||||
|
return Array.isArray(v) ? deepFlatten(v) : v; |
||||
|
}))); |
||||
|
}; |
||||
|
/* Returns true if a promise is passed */ |
||||
|
|
||||
|
|
||||
|
var isPromise = function isPromise(prom) { |
||||
|
return prom && typeof prom.then === 'function'; |
||||
|
}; |
||||
|
/* Lift a value or promise into a function */ |
||||
|
|
||||
|
|
||||
|
var liftPromise = function liftPromise(fn, thing) { |
||||
|
return isPromise(thing) ? thing.then(fn) : fn(thing); |
||||
|
}; |
||||
|
|
||||
|
module.exports = { |
||||
|
/* Returns true if an object is passed */ |
||||
|
isObject: isObject, |
||||
|
|
||||
|
/* Returns true if a promise is passed */ |
||||
|
isPromise: isPromise, |
||||
|
|
||||
|
/* Lift a value or promise into a function */ |
||||
|
liftPromise: liftPromise, |
||||
|
|
||||
|
/* Returns the element found at the given path or undefined */ |
||||
|
path: function path(obj) { |
||||
|
return function (path) { |
||||
|
return path.reduce(function (result, segment) { |
||||
|
return result && result[segment]; |
||||
|
}, obj); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Picks a key from an object */ |
||||
|
pick: function pick(key) { |
||||
|
return function (obj) { |
||||
|
return obj[key]; |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Pipe a value or promise through any number of unary functions */ |
||||
|
pipe: function pipe() { |
||||
|
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) { |
||||
|
fns[_key] = arguments[_key]; |
||||
|
} |
||||
|
|
||||
|
return function (arg) { |
||||
|
return fns.reduce(function (acc, fn) { |
||||
|
return liftPromise(fn, acc); |
||||
|
}, arg); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Reduces an array */ |
||||
|
reduce: function reduce(fn, def) { |
||||
|
return function (arr) { |
||||
|
return arr.reduce(fn, def); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Flattens an array of arrays to an array */ |
||||
|
flatten: function flatten(arrData) { |
||||
|
return [].concat.apply([], arrData); |
||||
|
}, |
||||
|
|
||||
|
/* Deep flattens arrays */ |
||||
|
deepFlatten: deepFlatten, |
||||
|
|
||||
|
/* Maps a function over an array */ |
||||
|
map: function map(fn) { |
||||
|
return function (x) { |
||||
|
return x.map(fn); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Filter an array using provided function */ |
||||
|
filter: function filter(fn) { |
||||
|
return function (x) { |
||||
|
return x.filter(fn); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Returns identity */ |
||||
|
identity: function identity(x) { |
||||
|
return x; |
||||
|
}, |
||||
|
|
||||
|
/* Wraps a value in an object with given key */ |
||||
|
wrapWith: function wrapWith(x) { |
||||
|
return function (y) { |
||||
|
return _defineProperty({}, x, y); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Unwraps a value from an object with given key */ |
||||
|
unwrapFrom: function unwrapFrom(x) { |
||||
|
return function (y) { |
||||
|
return y[x]; |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Resolves an array of Promises */ |
||||
|
promiseAll: function promiseAll(x) { |
||||
|
return Promise.all(x); |
||||
|
}, |
||||
|
|
||||
|
/* Pass partial arguments and return a function that accepts the rest */ |
||||
|
partial: function partial(fn) { |
||||
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
||||
|
args[_key2 - 1] = arguments[_key2]; |
||||
|
} |
||||
|
|
||||
|
return function () { |
||||
|
for (var _len3 = arguments.length, rest = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { |
||||
|
rest[_key3] = arguments[_key3]; |
||||
|
} |
||||
|
|
||||
|
return fn.apply(void 0, args.concat(rest)); |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Item is in collection */ |
||||
|
isIn: function isIn(collection, item) { |
||||
|
return collection.indexOf(item) !== -1; |
||||
|
}, |
||||
|
|
||||
|
/* Collection contains given path */ |
||||
|
containsPath: function containsPath(collection, path) { |
||||
|
return collection.some(function (x) { |
||||
|
return path.match(new RegExp("/".concat(x, "/?$"))); |
||||
|
}); |
||||
|
}, |
||||
|
|
||||
|
/* Stringifies object or coerces to string */ |
||||
|
stringify: stringify, |
||||
|
|
||||
|
/* Tagged Stringify */ |
||||
|
taggedStringify: function taggedStringify(strings) { |
||||
|
for (var _len4 = arguments.length, expr = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { |
||||
|
expr[_key4 - 1] = arguments[_key4]; |
||||
|
} |
||||
|
|
||||
|
return strings.reduce(function (acc, curr, i) { |
||||
|
return acc + curr + (stringify(expr[i]) || ''); |
||||
|
}, ''); |
||||
|
}, |
||||
|
|
||||
|
/* Short circuits with given value on pred. Else calls function */ |
||||
|
short: function short(pred, shorter) { |
||||
|
return function (fn) { |
||||
|
return function (value) { |
||||
|
return pred(value) ? shorter(value) : fn(value); |
||||
|
}; |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Check if object has given property */ |
||||
|
hasProp: function hasProp(obj) { |
||||
|
return function (prop) { |
||||
|
return prop in obj; |
||||
|
}; |
||||
|
}, |
||||
|
|
||||
|
/* Fetches last element from list */ |
||||
|
last: function last(arr) { |
||||
|
return arr[arr.length - 1]; |
||||
|
}, |
||||
|
|
||||
|
/* Uppercases first letter of word */ |
||||
|
upperCaseFirstLetter: function upperCaseFirstLetter(word) { |
||||
|
return word[0].toUpperCase() + word.slice(1); |
||||
|
}, |
||||
|
|
||||
|
/* Lowercases first letter of word */ |
||||
|
lowerCaseFirstLetter: function lowerCaseFirstLetter(word) { |
||||
|
return word[0].toLowerCase() + word.slice(1); |
||||
|
}, |
||||
|
|
||||
|
/* Creates an array or pushes to an existing one */ |
||||
|
arrayOrPush: function arrayOrPush(obj, key, item) { |
||||
|
return Array.isArray(obj[key]) ? obj[key].push(item) : obj[key] = [item]; |
||||
|
}, |
||||
|
|
||||
|
/* Assigns to key or creates a new object */ |
||||
|
assignToObject: function assignToObject(obj, path) { |
||||
|
return function (key, value) { |
||||
|
return isObject(obj[path]) ? obj[path][key] = value : obj[path] = _defineProperty({}, key, value); |
||||
|
}; |
||||
|
} |
||||
|
}; |
@ -0,0 +1,12 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
module.exports = { |
||||
|
clear: function clear() { |
||||
|
if (typeof global === 'undefined' || typeof global.process === 'undefined' || typeof global.process.stdout === 'undefined') return; |
||||
|
var process = global.process; // clear screen
|
||||
|
|
||||
|
process.stdout.write("\x1B[2J"); // set cursor position to top
|
||||
|
|
||||
|
process.stdout.write("\x1B[1;1H"); |
||||
|
} |
||||
|
}; |
@ -0,0 +1,78 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
var fs = require("fs").promises; |
||||
|
|
||||
|
var _require = require('../util'), |
||||
|
map = _require.map, |
||||
|
pipe = _require.pipe, |
||||
|
filter = _require.filter, |
||||
|
flatten = _require.flatten, |
||||
|
wrapWith = _require.wrapWith, |
||||
|
promiseAll = _require.promiseAll, |
||||
|
containsPath = _require.containsPath; // const { warn } = console;
|
||||
|
// const validate = config => {
|
||||
|
// if(!config) throw new Error(`Create a config file to proceed.`);
|
||||
|
// if(!config.testData) throw new Error(`"testData" property not found in config.js`);
|
||||
|
// if(!config.plans) throw new Error(`"planDir" property not found in config.js`);
|
||||
|
// if(!config.pattern) warn(`> "pattern" property not found in config.js.`
|
||||
|
// + ` All json files in the target directory will be loaded.`);
|
||||
|
// };
|
||||
|
|
||||
|
|
||||
|
var isFileOrDir = function isFileOrDir(path) { |
||||
|
return fs.stat(path).then(function (stat) { |
||||
|
return stat.isDirectory() ? { |
||||
|
path: path, |
||||
|
type: "dir" |
||||
|
} : { |
||||
|
path: path, |
||||
|
type: "file" |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
var _matchOnePattern = function _matchOnePattern(pattern, path) { |
||||
|
var tests = Array.isArray(pattern) ? pattern : [pattern]; |
||||
|
return tests.some(function (test) { |
||||
|
return new RegExp(test).test(path); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
var _getEachFile = function _getEachFile(_ref) { |
||||
|
var path = _ref.path, |
||||
|
exclude = _ref.exclude, |
||||
|
pattern = _ref.pattern; |
||||
|
return function (item) { |
||||
|
return isFileOrDir(path + "/" + item).then(function (y) { |
||||
|
if (exclude && containsPath(exclude, y.path)) return []; |
||||
|
/* eslint-disable-next-line */ |
||||
|
|
||||
|
return y.type === "dir" ? requireDeep({ |
||||
|
plans: y.path, |
||||
|
exclude: exclude, |
||||
|
pattern: pattern |
||||
|
}) : _matchOnePattern(pattern || '.json', y.path) // Wrapping in object to prevent accidental flattening
|
||||
|
? wrapWith("module")(require(y.path)) : []; |
||||
|
}); |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
var requireDeep = function requireDeep(_ref2) { |
||||
|
var path = _ref2.plans, |
||||
|
exclude = _ref2.exclude, |
||||
|
_ref2$pattern = _ref2.pattern, |
||||
|
pattern = _ref2$pattern === void 0 ? '.json' : _ref2$pattern; |
||||
|
return isFileOrDir(path).then(function (o) { |
||||
|
return o.type === "dir" ? pipe(fs.readdir, map(_getEachFile({ |
||||
|
path: path, |
||||
|
exclude: exclude, |
||||
|
pattern: pattern |
||||
|
})), promiseAll, flatten, filter(Boolean), // Filter out undefined values
|
||||
|
map(function (y) { |
||||
|
return y.module || y; |
||||
|
}) // Unwrap objects from their wrappers
|
||||
|
)(o.path) : Promise.reject("".concat(path, " is not a directory")); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
module.exports = requireDeep; |
@ -0,0 +1,9 @@ |
|||||
|
"use strict"; |
||||
|
|
||||
|
module.exports = { |
||||
|
Start: Symbol('Start'), |
||||
|
End: Symbol('End'), |
||||
|
expect: Symbol('expect'), |
||||
|
pass: 'pass', |
||||
|
fail: 'fail' |
||||
|
}; |
@ -1 +0,0 @@ |
|||||
module.exports = require('../src/gunner'); |
|
@ -1 +1 @@ |
|||||
module.exports = require('./src/gunner'); |
module.exports = require('./src/Gunner'); |
@ -1,20 +1,32 @@ |
|||||
#!/bin/bash |
#!/bin/bash |
||||
|
|
||||
rm -rf ./es5 |
rm -rf ./es5 |
||||
|
rm -rf ./browser |
||||
mkdir ./es5 |
mkdir ./es5 |
||||
|
mkdir ./browser |
||||
|
|
||||
|
echo "----> :: Building Gunner for browser ::" |
||||
|
|
||||
echo "----> :: Gunner ::" |
|
||||
echo "----> Browserifying..." |
echo "----> Browserifying..." |
||||
./node_modules/.bin/browserify ./index.js -s Gunner > ./es5/index.js |
./node_modules/.bin/browserify ./index.js -s Gunner > ./browser/index.js |
||||
|
|
||||
echo "----> Babelifying..." |
echo "----> Babelifying..." |
||||
./node_modules/.bin/babel --presets env --plugins transform-object-rest-spread ./es5/index.js -o ./es5/index.js |
./node_modules/.bin/babel \ |
||||
echo "> Done" |
--presets @babel/preset-env \ |
||||
|
--plugins @babel/plugin-syntax-object-rest-spread \ |
||||
|
./browser/index.js \ |
||||
|
-o ./browser/index.js |
||||
|
|
||||
|
echo "> Done ./browser/index.js" |
||||
echo "" |
echo "" |
||||
|
|
||||
echo "----> :: Runner ::" |
echo "----> :: Babelifying Gunner source ::" |
||||
echo "----> Browserifying..." |
|
||||
./node_modules/.bin/browserify ./Runner.js -s Runner > ./es5/Runner.js |
|
||||
echo "----> Babelifying..." |
echo "----> Babelifying..." |
||||
./node_modules/.bin/babel --presets env --plugins transform-object-rest-spread ./es5/Runner.js -o ./es5/Runner.js |
./node_modules/.bin/babel \ |
||||
|
--presets @babel/preset-env \ |
||||
|
--plugins @babel/plugin-syntax-object-rest-spread \ |
||||
|
./src \ |
||||
|
--out-dir ./es5 |
||||
|
|
||||
echo "> Done" |
echo "> Done ./es5" |
||||
|
File diff suppressed because it is too large
Loading…
Reference in new issue