我正在尝试使用create react应用程序生成的项目对TravisCI
进行自动测试。
有人告诉我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
中的[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
可以看到here
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.
答案 0 :(得分:3)
在您的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
这将允许您运行测试并在测试完成后退出图像
答案 1 :(得分:0)
从docker容器中的create-react-app运行测试时,请使用watchAll = false标志。
在.travis.yml中:
脚本:docker run npm run test---watchAll = false