I'm trying to make this example work in my Azure Devops Pipeline. https://mochajs.org/#getting-started
First I tried to have my own tests already but after I keep getting the following error I reverted to the basic example but still I'm getting this error:
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
I've tried running it in both a windows and linux container but can't see any difference. This is my file structure
index.html
app.js
package.json
style.css
readme.md
-test
test.js
This is the content of the package.json
{
"scripts": {
"test": "mocha"
}
}
This is the contact of the test\test.js file
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);
});
});
});
The html and app.js file are for now now interesting I assume because they aren't called anywhere.
Here is also the pipeline defenition:
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'
When I try to run it without the reporter then it gives an output and the tests are done, I just get this error when adding the reporter. I also tried to use the xunit reporter instead but then I get the same error.
What am I missing here? Anyone knows why I get this error and how I can prevent it? I'm not much of a javascript code myself I'm more at home in other languages and mostly do this to setup automatic testing for other programmers.
I recently was able to look into this again and now it seems to be fixed so I think indeed it was a bug in mocha. Thanks for the help anyways.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.