【发布时间】:2019-01-22 05:18:03
【问题描述】:
我使用 create-react-app 创建了一个 reactjs 应用。
运行应用程序有效。运行测试有效。非常好和容易。
然后为 gitlab 创建一个管道来运行构建和测试。
在 gitlab 上构建成功,但在测试时失败。
> react-scripts test
PASS src/App.test.js
✓ renders without crashing (25ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.955s
Ran all test suites.
npm ERR! Test failed. See above for more details.
无论如何我都找不到有关失败原因的更多详细信息,也不知道如何解决它。
运行 npm test --verbose 后,这里是新的输出:
$npm test --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'test',
npm verb cli '--verbose' ]
npm info using npm@6.5.0
npm info using node@v11.7.0
npm verb run-script [ 'pretest', 'test', 'posttest' ]
npm info lifecycle easyauto123@0.1.0~pretest: easyauto123@0.1.0
npm info lifecycle easyauto123@0.1.0~test: easyauto123@0.1.0
> easyauto123@0.1.0 test /builds/easyauto123/website
> react-scripts test
PASS src/App.test.js
✓ renders without crashing (30ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.13s
Ran all test suites.
npm verb lifecycle easyauto123@0.1.0~test: unsafe-perm in lifecycle true
npm verb lifecycle easyauto123@0.1.0~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/builds/easyauto123/website/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
npm verb lifecycle easyauto123@0.1.0~test: CWD: /builds/easyauto123/website
npm info lifecycle easyauto123@0.1.0~test: Failed to exec test script
npm ERR! Test failed. See above for more details.
npm verb exit [ 1, true ]
npm timing npm Completed in 3576ms
npm verb code 1
ERROR: Job failed: exit code 1
【问题讨论】:
-
能否在本地运行
yarn test并检查是否成功运行? -
在 gitlab build 中使用
--verbose选项运行您的测试。它应该为您提供有关实际损坏位置的更多信息。npm run test --verbose -
谢谢。我使用了 --verbose 并用新的输出更新了问题。
-
运行 yarn test 而不是 npm test 并没有什么不同。我都尝试过,结果相同。
-
有趣!测试用例失败,错误代码为 1。正如你所说,那里没有太多信息。
标签: reactjs jestjs create-react-app