如何解决在Jenkins上运行的Karma单元测试中的这个错误:"找不到变量:jQuery"

问题描述 投票:0回答:1

我已经添加了 可排序 库到一个 AngularJS 项目中,以实现无序列表的拖放功能。该项目使用 bower 来管理 UI 库,bower.json 包含了 jquery 和 jquery-ui

{
  "name": "fountain-inject",
  "version": "0.0.1",
  "dependencies": {
    "jquery": "3.5.1",
    "jquery-ui": "1.12.1",
    "angular": "1.7.9"
  }
}

当在Windows上本地构建时,所有的单元测试都通过了,但是当在Linux上的Jenkins中构建时,所有的单元测试都通过了,但是却报告了这个错误,构建失败。

[INFO] PhantomJS 2.1.1 (Linux 0.0.0) ERROR
[INFO]   An error was thrown in afterAll
[INFO]   ReferenceError: Can't find variable: jQuery
[INFO]   bower_components/jquery-ui/jquery-ui.js:14
[INFO] PhantomJS 2.1.1 (Linux 0.0.0): Executed 741 of 742 (skipped 1) ERROR (13.945 secs / 13.232 secs)

构建本身是一个多模块maven项目的前端模块。它使用了 前端Maven插件 安装node,拉出bower和node的依赖关系,然后运行gulp构建文件,包括单元测试。

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>install node and npm</id>
            <goals>
                <goal>install-node-and-npm</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <nodeVersion>v12.13.1</nodeVersion>
            </configuration>
        </execution>

        <execution>
            <id>npm install</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <arguments>install</arguments>
            </configuration>
        </execution>

        <execution>
            <id>bower install</id>
            <goals>
                <goal>bower</goal>
            </goals>
            <configuration>
                <arguments>install</arguments>
            </configuration>
        </execution>

        <execution>
            <id>gulp build</id>
            <goals>
                <goal>gulp</goal>
            </goals>
            <phase>test-compile</phase>
            <configuration>
                <arguments>build</arguments>
            </configuration>
        </execution>

        <execution>
            <id>gulp test</id>
            <phase>test</phase>
            <goals>
                <goal>gulp</goal>
            </goals>
            <configuration>
                <arguments>test --no-notification</arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

有人知道如何解决这个问题吗?

jquery angularjs jenkins jquery-ui bower
1个回答
0
投票

当我将bower_componentsjQuery目录添加到版本库后,这个问题就解决了,并且构建完成。由于某些原因,构建机在从互联网上检索bower的依赖关系时出现了问题,但在构建本身所需的节点依赖关系方面却没有问题。

© www.soinside.com 2019 - 2024. All rights reserved.