升级版本 0.8.0 后 gulp-mocha-phantomjs 的问题

Problems with gulp-mocha-phantomjs after upgrade version 0.8.0

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

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

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

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

runner.html 中的所有必需文件似乎都可用,并且测试在 FF 或 Chrome.

等实际浏览器中确实按预期工作

runner.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',函数(/回调/){ 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.

runner.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'}));
});

感谢任何帮助!

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

相关: ReferenceError: Can't find variable: Mocha when running test · Issue #7 · nathanboktae/mocha-phantomjs-core