0

现在构建一个由create-react-app.

在我的package.json中,我安装了一些依赖项。完整列表在这里:

包.json

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "dependencies": {
    "jest-cli": "^22.4.3",
    "raven-js": "^3.25.1",
    "react": "^16.3.2",
    "react-raven": "^1.2.3",
    "react-scripts": "1.1.4",
    "babel-plugin-add-module-exports": "0.2.1"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-jest": "^22.4.3",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-react-app": "^3.1.1",
    "coveralls": "^3.0.1",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "jest": "^22.4.3",
    "react-addons-test-utils": "^15.6.2",
    "react-dom": "^16.3.2",
    "react-test-renderer": "^16.3.2"
  }
}

还创建了一个.travis.yml文件。想在 TravisCI 上测试代码:

.travis.yml

language: node_js
node_js:
  - "8"

before_script:
  - npm install
  - npm install coveralls

script:
  - jest --coverage --coverageReporters=text-lcov | coveralls

但是当 TravisCI 运行任务时,它的控制台日志显示:

...
$ jest --coverage --coverageReporters=text-lcov | coveralls
PASS src/sum.test.js
  ✓ adds 1 + 2 to equal 3 (7ms)
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.629s
Ran all test suites.
/home/travis/build/[MY_GITHUB]/[MY_PROJECT]/node_modules/coveralls/bin/coveralls.js:18
        throw err;
        ^
Bad response: 500 {"message":"Build processing error.","error":true,"url":""}
The command "jest --coverage --coverageReporters=text-lcov | coveralls" exited with 1.
Done. Your build exited with 1.

为什么不能将覆盖结果发送到工作服?

4

1 回答 1

1

我整理了一个简单的存储库来演示使用jestwithtraviscoverallshere:

https://github.com/AaronWatters/hello_jest

jest.config.js用来告诉 jest 把覆盖率报告放在 "./tests/coverage"然后coveralls指令package.json

"coveralls": "jest --coverage && cat ./tests/coverage/lcov.info | coveralls",

很抱歉,它是如此令人费解,但它似乎有效,即使它不像你想要做的那样简单。它也没有使用react,但我认为对组件使用相同的方法应该不是问题react

请查看存储库了解所有血腥细节。

如果您发现该方法存在问题或者您有其他建议或意见,请在存储库中发布问题。

于 2018-11-15T13:54:41.290 回答