code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function close_tunnel(status) { // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) return; // If connection closed abnormally, signal error. if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) tunnel.onerror(status); // Mark as closed tunnel.state = Guacamole.Tunnel.State.CLOSED; if (tunnel.onstatechange) tunnel.onstatechange(tunnel.state); socket.close(); }
Closes this tunnel, signaling the given status and corresponding message, which will be sent to the onerror handler if the status is an error status. @private @param {Guacamole.Status} status The status causing the connection to close;
close_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function getElement(value) { var string = new String(value); return string.length + "." + string; }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
getElement
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function attach(tunnel) { // Set own functions to tunnel's functions chained_tunnel.disconnect = tunnel.disconnect; chained_tunnel.sendMessage = tunnel.sendMessage; /** * Fails the currently-attached tunnel, attaching a new tunnel if * possible. * * @private * @return {Guacamole.Tunnel} The next tunnel, or null if there are no * more tunnels to try. */ function fail_tunnel() { // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; } /** * Use the current tunnel from this point forward. Do not try any more * tunnels, even if the current tunnel fails. * * @private */ function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; } // Wrap own onstatechange within current tunnel tunnel.onstatechange = function(state) { switch (state) { // If open, use this tunnel from this point forward. case Guacamole.Tunnel.State.OPEN: commit_tunnel(); if (chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; // If closed, mark failure, attempt next tunnel case Guacamole.Tunnel.State.CLOSED: if (!fail_tunnel() && chained_tunnel.onstatechange) chained_tunnel.onstatechange(state); break; } }; // Wrap own oninstruction within current tunnel tunnel.oninstruction = function(opcode, elements) { // Accept current tunnel commit_tunnel(); // Invoke handler if (chained_tunnel.oninstruction) chained_tunnel.oninstruction(opcode, elements); }; // Attach next tunnel on error tunnel.onerror = function(status) { // Mark failure, attempt next tunnel if (!fail_tunnel() && chained_tunnel.onerror) chained_tunnel.onerror(status); }; // Attempt connection tunnel.connect(connect_data); }
Sets the current tunnel. @private @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
attach
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function fail_tunnel() { // Get next tunnel var next_tunnel = tunnels.shift(); // If there IS a next tunnel, try using it. if (next_tunnel) { tunnel.onerror = null; tunnel.oninstruction = null; tunnel.onstatechange = null; attach(next_tunnel); } return next_tunnel; }
Fails the currently-attached tunnel, attaching a new tunnel if possible. @private @return {Guacamole.Tunnel} The next tunnel, or null if there are no more tunnels to try.
fail_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function commit_tunnel() { tunnel.onstatechange = chained_tunnel.onstatechange; tunnel.oninstruction = chained_tunnel.oninstruction; tunnel.onerror = chained_tunnel.onerror; }
Use the current tunnel from this point forward. Do not try any more tunnels, even if the current tunnel fails. @private
commit_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function every (arr, fn, thisObj) { var scope = thisObj || global; for (var i = 0, j = arr.length; i < j; ++i) { if (!fn.call(scope, arr[i], i, arr)) { return false; } } return true; }
Array every compatibility @see bit.ly/5Fq1N2 @api public
every
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/expect.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/expect.js
MIT
function indexOf (arr, o, i) { if (Array.prototype.indexOf) { return Array.prototype.indexOf.call(arr, o, i); } if (arr.length === undefined) { return -1; } for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0 ; i < j && arr[i] !== o; i++); return j <= i ? -1 : i; }
Array indexOf compatibility. @see bit.ly/a5Dxa2 @api public
indexOf
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/expect.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/expect.js
MIT
getOuterHTML = function(element) { if ('outerHTML' in element) return element.outerHTML; var ns = "http://www.w3.org/1999/xhtml"; var container = document.createElementNS(ns, '_'); var xmlSerializer = new XMLSerializer(); var html; if (document.xmlVersion) { return xmlSerializer.serializeToString(element); } else { container.appendChild(element.cloneNode(false)); html = container.innerHTML.replace('><', '>' + element.innerHTML + '<'); container.innerHTML = ''; return html; } }
Array indexOf compatibility. @see bit.ly/a5Dxa2 @api public
getOuterHTML
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/expect.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/expect.js
MIT
isDOMElement = function (object) { if (typeof HTMLElement === 'object') { return object instanceof HTMLElement; } else { return object && typeof object === 'object' && object.nodeType === 1 && typeof object.nodeName === 'string'; } }
Array indexOf compatibility. @see bit.ly/a5Dxa2 @api public
isDOMElement
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/expect.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/expect.js
MIT
function isArray(obj) { return '[object Array]' == {}.toString.call(obj); }
Check if `obj` is an array.
isArray
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Hook(title, fn) { Runnable.call(this, title, fn); this.type = 'hook'; }
Initialize a new `Hook` with the given `title` and callback `fn`. @param {String} title @param {Function} fn @api private
Hook
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function visit(obj) { var suite; for (var key in obj) { if ('function' == typeof obj[key]) { var fn = obj[key]; switch (key) { case 'before': suites[0].beforeAll(fn); break; case 'after': suites[0].afterAll(fn); break; case 'beforeEach': suites[0].beforeEach(fn); break; case 'afterEach': suites[0].afterEach(fn); break; default: suites[0].addTest(new Test(key, fn)); } } else { var suite = Suite.create(suites[0], key); suites.unshift(suite); visit(obj[key]); suites.shift(); } } }
TDD-style interface: exports.Array = { '#indexOf()': { 'should return -1 when the value is not present': function(){ }, 'should return the correct index when the value is present': function(){ } } };
visit
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function image(name) { return __dirname + '/../images/' + name + '.png'; }
Return image `name` path. @param {String} name @return {String} @api private
image
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Mocha(options) { options = options || {}; this.files = []; this.options = options; this.grep(options.grep); this.suite = new exports.Suite('', new exports.Context); this.ui(options.ui); this.bail(options.bail); this.reporter(options.reporter); if (null != options.timeout) this.timeout(options.timeout); if (options.slow) this.slow(options.slow); }
Setup mocha with `options`. Options: - `ui` name "bdd", "tdd", "exports" etc - `reporter` reporter instance, defaults to `mocha.reporters.Dot` - `globals` array of accepted globals - `timeout` timeout in milliseconds - `bail` bail on the first test failure - `slow` milliseconds to wait before considering a test slow - `ignoreLeaks` ignore global leaks - `grep` string or regexp to filter tests with @param {Object} options @api public
Mocha
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function parse(str) { var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str); if (!match) return; var n = parseFloat(match[1]); var type = (match[2] || 'ms').toLowerCase(); switch (type) { case 'years': case 'year': case 'y': return n * y; case 'days': case 'day': case 'd': return n * d; case 'hours': case 'hour': case 'h': return n * h; case 'minutes': case 'minute': case 'm': return n * m; case 'seconds': case 'second': case 's': return n * s; case 'ms': return n; } }
Parse the given `str` and return milliseconds. @param {String} str @return {Number} @api private
parse
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function short(ms) { if (ms >= d) return Math.round(ms / d) + 'd'; if (ms >= h) return Math.round(ms / h) + 'h'; if (ms >= m) return Math.round(ms / m) + 'm'; if (ms >= s) return Math.round(ms / s) + 's'; return ms + 'ms'; }
Short format for `ms`. @param {Number} ms @return {String} @api private
short
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function long(ms) { return plural(ms, d, 'day') || plural(ms, h, 'hour') || plural(ms, m, 'minute') || plural(ms, s, 'second') || ms + ' ms'; }
Long format for `ms`. @param {Number} ms @return {String} @api private
long
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Base(runner) { var self = this , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 } , failures = this.failures = []; if (!runner) return; this.runner = runner; runner.stats = stats; runner.on('start', function(){ stats.start = new Date; }); runner.on('suite', function(suite){ stats.suites = stats.suites || 0; suite.root || stats.suites++; }); runner.on('test end', function(test){ stats.tests = stats.tests || 0; stats.tests++; }); runner.on('pass', function(test){ stats.passes = stats.passes || 0; var medium = test.slow() / 2; test.speed = test.duration > test.slow() ? 'slow' : test.duration > medium ? 'medium' : 'fast'; stats.passes++; }); runner.on('fail', function(test, err){ stats.failures = stats.failures || 0; stats.failures++; test.err = err; failures.push(test); }); runner.on('end', function(){ stats.end = new Date; stats.duration = new Date - stats.start; }); runner.on('pending', function(){ stats.pending++; }); }
Initialize a new `Base` reporter. All other reporters generally inherit from this reporter, providing stats such as test duration, number of tests passed / failed etc. @param {Runner} runner @api public
Base
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function pad(str, len) { str = String(str); return Array(len - str.length + 1).join(' ') + str; }
Pad the given `str` to `len`. @param {String} str @param {String} len @return {String} @api private
pad
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function inlineDiff(err, escape) { var msg = errorDiff(err, 'WordsWithSpace', escape); // linenos var lines = msg.split('\n'); if (lines.length > 4) { var width = String(lines.length).length; msg = lines.map(function(str, i){ return pad(++i, width) + ' |' + ' ' + str; }).join('\n'); } // legend msg = '\n' + color('diff removed', 'actual') + ' ' + color('diff added', 'expected') + '\n\n' + msg + '\n'; // indent msg = msg.replace(/^/gm, ' '); return msg; }
Returns an inline diff between 2 strings with coloured ANSI output @param {Error} Error with actual/expected @return {String} Diff @api private
inlineDiff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function unifiedDiff(err, escape) { var indent = ' '; function cleanUp(line) { if (escape) { line = escapeInvisibles(line); } if (line[0] === '+') return indent + colorLines('diff added', line); if (line[0] === '-') return indent + colorLines('diff removed', line); if (line.match(/\@\@/)) return null; if (line.match(/\\ No newline/)) return null; else return indent + line; } function notBlank(line) { return line != null; } msg = diff.createPatch('string', err.actual, err.expected); var lines = msg.split('\n').splice(4); return '\n ' + colorLines('diff added', '+ expected') + ' ' + colorLines('diff removed', '- actual') + '\n\n' + lines.map(cleanUp).filter(notBlank).join('\n'); }
Returns a unified diff between 2 strings @param {Error} Error with actual/expected @return {String} Diff @api private
unifiedDiff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function cleanUp(line) { if (escape) { line = escapeInvisibles(line); } if (line[0] === '+') return indent + colorLines('diff added', line); if (line[0] === '-') return indent + colorLines('diff removed', line); if (line.match(/\@\@/)) return null; if (line.match(/\\ No newline/)) return null; else return indent + line; }
Returns a unified diff between 2 strings @param {Error} Error with actual/expected @return {String} Diff @api private
cleanUp
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function notBlank(line) { return line != null; }
Returns a unified diff between 2 strings @param {Error} Error with actual/expected @return {String} Diff @api private
notBlank
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function errorDiff(err, type, escape) { var actual = escape ? escapeInvisibles(err.actual) : err.actual; var expected = escape ? escapeInvisibles(err.expected) : err.expected; return diff['diff' + type](actual, expected).map(function(str){ if (str.added) return colorLines('diff added', str.value); if (str.removed) return colorLines('diff removed', str.value); return str.value; }).join(''); }
Return a character diff for `err`. @param {Error} err @return {String} @api private
errorDiff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function escapeInvisibles(line) { return line.replace(/\t/g, '<tab>') .replace(/\r/g, '<CR>') .replace(/\n/g, '<LF>\n'); }
Returns a string with all invisible characters in plain text @param {String} line @return {String} @api private
escapeInvisibles
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function colorLines(name, str) { return str.split('\n').map(function(str){ return color(name, str); }).join('\n'); }
Color lines for `str`, using the color `name`. @param {String} name @param {String} str @return {String} @api private
colorLines
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function stringify(obj) { if (obj instanceof RegExp) return obj.toString(); return JSON.stringify(obj, null, 2); }
Stringify `obj`. @param {Mixed} obj @return {String} @api private
stringify
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function sameType(a, b) { a = Object.prototype.toString.call(a); b = Object.prototype.toString.call(b); return a == b; }
Check that a / b have the same type. @param {Object} a @param {Object} b @return {Boolean} @api private
sameType
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Doc(runner) { Base.call(this, runner); var self = this , stats = this.stats , total = runner.total , indents = 2; function indent() { return Array(indents).join(' '); } runner.on('suite', function(suite){ if (suite.root) return; ++indents; console.log('%s<section class="suite">', indent()); ++indents; console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title)); console.log('%s<dl>', indent()); }); runner.on('suite end', function(suite){ if (suite.root) return; console.log('%s</dl>', indent()); --indents; console.log('%s</section>', indent()); --indents; }); runner.on('pass', function(test){ console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title)); var code = utils.escape(utils.clean(test.fn.toString())); console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code); }); }
Initialize a new `Doc` reporter. @param {Runner} runner @api public
Doc
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function indent() { return Array(indents).join(' '); }
Initialize a new `Doc` reporter. @param {Runner} runner @api public
indent
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Dot(runner) { Base.call(this, runner); var self = this , stats = this.stats , width = Base.window.width * .75 | 0 , n = 0; runner.on('start', function(){ process.stdout.write('\n '); }); runner.on('pending', function(test){ process.stdout.write(color('pending', Base.symbols.dot)); }); runner.on('pass', function(test){ if (++n % width == 0) process.stdout.write('\n '); if ('slow' == test.speed) { process.stdout.write(color('bright yellow', Base.symbols.dot)); } else { process.stdout.write(color(test.speed, Base.symbols.dot)); } }); runner.on('fail', function(test, err){ if (++n % width == 0) process.stdout.write('\n '); process.stdout.write(color('fail', Base.symbols.dot)); }); runner.on('end', function(){ console.log(); self.epilogue(); }); }
Initialize a new `Dot` matrix test reporter. @param {Runner} runner @api public
Dot
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function HTMLCov(runner) { var jade = require('jade') , file = __dirname + '/templates/coverage.jade' , str = fs.readFileSync(file, 'utf8') , fn = jade.compile(str, { filename: file }) , self = this; JSONCov.call(this, runner, false); runner.on('end', function(){ process.stdout.write(fn({ cov: self.cov , coverageClass: coverageClass })); }); }
Initialize a new `JsCoverage` reporter. @param {Runner} runner @api public
HTMLCov
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function coverageClass(n) { if (n >= 75) return 'high'; if (n >= 50) return 'medium'; if (n >= 25) return 'low'; return 'terrible'; }
Return coverage class for `n`. @return {String} @api private
coverageClass
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function hideSuitesWithout(classname) { var suites = document.getElementsByClassName('suite'); for (var i = 0; i < suites.length; i++) { var els = suites[i].getElementsByClassName(classname); if (0 == els.length) suites[i].className += ' hidden'; } }
Check for suites that do not have elements with `classname`, and hide them.
hideSuitesWithout
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function on(el, event, fn) { if (el.addEventListener) { el.addEventListener(event, fn, false); } else { el.attachEvent('on' + event, fn); } }
Listen on `event` with callback `fn`.
on
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function JSONCov(runner, output) { var self = this , output = 1 == arguments.length ? true : output; Base.call(this, runner); var tests = [] , failures = [] , passes = []; runner.on('test end', function(test){ tests.push(test); }); runner.on('pass', function(test){ passes.push(test); }); runner.on('fail', function(test){ failures.push(test); }); runner.on('end', function(){ var cov = global._$jscoverage || {}; var result = self.cov = map(cov); result.stats = self.stats; result.tests = tests.map(clean); result.failures = failures.map(clean); result.passes = passes.map(clean); if (!output) return; process.stdout.write(JSON.stringify(result, null, 2 )); }); }
Initialize a new `JsCoverage` reporter. @param {Runner} runner @param {Boolean} output @api public
JSONCov
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function map(cov) { var ret = { instrumentation: 'node-jscoverage' , sloc: 0 , hits: 0 , misses: 0 , coverage: 0 , files: [] }; for (var filename in cov) { var data = coverage(filename, cov[filename]); ret.files.push(data); ret.hits += data.hits; ret.misses += data.misses; ret.sloc += data.sloc; } ret.files.sort(function(a, b) { return a.filename.localeCompare(b.filename); }); if (ret.sloc > 0) { ret.coverage = (ret.hits / ret.sloc) * 100; } return ret; }
Map jscoverage data to a JSON structure suitable for reporting. @param {Object} cov @return {Object} @api private
map
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function coverage(filename, data) { var ret = { filename: filename, coverage: 0, hits: 0, misses: 0, sloc: 0, source: {} }; data.source.forEach(function(line, num){ num++; if (data[num] === 0) { ret.misses++; ret.sloc++; } else if (data[num] !== undefined) { ret.hits++; ret.sloc++; } ret.source[num] = { source: line , coverage: data[num] === undefined ? '' : data[num] }; }); ret.coverage = ret.hits / ret.sloc * 100; return ret; }
Map jscoverage data for a single source file to a JSON structure suitable for reporting. @param {String} filename name of the source file @param {Object} data jscoverage coverage data @return {Object} @api private
coverage
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function clean(test) { return { title: test.title , fullTitle: test.fullTitle() , duration: test.duration } }
Return a plain-object representation of `test` free of cyclic properties etc. @param {Object} test @return {Object} @api private
clean
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function List(runner) { Base.call(this, runner); var self = this , stats = this.stats , total = runner.total; runner.on('start', function(){ console.log(JSON.stringify(['start', { total: total }])); }); runner.on('pass', function(test){ console.log(JSON.stringify(['pass', clean(test)])); }); runner.on('fail', function(test, err){ console.log(JSON.stringify(['fail', clean(test)])); }); runner.on('end', function(){ process.stdout.write(JSON.stringify(['end', self.stats])); }); }
Initialize a new `List` test reporter. @param {Runner} runner @api public
List
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function clean(test) { return { title: test.title , fullTitle: test.fullTitle() , duration: test.duration } }
Return a plain-object representation of `test` free of cyclic properties etc. @param {Object} test @return {Object} @api private
clean
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function JSONReporter(runner) { var self = this; Base.call(this, runner); var tests = [] , failures = [] , passes = []; runner.on('test end', function(test){ tests.push(test); }); runner.on('pass', function(test){ passes.push(test); }); runner.on('fail', function(test){ failures.push(test); }); runner.on('end', function(){ var obj = { stats: self.stats , tests: tests.map(clean) , failures: failures.map(clean) , passes: passes.map(clean) }; process.stdout.write(JSON.stringify(obj, null, 2)); }); }
Initialize a new `JSON` reporter. @param {Runner} runner @api public
JSONReporter
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function clean(test) { return { title: test.title , fullTitle: test.fullTitle() , duration: test.duration } }
Return a plain-object representation of `test` free of cyclic properties etc. @param {Object} test @return {Object} @api private
clean
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function runway() { var buf = Array(width).join('-'); return ' ' + color('runway', buf); }
Initialize a new `Landing` reporter. @param {Runner} runner @api public
runway
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function List(runner) { Base.call(this, runner); var self = this , stats = this.stats , n = 0; runner.on('start', function(){ console.log(); }); runner.on('test', function(test){ process.stdout.write(color('pass', ' ' + test.fullTitle() + ': ')); }); runner.on('pending', function(test){ var fmt = color('checkmark', ' -') + color('pending', ' %s'); console.log(fmt, test.fullTitle()); }); runner.on('pass', function(test){ var fmt = color('checkmark', ' '+Base.symbols.dot) + color('pass', ' %s: ') + color(test.speed, '%dms'); cursor.CR(); console.log(fmt, test.fullTitle(), test.duration); }); runner.on('fail', function(test, err){ cursor.CR(); console.log(color('fail', ' %d) %s'), ++n, test.fullTitle()); }); runner.on('end', self.epilogue.bind(self)); }
Initialize a new `List` test reporter. @param {Runner} runner @api public
List
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Markdown(runner) { Base.call(this, runner); var self = this , stats = this.stats , level = 0 , buf = ''; function title(str) { return Array(level).join('#') + ' ' + str; } function indent() { return Array(level).join(' '); } function mapTOC(suite, obj) { var ret = obj; obj = obj[suite.title] = obj[suite.title] || { suite: suite }; suite.suites.forEach(function(suite){ mapTOC(suite, obj); }); return ret; } function stringifyTOC(obj, level) { ++level; var buf = ''; var link; for (var key in obj) { if ('suite' == key) continue; if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n'; if (key) buf += Array(level).join(' ') + link; buf += stringifyTOC(obj[key], level); } --level; return buf; } function generateTOC(suite) { var obj = mapTOC(suite, {}); return stringifyTOC(obj, 0); } generateTOC(runner.suite); runner.on('suite', function(suite){ ++level; var slug = utils.slug(suite.fullTitle()); buf += '<a name="' + slug + '"></a>' + '\n'; buf += title(suite.title) + '\n'; }); runner.on('suite end', function(suite){ --level; }); runner.on('pass', function(test){ var code = utils.clean(test.fn.toString()); buf += test.title + '.\n'; buf += '\n```js\n'; buf += code + '\n'; buf += '```\n\n'; }); runner.on('end', function(){ process.stdout.write('# TOC\n'); process.stdout.write(generateTOC(runner.suite)); process.stdout.write(buf); }); }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
Markdown
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function title(str) { return Array(level).join('#') + ' ' + str; }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
title
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function indent() { return Array(level).join(' '); }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
indent
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function mapTOC(suite, obj) { var ret = obj; obj = obj[suite.title] = obj[suite.title] || { suite: suite }; suite.suites.forEach(function(suite){ mapTOC(suite, obj); }); return ret; }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
mapTOC
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function stringifyTOC(obj, level) { ++level; var buf = ''; var link; for (var key in obj) { if ('suite' == key) continue; if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n'; if (key) buf += Array(level).join(' ') + link; buf += stringifyTOC(obj[key], level); } --level; return buf; }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
stringifyTOC
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function generateTOC(suite) { var obj = mapTOC(suite, {}); return stringifyTOC(obj, 0); }
Initialize a new `Markdown` reporter. @param {Runner} runner @api public
generateTOC
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Min(runner) { Base.call(this, runner); runner.on('start', function(){ // clear screen process.stdout.write('\u001b[2J'); // set cursor position process.stdout.write('\u001b[1;3H'); }); runner.on('end', this.epilogue.bind(this)); }
Initialize a new `Min` minimal test reporter (best used with --watch). @param {Runner} runner @api public
Min
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function NyanCat(runner) { Base.call(this, runner); var self = this , stats = this.stats , width = Base.window.width * .75 | 0 , rainbowColors = this.rainbowColors = self.generateColors() , colorIndex = this.colorIndex = 0 , numerOfLines = this.numberOfLines = 4 , trajectories = this.trajectories = [[], [], [], []] , nyanCatWidth = this.nyanCatWidth = 11 , trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth) , scoreboardWidth = this.scoreboardWidth = 5 , tick = this.tick = 0 , n = 0; runner.on('start', function(){ Base.cursor.hide(); self.draw(); }); runner.on('pending', function(test){ self.draw(); }); runner.on('pass', function(test){ self.draw(); }); runner.on('fail', function(test, err){ self.draw(); }); runner.on('end', function(){ Base.cursor.show(); for (var i = 0; i < self.numberOfLines; i++) write('\n'); self.epilogue(); }); }
Initialize a new `Dot` matrix test reporter. @param {Runner} runner @api public
NyanCat
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function draw(color, n) { write(' '); write('\u001b[' + color + 'm' + n + '\u001b[0m'); write('\n'); }
Draw the "scoreboard" showing the number of passes, failures and pending tests. @api private
draw
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function indent() { return Array(indents).join(' ') }
Initialize a new `Spec` test reporter. @param {Runner} runner @api public
indent
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function TAP(runner) { Base.call(this, runner); var self = this , stats = this.stats , n = 1 , passes = 0 , failures = 0; runner.on('start', function(){ var total = runner.grepTotal(runner.suite); console.log('%d..%d', 1, total); }); runner.on('test end', function(){ ++n; }); runner.on('pending', function(test){ console.log('ok %d %s # SKIP -', n, title(test)); }); runner.on('pass', function(test){ passes++; console.log('ok %d %s', n, title(test)); }); runner.on('fail', function(test, err){ failures++; console.log('not ok %d %s', n, title(test)); if (err.stack) console.log(err.stack.replace(/^/gm, ' ')); }); runner.on('end', function(){ console.log('# tests ' + (passes + failures)); console.log('# pass ' + passes); console.log('# fail ' + failures); }); }
Initialize a new `TAP` reporter. @param {Runner} runner @api public
TAP
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function title(test) { return test.fullTitle().replace(/#/g, ''); }
Return a TAP-safe title of `test` @param {Object} test @return {String} @api private
title
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function XUnit(runner) { Base.call(this, runner); var stats = this.stats , tests = [] , self = this; runner.on('pass', function(test){ tests.push(test); }); runner.on('fail', function(test){ tests.push(test); }); runner.on('end', function(){ console.log(tag('testsuite', { name: 'Mocha Tests' , tests: stats.tests , failures: stats.failures , errors: stats.failures , skipped: stats.tests - stats.failures - stats.passes , timestamp: (new Date).toUTCString() , time: (stats.duration / 1000) || 0 }, false)); tests.forEach(test); console.log('</testsuite>'); }); }
Initialize a new `XUnit` reporter. @param {Runner} runner @api public
XUnit
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function test(test) { var attrs = { classname: test.parent.fullTitle() , name: test.title , time: test.duration / 1000 }; if ('failed' == test.state) { var err = test.err; attrs.message = escape(err.message); console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack)))); } else if (test.pending) { console.log(tag('testcase', attrs, false, tag('skipped', {}, true))); } else { console.log(tag('testcase', attrs, true) ); } }
Output tag for the given `test.`
test
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Runnable(title, fn) { this.title = title; this.fn = fn; this.async = fn && fn.length; this.sync = ! this.async; this._timeout = 2000; this._slow = 75; this.timedOut = false; }
Initialize a new `Runnable` with the given `title` and callback `fn`. @param {String} title @param {Function} fn @api private
Runnable
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function multiple(err) { if (emitted) return; emitted = true; self.emit('error', err || new Error('done() called multiple times')); }
Run the test and invoke `fn(err)`. @param {Function} fn @api private
multiple
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function done(err) { if (self.timedOut) return; if (finished) return multiple(err); self.clearTimeout(); self.duration = new Date - start; finished = true; fn(err); }
Run the test and invoke `fn(err)`. @param {Function} fn @api private
done
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Runner(suite) { var self = this; this._globals = []; this.suite = suite; this.total = suite.total(); this.failures = 0; this.on('test end', function(test){ self.checkGlobals(test); }); this.on('hook end', function(hook){ self.checkGlobals(hook); }); this.grep(/.*/); this.globals(this.globalProps().concat(['errno'])); }
Initialize a `Runner` for the given `suite`. Events: - `start` execution started - `end` execution complete - `suite` (suite) test suite execution started - `suite end` (suite) all tests (and sub-suites) have finished - `test` (test) test execution started - `test end` (test) test completed - `hook` (hook) hook execution started - `hook end` (hook) hook complete - `pass` (test) test passed - `fail` (test, err) test failed - `pending` (test) test pending @api public
Runner
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next(i) { var hook = hooks[i]; if (!hook) return fn(); if (self.failures && suite.bail()) return fn(); self.currentRunnable = hook; hook.ctx.currentTest = self.test; self.emit('hook', hook); hook.on('error', function(err){ self.failHook(hook, err); }); hook.run(function(err){ hook.removeAllListeners('error'); var testError = hook.error(); if (testError) self.fail(self.test, testError); if (err) return self.failHook(hook, err); self.emit('hook end', hook); delete hook.ctx.currentTest; next(++i); }); }
Run hook `name` callbacks and then invoke `fn()`. @param {String} name @param {Function} function @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next(suite) { self.suite = suite; if (!suite) { self.suite = orig; return fn(); } self.hook(name, function(err){ if (err) { self.suite = orig; return fn(err); } next(suites.pop()); }); }
Run hook `name` for the given array of `suites` in order, and callback `fn(err)`. @param {String} name @param {Array} suites @param {Function} fn @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next(err) { // if we bail after first err if (self.failures && suite._bail) return fn(); // next test test = tests.shift(); // all done if (!test) return fn(); // grep var match = self._grep.test(test.fullTitle()); if (self._invert) match = !match; if (!match) return next(); // pending if (test.pending) { self.emit('pending', test); self.emit('test end', test); return next(); } // execute test and hook(s) self.emit('test', self.test = test); self.hookDown('beforeEach', function(){ self.currentRunnable = self.test; self.runTest(function(err){ test = self.test; if (err) { self.fail(test, err); self.emit('test end', test); return self.hookUp('afterEach', next); } test.state = 'passed'; self.emit('pass', test); self.emit('test end', test); self.hookUp('afterEach', next); }); }); }
Run tests in the given `suite` and invoke the callback `fn()` when complete. @param {Suite} suite @param {Function} fn @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function next() { var curr = suite.suites[i++]; if (!curr) return done(); self.runSuite(curr, next); }
Run the given `suite` and invoke the callback `fn()` when complete. @param {Suite} suite @param {Function} fn @api private
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function done() { self.suite = suite; self.hook('afterAll', function(){ self.emit('suite end', suite); fn(); }); }
Run the given `suite` and invoke the callback `fn()` when complete. @param {Suite} suite @param {Function} fn @api private
done
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function filterLeaks(ok, globals) { return filter(globals, function(key){ // Firefox and Chrome exposes iframes as index inside the window object if (/^d+/.test(key)) return false; // in firefox // if runner runs in an iframe, this iframe's window.getInterface method not init at first // it is assigned in some seconds if (global.navigator && /^getInterface/.test(key)) return false; // an iframe could be approached by window[iframeIndex] // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak if (global.navigator && /^\d+/.test(key)) return false; // Opera and IE expose global variables for HTML element IDs (issue #243) if (/^mocha-/.test(key)) return false; var matched = filter(ok, function(ok){ if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]); return key == ok; }); return matched.length == 0 && (!global.navigator || 'onerror' !== key); }); }
Filter leaks with the given globals flagged as `ok`. @param {Array} ok @param {Array} globals @return {Array} @api private
filterLeaks
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Suite(title, ctx) { this.title = title; this.ctx = ctx; this.suites = []; this.tests = []; this.pending = false; this._beforeEach = []; this._beforeAll = []; this._afterEach = []; this._afterAll = []; this.root = !title; this._timeout = 2000; this._slow = 75; this._bail = false; }
Initialize a new `Suite` with the given `title` and `ctx`. @param {String} title @param {Context} ctx @api private
Suite
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function Test(title, fn) { Runnable.call(this, title, fn); this.pending = !fn; this.type = 'test'; }
Initialize a new `Test` with the given `title` and callback `fn`. @param {String} title @param {Function} fn @api private
Test
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
function highlight(js) { return js .replace(/</g, '&lt;') .replace(/>/g, '&gt;') .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>') .replace(/('.*?')/gm, '<span class="string">$1</span>') .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>') .replace(/(\d+)/gm, '<span class="number">$1</span>') .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>') .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>') }
Highlight the given string of `js`. @param {String} js @return {String} @api private
highlight
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/mocha.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/mocha.js
MIT
errorString = function( error ) { var name, message, errorString = error.toString(); if ( errorString.substring( 0, 7 ) === "[object" ) { name = error.name ? error.name.toString() : "Error"; message = error.message ? error.message.toString() : ""; if ( name && message ) { return name + ": " + message; } else if ( name ) { return name; } else if ( message ) { return message; } else { return "Error"; } } else { return errorString; } }
Provides a normalized error string, correcting an issue with IE 7 (and prior) where Error.prototype.toString is not properly implemented Based on http://es5.github.com/#x15.11.4.4 @param {String|Error} error @return {String} error message
errorString
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
objectValues = function( obj ) { // Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392. /*jshint newcap: false */ var key, val, vals = QUnit.is( "array", obj ) ? [] : {}; for ( key in obj ) { if ( hasOwn.call( obj, key ) ) { val = obj[key]; vals[key] = val === Object(val) ? objectValues(val) : val; } } return vals; }
Makes a clone of an object using only Array or Object as base, and copies over the own enumerable properties. @param {Object} obj @return {Object} New object with only the own properties (recursively).
objectValues
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function validTest( test ) { var include, filter = config.filter && config.filter.toLowerCase(), module = config.module && config.module.toLowerCase(), fullName = ( test.module + ": " + test.testName ).toLowerCase(); // Internally-generated tests are always valid if ( test.callback && test.callback.validTest === validTest ) { delete test.callback.validTest; return true; } if ( config.testNumber.length > 0 ) { if ( inArray( test.testNumber, config.testNumber ) < 0 ) { return false; } } if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { return false; } if ( !filter ) { return true; } include = filter.charAt( 0 ) !== "!"; if ( !include ) { filter = filter.slice( 1 ); } // If the filter matches, we need to honour include if ( fullName.indexOf( filter ) !== -1 ) { return include; } // Otherwise, do the opposite return !include; }
@return Boolean: true if this test should be ran
validTest
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function extractStacktrace( e, offset ) { offset = offset === undefined ? 3 : offset; var stack, include, i; if ( e.stacktrace ) { // Opera return e.stacktrace.split( "\n" )[ offset + 3 ]; } else if ( e.stack ) { // Firefox, Chrome stack = e.stack.split( "\n" ); if (/^error$/i.test( stack[0] ) ) { stack.shift(); } if ( fileName ) { include = []; for ( i = offset; i < stack.length; i++ ) { if ( stack[ i ].indexOf( fileName ) !== -1 ) { break; } include.push( stack[ i ] ); } if ( include.length ) { return include.join( "\n" ); } } return stack[ offset ]; } else if ( e.sourceURL ) { // Safari, PhantomJS // hopefully one day Safari provides actual stacktraces // exclude useless self-reference for generated Error objects if ( /qunit.js$/.test( e.sourceURL ) ) { return; } // for actual exceptions, this is useful return e.sourceURL + ":" + e.line; } }
@return Boolean: true if this test should be ran
extractStacktrace
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function sourceFromStacktrace( offset ) { try { throw new Error(); } catch ( e ) { return extractStacktrace( e, offset ); } }
@return Boolean: true if this test should be ran
sourceFromStacktrace
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function escapeText( s ) { if ( !s ) { return ""; } s = s + ""; // Both single quotes and double quotes (for attributes) return s.replace( /['"<>&]/g, function( s ) { switch( s ) { case "'": return "&#039;"; case "\"": return "&quot;"; case "<": return "&lt;"; case ">": return "&gt;"; case "&": return "&amp;"; } }); }
Escape text for attribute or text content.
escapeText
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function synchronize( callback, last ) { config.queue.push( callback ); if ( config.autorun && !config.blocking ) { process( last ); } }
Escape text for attribute or text content.
synchronize
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function process( last ) { function next() { process( last ); } var start = new Date().getTime(); config.depth = config.depth ? config.depth + 1 : 1; while ( config.queue.length && !config.blocking ) { if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { config.queue.shift()(); } else { setTimeout( next, 13 ); break; } } config.depth--; if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { done(); } }
Escape text for attribute or text content.
process
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function next() { process( last ); }
Escape text for attribute or text content.
next
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function saveGlobal() { config.pollution = []; if ( config.noglobals ) { for ( var key in window ) { if ( hasOwn.call( window, key ) ) { // in Opera sometimes DOM element ids show up here, ignore them if ( /^qunit-test-output/.test( key ) ) { continue; } config.pollution.push( key ); } } } }
Escape text for attribute or text content.
saveGlobal
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function checkPollution() { var newGlobals, deletedGlobals, old = config.pollution; saveGlobal(); newGlobals = diff( config.pollution, old ); if ( newGlobals.length > 0 ) { QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); } deletedGlobals = diff( old, config.pollution ); if ( deletedGlobals.length > 0 ) { QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); } }
Escape text for attribute or text content.
checkPollution
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function diff( a, b ) { var i, j, result = a.slice(); for ( i = 0; i < result.length; i++ ) { for ( j = 0; j < b.length; j++ ) { if ( result[i] === b[j] ) { result.splice( i, 1 ); i--; break; } } } return result; }
Escape text for attribute or text content.
diff
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function extend( a, b ) { for ( var prop in b ) { if ( hasOwn.call( b, prop ) ) { // Avoid "Member not found" error in IE8 caused by messing with window.constructor if ( !( prop === "constructor" && a === window ) ) { if ( b[ prop ] === undefined ) { delete a[ prop ]; } else { a[ prop ] = b[ prop ]; } } } } return a; }
Escape text for attribute or text content.
extend
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function addEvent( elem, type, fn ) { if ( elem.addEventListener ) { // Standards-based browsers elem.addEventListener( type, fn, false ); } else if ( elem.attachEvent ) { // support: IE <9 elem.attachEvent( "on" + type, fn ); } else { // Caller must ensure support for event listeners is present throw new Error( "addEvent() was called in a context without event listener support" ); } }
@param {HTMLElement} elem @param {string} type @param {Function} fn
addEvent
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function addEvents( elems, type, fn ) { var i = elems.length; while ( i-- ) { addEvent( elems[i], type, fn ); } }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
addEvents
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function hasClass( elem, name ) { return (" " + elem.className + " ").indexOf(" " + name + " ") > -1; }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
hasClass
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function addClass( elem, name ) { if ( !hasClass( elem, name ) ) { elem.className += (elem.className ? " " : "") + name; } }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
addClass
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function removeClass( elem, name ) { var set = " " + elem.className + " "; // Class name may appear multiple times while ( set.indexOf(" " + name + " ") > -1 ) { set = set.replace(" " + name + " " , " "); } // If possible, trim it for prettiness, but not necessarily elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, ""); }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
removeClass
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function id( name ) { return defined.document && document.getElementById && document.getElementById( name ); }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
id
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function registerLoggingCallback( key ) { return function( callback ) { config[key].push( callback ); }; }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
registerLoggingCallback
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function runLoggingCallbacks( key, scope, args ) { var i, callbacks; if ( QUnit.hasOwnProperty( key ) ) { QUnit[ key ].call(scope, args ); } else { callbacks = config[ key ]; for ( i = 0; i < callbacks.length; i++ ) { callbacks[ i ].call( scope, args ); } } }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
runLoggingCallbacks
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function inArray( elem, array ) { if ( array.indexOf ) { return array.indexOf( elem ); } for ( var i = 0, length = array.length; i < length; i++ ) { if ( array[ i ] === elem ) { return i; } } return -1; }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
inArray
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function Test( settings ) { extend( this, settings ); this.assertions = []; this.testNumber = ++Test.count; }
@param {Array|NodeList} elems @param {string} type @param {Function} fn
Test
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function run() { // each of these can by async synchronize(function() { test.setup(); }); synchronize(function() { test.run(); }); synchronize(function() { test.teardown(); }); synchronize(function() { test.finish(); }); }
Expose the current test environment. @deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead.
run
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function bindCallbacks( o, callbacks, args ) { var prop = QUnit.objectType( o ); if ( prop ) { if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { return callbacks[ prop ].apply( callbacks, args ); } else { return callbacks[ prop ]; // or undefined } } }
@deprecated since 1.0.0, replaced with error pushes since 1.3.0 Kept to avoid TypeErrors for undefined methods.
bindCallbacks
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function useStrictEquality( b, a ) { /*jshint eqeqeq:false */ if ( b instanceof a.constructor || a instanceof b.constructor ) { // to catch short annotation VS 'new' annotation of a // declaration // e.g. var i = 1; // var j = new Number(1); return a == b; } else { return a === b; } }
@deprecated since 1.0.0, replaced with error pushes since 1.3.0 Kept to avoid TypeErrors for undefined methods.
useStrictEquality
javascript
alibaba/f2etest
f2etest-web/public/demo/lib/qunit-1.14.0.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/demo/lib/qunit-1.14.0.js
MIT
function jscoverage_init(w) { try { // in Safari, "import" is a syntax error Components.utils['import']('resource://app/modules/jscoverage.jsm'); jscoverage_isInvertedMode = true; return; } catch (e) {} // check if we are in inverted mode if (w.opener) { try { if (w.opener.top._$jscoverage) { jscoverage_isInvertedMode = true; if (! w._$jscoverage) { w._$jscoverage = w.opener.top._$jscoverage; } } else { jscoverage_isInvertedMode = false; } } catch (e) { try { if (w.opener._$jscoverage) { jscoverage_isInvertedMode = true; if (! w._$jscoverage) { w._$jscoverage = w.opener._$jscoverage; } } else { jscoverage_isInvertedMode = false; } } catch (e2) { jscoverage_isInvertedMode = false; } } } else { jscoverage_isInvertedMode = false; } if (! jscoverage_isInvertedMode) { if (! w._$jscoverage) { w._$jscoverage = {}; } } }
Initializes the _$jscoverage object in a window. This should be the first function called in the page. @param w this should always be the global window object
jscoverage_init
javascript
alibaba/f2etest
f2etest-web/public/jscover/jscoverage.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/jscover/jscoverage.js
MIT
function jscoverage_createRequest() { // Note that the IE7 XMLHttpRequest does not support file URL's. // http://xhab.blogspot.com/2006/11/ie7-support-for-xmlhttprequest.html // http://blogs.msdn.com/ie/archive/2006/12/06/file-uris-in-windows.aspx //#JSCOVERAGE_IF if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { return new XMLHttpRequest(); } }
Initializes the _$jscoverage object in a window. This should be the first function called in the page. @param w this should always be the global window object
jscoverage_createRequest
javascript
alibaba/f2etest
f2etest-web/public/jscover/jscoverage.js
https://github.com/alibaba/f2etest/blob/master/f2etest-web/public/jscover/jscoverage.js
MIT