Bash错误的退出代码

时间:2018-11-24 04:58:21

标签: node.js bash circleci

在CircleCI上,我的配置文件中正在运行npm run test-ci

我的package.json中有以下脚本:

"test-ci": ". ./envvars/test.sh && nyc --all mocha --recursive --timeout 10000 && npm run report-coverage-ci",
"report-coverage-ci": "nyc report --reporter=text-lcov > coverage.lcov && codecov -f coverage.json && echo CodeCov Done",

问题是,Mocha测试失败,但仍在CircleCI上显示该测试成功。

因此,如果Mocha测试失败,则不应继续到报告代码覆盖率以及所有这些内容的部分。但它继续到该部分。

您可以在下面看到日志的最后部分(我已经撤消了一些敏感信息)。

我该如何解决?

    ✓ Should work with last key (3760ms)

<--- Last few GCs --->

[8488:0x3743ca0]   140011 ms: Scavenge 1328.2 (1422.9) -> 1327.9 (1423.9) MB, 7.2 / 0.0 ms  (average mu = 0.151, current mu = 0.118) allocation failure 
[8488:0x3743ca0]   140033 ms: Scavenge 1328.7 (1423.9) -> 1328.3 (1424.4) MB, 15.9 / 0.0 ms  (average mu = 0.151, current mu = 0.118) allocation failure 
[8488:0x3743ca0]   140056 ms: Scavenge 1329.1 (1424.4) -> 1328.8 (1425.4) MB, 7.7 / 0.0 ms  (average mu = 0.151, current mu = 0.118) allocation failure 


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x1581d2a5c01d]
Security context: 0x18382199e549 <JSObject>
    1: /* anonymous */ [0x74025342ac9] [/home/circleci/repo/node_modules/q/q.js:~846] [pc=0x1581d355b56f](this=0x1ccc2a3a6ac9 <Object map = 0x3093e6868539>,fulfilled=0x1ccc2a3a67c1 <JSFunction query (sfi = 0x35b314d784e9)>,rejected=0x3344031826f1 <undefined>,progressed=0x3344031826f1 <undefined>)
    2: arguments adaptor frame: 1->3
    3: /* anonymous */ [0...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x8c02c0 node::Abort() [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 2: 0x8c030c  [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 3: 0xad15de v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 4: 0xad1814 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 5: 0xebe752  [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 6: 0xebe858 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 7: 0xeca982 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 8: 0xecb2b4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
 9: 0xecdf21 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
10: 0xe97444 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
11: 0x1136d5e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/opt/circleci/.nvm/versions/node/v10.9.0/bin/node]
12: 0x1581d2a5c01d 
-----------------------------------------|----------|----------|----------|----------|-------------------|
File                                     |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------------------------------------|----------|----------|----------|----------|-------------------|
All files                                |        0 |        0 |        0 |        0 |                   |
 repo                                    |        0 |        0 |      100 |        0 |                   |
  create_tables.js                       |        0 |        0 |        0 |        0 |                   |
-----------------------------------------|----------|----------|----------|----------|-------------------|

> Project@1.0.0 report-coverage-ci /home/circleci/repo
> nyc report --reporter=text-lcov > coverage.lcov && codecov -f coverage.json && echo CodeCov Done

  _____          _  
 / ____|        | |  
| |     ___   __| | ___  ___ _____   __  
| |    / _ \ / _` |/ _ \/ __/ _ \ \ / /  
| |___| (_) | (_| |  __/ (_| (_) \ V /  
 \_____\___/ \__,_|\___|\___\___/ \_/  
                                v3.1.0
==> Detecting CI Provider
    Circle CI Detected
==> Configuration: 
    Endpoint: https://codecov.io
{ commit: '',
  branch: 'master',
  package: 'node-v3.1.0' }
==> Building file structure
==> Generating gcov reports (skip via --disable=gcov)
    $ find /home/circleci/repo -type f -name '*.gcno'  -exec gcov  {} +
==> Targeting specific file
    X Failed to read file at /home/circleci/repo/coverage.json
==> Uploading reports
    Success!
    View report at: https://codecov.io/github/rrainn/package/commit/
CodeCov Done

1 个答案:

答案 0 :(得分:1)

就bash而言,您的命令行是正确的。问题似乎是命令nyc --all mocha --recursive --timeout 10000失败,但是使用零退出代码完成了执行。因此&&操作员认为可以转到下一条命令。

根本原因似乎是在摩卡咖啡中,或更确切地说是在节点中。有一个github问题发布: Mocha exits with 0 exit code with failing tests #2713

从问题注释看来,它已在节点8.10中修复。