1

升级到 gulp-mocha-phantomjs 版本 0.8.0 后,我遇到了一些问题:

1) 通过 url 对远程运行时出错:

针对远程 URL 运行测试时,出现以下错误:

ReferenceError: Can't find variable: Mocha
   at browser-shim.js:27

runner.html 中的所有必需文件似乎都可用,并且测试在 FF 或 Chrome 等实际浏览器中按预期工作。

亚军.html:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Mocha Test Runner</title>
        <link rel="stylesheet" href="HTTP://localhost:7777/q/p/lj_unittest/test/mocha.css">
        <link rel="stylesheet" href="HTTP://localhost:7777/q/p/lj_unittest/css/core.css">
    </head>
    <body>
        <div id="mocha"></div>

        <div id="fixture" style="display:none;">
            <div id="charset_ascii"> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</div>
            <div id="charset_other">ÄäÆæß</div>
        </div>

        <script src="HTTP://localhost:7777/q/p/lj_unittest/js/core.js"></script>
        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/mocha.js"></script>
        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/chai.js"></script>
        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/chai-datetime.js"></script>
        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/sinon.js"></script>

        <script>
            mocha.setup("bdd");
        </script>

        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/backend/ods/charset_backend.js"></script>
        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/backend/ods/ods.log_backend.js"></script>
        <script src="HTTP://localhost:7777/q/p/lj_unittest/test/backend/ods/date.js"></script>

        <script>
            mocha.run();
        </script>
    </body>
</html>

Gulpfile.js:

gulp.task('test:backend:ODS', function (/ callback /) { var stream = mochaPhantomJS({'reporter': 'spec'});

stream.write({path: config.URL_ROOT + '/TEST_WEB_ODS.main'});
stream.end();

return stream;

});

2)一些(但不是全部)runner.html基于测试的奇怪警告:

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///D:/MyDev/ljs_app/trunk/periscope/build/node_modules/gulp-mocha-phant
mjs/node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js. Domains, protocols and ports must match.

亚军.html:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Mocha Test Runner</title>
        <link rel="stylesheet" href="../../../libs/mocha/mocha.css">
        <link rel="stylesheet" href="../../../dist/css/core.css">
    </head>
    <body>
        <div id="mocha"></div>
        <div id="fixture" style="display:none;"></div>
        <script src="../../../dist/js/core.js"></script>
        <script src="../../../libs/mocha/mocha.js"></script>
        <script src="../../../libs/chai/chai.js"></script>
        <script src="../../../libs/chai/chai-datetime.js"></script>
        <script src="../../../libs/sinon/sinon.js"></script>

        <script>
            mocha.setup('bdd');
        </script>

        <!-- START of actual unit test scripts -->
        <script src="./json.js"></script>
        <script src="./moment.js"></script>
        <script src="./underscore.js"></script>
        <!-- END of actual unit test scripts -->

        <script>
            mocha.run();
        </script>
    </body>
</html>

Gulpfile.js:

gulp.task('test:frontend:lib', function (/*callback*/) {
    return gulp.src('test/frontend/lib/runner.html').pipe(mochaPhantomJS({'reporter': 'spec'}));
});

任何帮助表示赞赏!

4

1 回答 1

0

先加载mocha.js。你自己的评论是正确的。

相关: ReferenceError:找不到变量:运行测试时的 Mocha · 问题 #7 · nathanboktae/mocha-phantomjs-core

于 2015-08-22T19:23:59.890 回答