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

时间:2015-07-22 07:35:05

标签: phantomjs gulp mocha mocha-phantomjs

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

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

对远程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(&#39;测试:后端:ODS&#39;,功能(/ 回调 /){     var stream = mochaPhantomJS({&#39;记者&#39;:&#39; spec&#39;});

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

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)