【问题标题】:Jasmine Maven Plugin including my scripts using file protocolJasmine Maven 插件,包括我使用文件协议的脚本
【发布时间】:2012-08-07 09:57:37
【问题描述】:

我正在尝试将 javascript 单元测试添加到我们的项目中,并发现了 Jasmine Maven Plugin。我按照指示在我的 pom.xml 中结束了这个:

<plugin>
    <groupId>com.github.searls</groupId>
    <artifactId>jasmine-maven-plugin</artifactId>
    <version>1.2.0.0</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <jsSrcDir>${project.basedir}/src/main/webapp/resources/js</jsSrcDir>
        <jsTestSrcDir>${project.basedir}/src/test/javascript</jsTestSrcDir>
    </configuration>
</plugin>

我运行mvn jasmine:bdd 并获得预期的输出。然后我转到http://localhost:8234,我得到的只是一个空白屏幕。我查看控制台并查看我的每个 js 文件:

Not allowed to load local resource: file:///absolute/path/to/the/js/src/main/webapp/resources/js/myJS.js

页面的 HTML 包含我的脚本,如下所示:

<script type="text/javascript" src="file:/absolute/path/to/the/js/src/main/webapp/resources/js/myJS.js"></script>

所以我的问题是,为什么插件使用文件协议来包含 js?这是它通常的工作方式吗?如果是这样,我如何让我的浏览器允许本地资源?有什么办法阻止它这样做吗?

为了以防万一,我在 Firefox 和 Chrome 上都试过了,我使用的是 OS X。

【问题讨论】:

    标签: javascript jasmine jasmine-maven-plugin


    【解决方案1】:

    我最近遇到了这个问题,问题是我的项目所在的目录中有空格。

    这是在 Windows 上,但在 OSX 上可能是一样的,所以值得一试。

    例如,我的项目位于这样的目录中:

    C:\directory with spaces\myproject

    将其更改为以下修复了jasmine:bdd 命令:

    C:\directorywithoutspaces\myproject

    祝你好运!

    【讨论】:

    • 这正是我的问题所在!我把空间拿出来,现在效果很好。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多