【问题标题】:jasmine-maven-plugin + phantomJS : Error: [$injector:nomod]jasmine-maven-plugin + phantomJS:错误:[$injector:nomod]
【发布时间】:2015-04-28 13:08:19
【问题描述】:

我创建了一个项目:

mvn archetype:generate -DarchetypeGroupId=com.github.searls -DarchetypeArtifactId=jasmine-archetype -DarchetypeVersion=1.3.1.5 -DgroupId=com.acme -DartifactId=my-jasmine-project -Dversion=0.0.1-SNAPSHOT

首先我用 mvn jasmine:test 进行测试,测试运行正常。

注意:我使用 maven 3.2.1

在“目标”目录中,我添加了一个文件夹“phantomjs-1.9.7-windows”,其中放置了“phantomjs.exe”

我修改了我原来的 pom.xml 来添加

                ...
    <configuration>
        <srcDirectoryName>${project.artifactId}/src/main/javascript</srcDirectoryName>
        <webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
        <webDriverCapabilities>
            <capability>
                <name>phantomjs.binary.path</name>
                <value>${project.build.directory}/phantomjs-1.9.7-${os.phantomJS}/${run.phantomJS}</value>
            </capability>
        </webDriverCapabilities>


        <preloadSources>
            <source>${project.basedir}/src/main/javascript/libs/jquery-1.9.1.js</source>
            <source>${project.basedir}/src/main/javascript/libs/angular.js</source>
            <source>${project.basedir}/src/main/javascript/libs/angular-ui-router.js</source>
            <source>${project.basedir}/src/main/javascript/libs/angular-resource.js</source>
        </preloadSources>
    </configuration>
    ...

我在“src/main/javascript”下创建了一个文件夹“libs”并将其放入: - jquery-1.9.1.js - 角.js - 角度-ui-router.js - 角资源.js

注意:angular 版本为 1.2.23

之后,我在“src/main/javascript”下创建了另一个文件夹“app”并将其放入:“app.module.js”

(function() {
    'use strict';

    angular.module('app', [
         'app.Security.modules'
    ]);
})();

在“src/main/javascript/app”下,我创建了一个文件夹“security”并将其放入:“security.module.js”

(function() {
'use strict';
    angular.module('app.Security.modules', []);
})();

和“cha_directive.js”

angular.module('app.Security.modules').directive('inputOld', InputAccessKeyManagement);
function InputAccessKeyManagement () {}

如果我使用 mvn jasmine:test 进行测试,我会得到一个错误:

[ERROR - 2015-02-26T08:12:49.751Z] Session [40eacc20-bd8f-11e4-a736-9934c466a5ff] - page.onError - stack:
  (anonymous function) (http://localhost:51170/jasmine-project/src/main/javascript/libs/angular.js:1679)
  ensure (http://localhost:51170/jasmine-project/src/main/javascript/libs/angular.js:1601)
  module (http://localhost:51170/jasmine-project/src/main/javascript/libs/angular.js:1892)
  (anonymous function) (http://localhost:51170/jasmine-project/src/main/javascript/app/security/cha_directive.js:1)
[WARNING] JavaScript Console Errors:

  * Error: [$injector:nomod] Module 'app.Security.modules' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.23/$injector/nomod?p0=app.Security.modules


[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.163s
[INFO] Finished at: Thu Feb 26 09:12:49 CET 2015
[INFO] Final Memory: 12M/210M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.searls:jasmine-maven-plugin:1.3.1.5:test (default-cli) on project jasmine-project: The jasmine-maven-plugin encountered an exception:
[ERROR] java.lang.RuntimeException: java.lang.RuntimeException: There were javascript console errors.
[ERROR] at com.github.searls.jasmine.runner.SpecRunnerExecutor.execute(SpecRunnerExecutor.java:46)
[ERROR] at com.github.searls.jasmine.mojo.TestMojo.executeSpecs(TestMojo.java:86)

如果我只是重命名“cha_directive.js”in“toto_directive.js”(使用相同的源代码)并运行mvn jasmine:test 再次测试正常运行。

如果我使用“cha_directive.js”名称文件并运行mvn jasmine:bdd。之后我在 FF 中运行 url http://localhost:8234 测试运行正常。

唯一的事情(如果我用 fireBug 编辑“Jasmine Spec Runner”的 HTML 代码)是我可以看到这个标签:

<head jmp_jserror="Error: [$injector:nomod] Module 'app.Security.modules' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.2.23/$injector/nomod?p0=app.Security.modules">

如果我在“checkForConsoleErrors”中查看 SpecRunnerExecutor.java 类,就会有一个测试:

WebElement head = driver.findElement(By.tagName("head"));
if (head != null) {
    String jserrors = head.getAttribute("jmp_jserror");
    if (StringUtils.isNotBlank(jserrors)) {
        throw new RuntimeException("There were javascript console errors.");
    }
}

注意:其他文件名会使测试崩溃:input_directive.js、accessKey_directive.js、...

【问题讨论】:

    标签: angularjs maven phantomjs jasmine-maven-plugin


    【解决方案1】:

    是导入脚本顺序的问题。

    我声明

    (function() {
       'use strict';
       angular.module('app.Security.modules', []);
    })();
    

    在名为“security.module.js”的文件中

    我尝试使用我的声明

    angular.module('app.Security.modules')
      .directive('inputOld', InputAccessKeyManagement);
      function InputAccessKeyManagement () {}
    

    在名为“cha_directive.js”的文件中

    如果您未指定自定义导入脚本顺序,则默认顺序为字母顺序,则“cha_directive.js”在“security.module.js”之前.

    我使用“customRunnerTemplate”解决了这个问题。

    但也许还有另一种方法可以“更漂亮”?

    【讨论】:

      【解决方案2】:

      如果其他人遇到这种情况,一个好的解决方案是在您的 sourceInclude 块中执行类似的操作:

      <sourceInclude>
        <include>**/*.module.js</include>
        <include>**/*.controller.js</include>
        <include>**/*.service.js</include>
      ...
      

      等等。假设您符合将模块定义在一个名为“example.module.js”的文件中,则模块将首先加载,然后是控制器,等等

      【讨论】:

        猜你喜欢
        • 2013-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-12
        相关资源
        最近更新 更多