TravisCI 与 npm run test from create react app

Lio*_*cer 1 javascript travis-ci reactjs create-react-app

我正在尝试使用TravisCI由 create react 应用程序生成的项目执行自动化测试。

有人告诉我,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.
Run Code Online (Sandbox Code Playgroud)

更新:

项目结构

/redribbon
  .travis.yml
  docker-compose.yml
  /client
    package.json
    Dockerfile
    Dockerfile.dev
  /server
Run Code Online (Sandbox Code Playgroud)

我知道默认情况下 TravisCI 会CI=true自动设置。目前,我的npm run testin[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
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

如果我添加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.
Run Code Online (Sandbox Code Playgroud)

Bad*_*dri 7

在你的 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
Run Code Online (Sandbox Code Playgroud)

这将允许您运行测试并在测试完成后退出图像