PhantomJS - 使用 System.import 加载 js 文件时出错

PhantomJS - error loading js file using System.import

这里有一个问题:我正在使用 phamtomJS 2.1.1,我想打开我的网页,该网页是用 reactJS + typescript 编写的,我在 System.import 期间收到异常。

代码 index.html:

<div id="__Mount"></div>

<script src="lib/systemjs/dist/system.src.js"></script>
<script src="lib/react/dist/phantomjs-shims.js"></script>

<!-- build:js -->
<!-- endbuild -->

<!-- build:systemjs_config -->
<script>
    System.config({
        baseURL: './lib',
        paths: {
            "react*": 'react/dist/react-with-addons', 
            "react-dom": 'react-dom/dist/react-dom',
            "jquery": 'kendoui/js/jquery.min',
            "bootstrap": 'bootstrap/dist/js/npm'
        }
    });

    System.defaultJSExtensions = true;
</script>
<!-- endbuild -->

<script>
    System.import('client/mount').catch(function(e)
    {
        console.error(e);
    });
</script>

mount.tsx代码:

import * as React from 'react';
import * as ReactDOM from 'react-dom';

import {App} from './app';

ReactDOM.render(<App/>, document.querySelector("#__Mount"));

还有一个 app.tsx,其中包含页面上应包含的所有逻辑。 我使用以下命令从控制台 运行 phantomjs:

phantomjs test.js http://127.0.0.1:8080

哪个给我错误:

ERROR: Error: (SystemJS) eval@[native code] __exec@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:1544:18 execute@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:4005:22 linkDynamicModule@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:3281:36 link@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:3124:28 execute@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:3491:17 doDynamicExecute@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:774:32 link@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:972:36 doLink@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:631:11 updateLinkSetOnLoad@http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:677:24 http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:493:30 Evaluating http://127.0.0.1:8080/lib/client/mount.js Error loading http://127.0.0.1:8080/lib/client/mount.js

test.js代码:

var page = require('webpage').create();
page.onError = function(msg) {
    console.log("On error message "+msg);
};
page.open('http://127.0.0.1:8080/', function (status) {
    console.log("status is: " + status);
    if (status === "success") {
        console.log("success");
        setTimeout(function () {
            console.log("screenshot");
            page.render('screenshot.png');

            var js = page.evaluate(function () {
                return document;
            });
            console.log(js.all[0].outerHTML);

            phantom.exit();

        }, 10000);
    }
    else {
        console.log("not success");
        phantom.exit();
    }
});

实在是看不下去了,找不到办法。任何帮助或提示将不胜感激。

根据 github 上的问题尚不支持此功能:https://github.com/ariya/phantomjs/issues/14515

所以我决定选择 electron http://electron.atom.io/ 现在它对我来说工作正常,它启动我的单元测试而不显示 UI - 完美。