⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecmaunit.js

📁 sarissa用于支持多浏览器的浏览及编程
💻 JS
📖 第 1 页 / 共 2 页
字号:
    this._tests.push(test);};TestSuite.prototype.runSuite = function() {    /* run the suite */    var now = new Date();    var starttime = now.getTime();    var testsran = 0;    for (var i=0; i < this._tests.length; i++) {        var test = new this._tests[i]();        test.initialize(this._reporter);        testsran += test._runHelper()[0];        // the TestCase class handles output of dots and Fs, but we        // should take care of the exceptions        if (test._exceptions.length) {            for (var j=0; j < test._exceptions.length; j++) {                // attr, exc in the org array, so here it becomes                // name, attr, exc                var excinfo = test._exceptions[j];                this._exceptions.push(excinfo);            };        };    };    var now = new Date();    var totaltime = now.getTime() - starttime;    this._reporter.summarize(testsran, totaltime, this._exceptions);};function StdoutReporter(verbose) {    if (verbose) {        this.verbose = verbose;    };};StdoutReporter.prototype.debug = function(text) {    print(text+"\n");}StdoutReporter.prototype.reportSuccess = function(testcase, attr) {    /* report a test success */    if (this.verbose) {        print(testcase + '.' + attr + '(): OK');    } else {        print('.');    };};StdoutReporter.prototype.reportError = function(testcase, attr,                                                 exception, raw) {    /* report a test failure */    if (this.verbose) {        print(testcase + '.' + attr + '(): FAILED!');    } else {        print('F');    };};StdoutReporter.prototype.summarize = function(numtests, time, exceptions) {    print('\n' + numtests + ' tests ran in ' + time / 1000.0 +             ' seconds\n');    if (exceptions.length) {        for (var i=0; i < exceptions.length; i++) {            var testcase = exceptions[i][0];            var attr = exceptions[i][1];            var exception = exceptions[i][2];            var raw = exceptions[i][3];            print(testcase + '.' + attr + ', exception: ' + exception);            if (this.verbose) {                this._printStackTrace(raw);            };        };        print('NOT OK!');    } else {        print('OK!');    };};StdoutReporter.prototype._printStackTrace = function(exc) {    if (!exc.stack) {        print('no stacktrace available');        return;    };    var lines = exc.stack.toString().split('\n');    var toprint = [];    for (var i=0; i < lines.length; i++) {        var line = lines[i];        if (line.indexOf('ecmaunit.js') > -1) {            // remove useless bit of traceback            break;        };        if (line.charAt(0) == '(') {            line = 'function' + line;        };        var chunks = line.split('@');        toprint.push(chunks);    };    toprint.reverse();    for (var i=0; i < toprint.length; i++) {        print('  ' + toprint[i][1]);        print('    ' + toprint[i][0]);    };    print();};function HTMLReporter(outputelement, verbose) {    if (outputelement) {        this.outputelement = outputelement;        this.document = outputelement.ownerDocument;        this.verbose = verbose;    };};HTMLReporter.prototype.debug = function(text) {    var msg = this.document.createTextNode(text);    var div = this.document.createElement('div');    div.appendChild(msg);    this.outputelement.appendChild(div);};HTMLReporter.prototype.reportSuccess = function(testcase, attr) {    /* report a test success */    // a single dot looks rather small    var dot = this.document.createTextNode('+');    this.outputelement.appendChild(dot);};HTMLReporter.prototype.reportError = function(testcase, attr, exception, raw) {    /* report a test failure */    var f = this.document.createTextNode('F');    this.outputelement.appendChild(f);};HTMLReporter.prototype.summarize = function(numtests, time, exceptions) {    /* write the result output to the html node */    var p = this.document.createElement('p');    var text = this.document.createTextNode(numtests + ' tests ran in ' +                                             time / 1000.0 + ' seconds');    p.appendChild(text);    this.outputelement.appendChild(p);    if (exceptions.length) {        for (var i=0; i < exceptions.length; i++) {            var testcase = exceptions[i][0];            var attr = exceptions[i][1];            var exception = exceptions[i][2].toString();            var raw = exceptions[i][3];            var div = this.document.createElement('div');            var lines = exception.toString().split('\n');            var text = this.document.createTextNode(                testcase + '.' + attr + ', exception ');            div.appendChild(text);            // add some formatting for Opera: this browser displays nice            // tracebacks...            for (var j=0; j < lines.length; j++) {                var text = lines[j];                if (j > 0) {                    text = '\xa0\xa0\xa0\xa0' + text;                };                div.appendChild(this.document.createTextNode(text));                div.appendChild(this.document.createElement('br'));            };            div.style.color = 'red';            this.outputelement.appendChild(div);            if (this.verbose) {                // display stack trace on Moz                this._displayStackTrace(raw);            };        };        var div = this.document.createElement('div');        var text = this.document.createTextNode('NOT OK!');        div.appendChild(text);        div.style.backgroundColor = 'red';        div.style.color = 'black';        div.style.fontWeight = 'bold';        div.style.textAlign = 'center';        div.style.marginTop = '1em';        this.outputelement.appendChild(div);    } else {        var div = this.document.createElement('div');        var text = this.document.createTextNode('OK!');        div.appendChild(text);        div.style.backgroundColor = 'lightgreen';        div.style.color = 'black';        div.style.fontWeight = 'bold';        div.style.textAlign = 'center';        div.style.marginTop = '1em';        this.outputelement.appendChild(div);    };};HTMLReporter.prototype._displayStackTrace = function(exc) {    /*    if (arguments.caller) {        // IE        var caller = arguments;        toprint = [];        while (caller) {            var callee = caller.callee.toString();            callee = callee.replace('\n', '').replace(/\s+/g, ' ');            var funcsig = /(.*?)\s*\{/.exec(callee)[1];            var args = caller.callee.arguments;            var displayargs = [];            for (var i=0; i < args.length; i++) {                displayargs.push(args[i].toString());            };            toprint.push((funcsig + ' - (' + displayargs + ')'));            caller = caller.caller;        };        toprint.reverse();        var pre = this.document.createElement('pre');        for (var i=0; i < toprint.length; i++) {            pre.appendChild(document.createTextNode(toprint[i]));            pre.appendChild(document.createElement('br'));        };        this.outputelement.appendChild(pre);    };    */    if (exc.stack) {        // Moz (sometimes)        var lines = exc.stack.toString().split('\n');        var toprint = []; // need to reverse this before outputting        for (var i=0; i < lines.length; i++) {            var line = lines[i];            if (line.indexOf('ecmaunit.js') > -1) {                // remove useless bit of traceback                break;            };            if (line[0] == '(') {                line = 'function' + line;            };            line = line.split('@');            toprint.push(line);        };        toprint.reverse();        var pre = this.document.createElement('pre');        for (var i=0; i < toprint.length; i++) {            pre.appendChild(                this.document.createTextNode(                    '  ' + toprint[i][1] + '\n    ' + toprint[i][0] + '\n'                )            );        };        pre.appendChild(document.createTextNode('\n'));        this.outputelement.appendChild(pre);    };};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -