[英]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.