App-Netdisco
view release on metacpan or search on metacpan
xt/js/qunit-tap.js view on Meta::CPAN
}
function isAssertOkFailed (details) {
return isFailed(details) && typeof details.expected === 'undefined' && typeof details.actual === 'undefined';
}
// borrowed from prototype.js
// not required since QUnit.log receives raw data (details). see jquery/qunit@c2cde34
function stripTags (str) {
if (!str) {
return str;
}
return str.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
}
function escapeLineEndings (str) {
return str.replace(/(\r?\n)/g, '$&# ');
}
function ltrim (str) {
return str.replace(/^\s+/, '');
}
function noop (obj) {
return obj;
}
function render (desc, fieldName, fieldValue, formatter) {
desc.push(fieldName + ': ' + formatter(fieldValue));
}
function renderIf (shouldRender, desc, fieldName, fieldValue, formatter) {
if (!shouldRender || typeof fieldValue === 'undefined') {
return;
}
render(desc, fieldName, fieldValue, formatter);
}
function formatTestLine (testLine, rest) {
if (!rest) {
return testLine;
}
return testLine + ' - ' + escapeLineEndings(rest);
}
var extractDetailsFrom = (function () {
var detailsExtractor;
function setupExtractor (logArguments) {
switch (logArguments.length) {
case 1: // details
detailsExtractor = function (args) { return args[0]; };
break;
case 2: // result, message(with tags)
detailsExtractor = function (args) { return {result: args[0], message: stripTags(args[1])}; };
break;
case 3: // result, message, details
detailsExtractor = function (args) { return args[2]; };
break;
default:
throw new Error('QUnit-TAP does not support QUnit#log arguments like this.');
}
}
return function (logArguments) {
if (detailsExtractor) {
return detailsExtractor(logArguments);
}
setupExtractor(logArguments);
return detailsExtractor(logArguments);
};
})();
var createCallbackAppenderFor = function (qu) {
// detect QUnit's multipleCallbacks feature. see jquery/qunit@34f6bc1
var isMultipleLoggingCallbacksSupported =
(typeof qu.config !== 'undefined' &&
typeof qu.config.log !== 'undefined' &&
typeof qu.config.done !== 'undefined' &&
typeof qu.config.testDone !== 'undefined' &&
typeof qu.config.moduleStart !== 'undefined' &&
typeof qu.config.testStart !== 'undefined');
return function (subject, observer, event) {
var originalLoggingCallback = subject[event],
callback;
if (isMultipleLoggingCallbacksSupported) {
callback = function () {
// make listener methods (moduleStart,testStart,log, ...) overridable.
observer[event].apply(observer, slice.apply(arguments));
};
originalLoggingCallback(callback);
} else if (typeof originalLoggingCallback === 'function') {
// do not overwrite old-style logging callbacks
callback = function () {
var args = slice.apply(arguments);
originalLoggingCallback.apply(subject, args);
observer[event].apply(observer, args);
};
subject[event] = callback;
}
return callback;
};
};
/**
* QUnit-TAP - A TAP Output Producer Plugin for QUnit
* @param qunitObject QUnit object reference.
* @param printLikeFunction print-like function for TAP output (assumes line-separator is added by this function for each call).
* @param options configuration options to customize default behavior.
* @return object to provide QUnit-TAP API and customization subject.
*/
function qunitTap(qunitObject, printLikeFunction, options) {
if (!qunitObject) {
throw new Error('should pass QUnit object reference. Please check QUnit\'s "require" path if you are using Node.js (or any CommonJS env).');
} else if (typeof printLikeFunction !== 'function') {
throw new Error('should pass print-like function');
}
var qu = qunitObject,
tap = {},
jsDumpExists = (typeof qu.jsDump !== 'undefined' && typeof qu.jsDump.parse === 'function'),
explain = (jsDumpExists ? function explain (obj) { return qu.jsDump.parse(obj); } : noop),
deprecateOption = function deprecateOption (optionName, fallback) {
// option deprecation and fallback function
if (!options || typeof options !== 'object') {
return;
}
if (typeof options[optionName] === 'undefined') {
return;
}
printLikeFunction('# WARNING: Option "' + optionName + '" is deprecated and will be removed in future version.');
fallback(options[optionName]);
},
targetEvents = [
'moduleStart',
'testStart',
'log',
'testDone',
'done'
],
registeredCallbacks = {};
tap.config = extend(
{
initialCount: 1,
showModuleNameOnFailure: true,
showTestNameOnFailure: true,
showExpectationOnFailure: true,
showSourceOnFailure: true
},
options
);
deprecateOption('noPlan', function (flag) {
printLikeFunction('# Now QUnit-TAP works as with "noPlan: true" by default. If you want to delare plan explicitly, please use "QUnit.config.requireExpects" option instead.');
tap.config.noPlan = flag;
});
deprecateOption('count', function (count) {
tap.config.initialCount = (count + 1);
});
deprecateOption('showDetailsOnFailure', function (flag) {
tap.config.showModuleNameOnFailure = flag;
tap.config.showTestNameOnFailure = flag;
tap.config.showExpectationOnFailure = flag;
tap.config.showSourceOnFailure = flag;
});
tap.VERSION = qunitTapVersion;
tap.puts = printLikeFunction;
tap.count = tap.config.initialCount - 1;
tap.expectedCount = tap.config.initialCount - 1;
function isEnabled (configName) {
return tap.config[configName];
}
function formatDetails (details) {
xt/js/qunit-tap.js view on Meta::CPAN
tap.note('module: ' + name);
};
tap.testStart = function testStart (arg) {
var name = (typeof arg === 'string') ? arg : arg.name;
tap.note('test: ' + name);
};
tap.log = function log () {
var details = extractDetailsFrom(arguments),
testLine = '';
tap.count += 1;
if (isFailed(details)) {
testLine += 'not ';
}
testLine += ('ok ' + tap.count);
tap.puts(formatTestLine(testLine, formatDetails(details)));
};
tap.testDone = function testDone () {
if (isPlanRequired(qu.config)) {
tap.expectedCount += qu.config.current.expected;
}
};
tap.done = function done () {
if (typeof tap.config.noPlan !== 'undefined' && !(tap.config.noPlan)) {
// Do nothing until removal of 'noPlan' option.
} else if (isPlanRequired(qu.config)) {
printPlanLine(tap.expectedCount);
} else {
printPlanLine(tap.count);
}
};
tap.unsubscribe = function unsubscribe () {
if (typeof qu.config === 'undefined') {
return;
}
if (arguments.length === 0) {
unsubscribeEvents(targetEvents);
} else {
unsubscribeEvents(slice.apply(arguments));
}
};
(function () {
var appendCallback = createCallbackAppenderFor(qu),
eventName, i, callback;
for (i = 0; i < targetEvents.length; i += 1) {
eventName = targetEvents[i];
callback = appendCallback(qu, tap, eventName);
registeredCallbacks[eventName] = callback;
}
})();
return tap;
}
qunitTap.qunitTap = function () {
throw new Error('[BC BREAK] Since 1.4.0, QUnit-TAP exports single qunitTap function as module.exports. Therefore, require("qunit-tap") returns qunitTap function itself. Please fix your code if you are using Node.js (or any CommonJS env).');
};
// using substack pattern (export single function)
return qunitTap;
}));
( run in 1.543 second using v1.01-cache-2.11-cpan-39bf76dae61 )