javascript - TravisCI 与来自创建反应应用程序的 npm 运行测试
问题描述
我正在尝试使用TravisCI
create react app 生成的项目执行自动化测试。
有人告诉我npm run test -- --coverage
应该在运行时停止watch mode
或提示出现npm run test
。但是我仍然看到提示。
Watch Usage
› Press f to run only failed tests.
› Press o to only run tests related to changed files.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
更新:
项目结构
/redribbon
.travis.yml
docker-compose.yml
/client
package.json
Dockerfile
Dockerfile.dev
/server
我了解到默认情况下 TravisCI 会CI=true
自动设置。目前,我npm run test
的in[package.json][1]
还没有被触及。
.travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t bradford/redribbon-client -f ./client/Dockerfile.dev ./client
script:
- docker run bradford/redribbon-client npm run test
TravisCI 输出可以在这里看到
如果没有 TravisCI,当我运行命令npm run test
或者npm test
这是我的输出时:
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
如果我添加CI=true
-->"test": "CI=true react-scripts test",
这是我的输出:
$ npm test
> client@0.1.0 test /Users/bli1/Development/projects/sideprojects/redribbon/client
> CI=true react-scripts test
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/bli1/Development/projects/sideprojects/redribbon/client
14 files checked.
testMatch: /Users/bli1/Development/projects/sideprojects/redribbon/client/src/**/__tests__/**/*.{js,jsx,ts,tsx}, /Users/bli1/Development/projects/sideprojects/redribbon/client/src/**/*.{spec,test}.{js,jsx,ts,tsx} - 0 matches
testPathIgnorePatterns: /node_modules/ - 14 matches
testRegex: - 0 matches
Pattern: - 0 matches
npm ERR! Test failed. See above for more details.
解决方案
在你的 travis.yml 中试试这个,
sudo: required
services:
- docker
before_install:
- docker build -t bradford/redribbon-client -f ./client/Dockerfile.dev ./client
script:
- docker run -e CI=true bradford/redribbon-client npm run test
这将允许您在测试完成后运行测试并退出映像
推荐阅读
- c# - 为什么我的代码在相机视图中的一个游戏对象被销毁时一次生成两个游戏对象(而不是一个)?
- ios - 在 Xcode 11,beta 2 的 Interface Builder 中指定条形颜色时,iOS 13 的 UITabBarItem 图标颜色不正确
- sas - 使用正则表达式删除宏变量括号内的文本
- python - 在随机矩阵中找到最可能的区域
- forms - 在 TYPO3 扩展中创建表单并处理结果
- php - 将 JSON 中的数组作为二维数组的数组或字符串返回
- android - 模拟电池状态
- python - 如何使这个 Python filterwarnings 语句起作用?
- syntax - 混合大小写,但保持一致
- sql - 我无法使用从案例表达式创建的唯一变量列表创建表