Javascript 摩卡JUnit reporter未处理PromiserEjectionWarning
我正在努力使这个示例在我的Azure Devops管道中工作。Javascript 摩卡JUnit reporter未处理PromiserEjectionWarning,javascript,azure-devops,mocha.js,pipeline,reporters,Javascript,Azure Devops,Mocha.js,Pipeline,Reporters,我正在努力使这个示例在我的Azure Devops管道中工作。 https://mochajs.org/#getting-已启动 首先,我已经尝试进行我自己的测试,但在我不断出现以下错误后,我恢复到基本示例,但仍然出现此错误: mocha test --reporter mocha-junit-reporter ========================== Starting Command Output =========================== "C:\windows\sy
https://mochajs.org/#getting-已启动
首先,我已经尝试进行我自己的测试,但在我不断出现以下错误后,我恢复到基本示例,但仍然出现此错误:
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
这是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'
当我尝试在没有报告器的情况下运行它时,它会给出一个输出,并且测试已经完成,我只是在添加报告器时出现了这个错误。我也试着用xunit reporter来代替,但是我得到了同样的错误
我错过了什么?有人知道我为什么会犯这个错误,以及我如何预防它吗?
我自己也不是什么javascript代码,我更熟悉其他语言,主要是为了为其他程序员设置自动测试。我最近能够再次研究这个问题,现在它似乎已经修复,所以我认为这确实是mocha中的一个bug。无论如何,谢谢您的帮助。您能分享一些有关管道定义的详细信息吗,这样我们就可以尝试重现这个问题了?如果您直接在本地计算机上运行此示例,此问题是否仍然存在?我已将管道防御添加到问题中。我无法在本地机器上测试它,因为我没有安装npm etc。正如我所说,我的工作主要是确保管道正常工作,而不是编写代码等。我认为几天前在mocha中引入了一个通用的bug。我正在另一个上下文中处理同一个错误(--需要ts节点/寄存器)。我发现:
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'