安装 Axios 模块以与 Testcafe 一起使用(在 Docker 容器中)

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

我们想使用带有 Axios 模块的 Testcafe 进行 E2E 测试。我们使用安装了 Axios 的标准 Docker 镜像 Testcafe

npm install -g axios

测试文件位于文件夹

/tests
中。

经过几次不成功的尝试后,我进入容器并尝试手动开始测试:

使用命令运行测试 testcafe firefox:headless /tests/AA_API_create_user.js 返回错误:

ERROR Cannot prepare tests due to the following error:

Error: Cannot find module 'axios'
Require stack:
- /tests/AA_API_create_user.js
- /usr/local/lib/node_modules/testcafe/lib/compiler/test-file/formats/es-next/compiler.js
- /usr/local/lib/node_modules/testcafe/lib/compiler/compilers.js
- /usr/local/lib/node_modules/testcafe/lib/compiler/index.js
- /usr/local/lib/node_modules/testcafe/lib/runner/bootstrapper.js
- /usr/local/lib/node_modules/testcafe/lib/runner/index.js
- /usr/local/lib/node_modules/testcafe/lib/testcafe.js
- /usr/local/lib/node_modules/testcafe/lib/index.js
- /usr/local/lib/node_modules/testcafe/lib/cli/cli.js
- /usr/local/lib/node_modules/testcafe/lib/cli/index.js
    at Object.<anonymous> (/tests/AA_API_create_user.js:3:1)`

如果我尝试模块列表:

npm list -g

/usr/local/lib
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
-- [email protected]

如果我将 npm 模块安装到与测试相同的目录,则会发现 Axios:

cd /tests
npm install axios

但这并不能解决我的问题,因为需要将带有测试的文件夹挂载到容器外部。知道如何安装 Axios 以便在 Docker 容器中正确使用 Testcafe 吗?

axios testcafe
1个回答
0
投票

测试中引用的Node js模块应位于映射的主机目录或其子目录中。否则,无法从容器访问它们。或者,您可以共享驱动器以从 Docker 容器访问它。有关更多信息,请参阅 Docker 文档

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