如何在 Karma 单元测试中解决此错误,运行 Jenkins:"Can't find variable: jQuery"

How to resolve this error in a Karma unit test, running on Jenkins: "Can't find variable: jQuery"

我已将 ui-sortable 库添加到 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 本地的 built 时,所有单元测试都通过了,但是当 Linux 上的 Jenkins 中的 built 时,所有单元测试都通过了,但是随后报这个错误,build fails

[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)

build本身就是多模块maven项目的前端模块。它使用 frontend maven plugin 安装 node,拉取 bower 和 node 依赖项,然后 运行 a gulp build 文件,包括单元测试

<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>

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

当我将 bower_components/jQuery 目录添加到存储库并完成构建时,问题得到了解决。出于某种原因,构建机器在从 Internet 检索 Bower 依赖项时遇到问题,但在构建本身所需的节点依赖项方面没有问题。