簡體   English   中英

摩卡 JUnit 記者 UnhandledPromiseRejectionWarning

[英]Mocha JUnit reporter UnhandledPromiseRejectionWarning

我試圖讓這個例子在我的 Azure Devops Pipeline 中工作。 https://mochajs.org/#getting-started

首先,我已經嘗試進行自己的測試,但是在不斷收到以下錯誤之后,我恢復到基本示例,但仍然收到此錯誤:

mocha test --reporter mocha-junit-reporter
========================== Starting Command Output ===========================
"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\3909d6a6-de56-4ad9-9fb2-b94c5529546b.cmd""
(node:2160) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Object.help (C:\npm\prefix\node_modules\mocha\node_modules\yargs\lib\usage.js:240:22)
    at Object.self.showHelp (C:\npm\prefix\node_modules\mocha\node_modules\yargs\lib\usage.js:432:15)
    at Array.<anonymous> (C:\npm\prefix\node_modules\mocha\lib\cli\cli.js:53:13)
    at Object.fail (C:\npm\prefix\node_modules\mocha\node_modules\yargs\lib\usage.js:41:17)
    at C:\npm\prefix\node_modules\mocha\node_modules\yargs\lib\command.js:246:36
(node:2160) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2160) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Finishing: Test Mocha

我試過在 windows 和 linux 容器中運行它,但看不出有任何區別。 這是我的文件結構

index.html
app.js
package.json
style.css
readme.md
-test
  test.js

這是package.json的內容

{
    "scripts": {
        "test": "mocha"
    }
}

這是test\test.js文件的聯系方式

    var assert = require('assert');
    describe('Array', function() {
      describe('#indexOf()', function() {
        it('should return -1 when the value is not present', function() {
          assert.equal([1, 2, 3].indexOf(4), -1);
        });
      });
    });

我認為 html 和 app.js 文件現在很有趣,因為它們不會在任何地方調用。

這也是管道的定義:

pool:
  name: Azure Pipelines
  demands: npm

steps:
- task: Npm@1
  displayName: 'npm install'
  inputs:
    verbose: false

- script: 'npm install --save-dev mocha'
  displayName: 'Install Mocha'

- script: 'npm install --save-dev mocha-junit-reporter'
  displayName: 'Install Reporter'

- script: |
   npm i --save-dev chai

  displayName: 'Install Chai'

- script: 'npm test'
  displayName: 'Test Mocha'
  continueOnError: true

- powershell: |
   ls "$(System.DefaultWorkingDirectory)"

  displayName: 'PowerShell Script'

- task: PublishTestResults@2
  displayName: 'Publish Test Results **/test-results.xml'
  inputs:
    testResultsFiles: '**/test-results.xml'
  condition: succeededOrFailed()

- task: ArchiveFiles@1
  displayName: 'Archive files'
  inputs:
    rootFolder: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveType: zip

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

當我嘗試在沒有報告器的情況下運行它時,它會給出 output 並且測試已完成,我在添加報告器時會收到此錯誤。 我也嘗試使用 xunit 報告器,但后來我得到了同樣的錯誤。

我在這里想念什么? 任何人都知道我為什么會收到此錯誤以及如何防止它? 我自己的 javascript 代碼並不多,我更熟悉其他語言,主要是為了為其他程序員設置自動測試。

我最近能夠再次對此進行調查,現在它似乎已修復,所以我認為這確實是 mocha 中的一個錯誤。 無論如何感謝您的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM