-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Karma + Mocha + reporter options crash #3068
Comments
Hi @ltee, could you elaborate on what you're trying to accomplish with a custom reporter in Karma? If you want to customize the console output when running with Karma I believe you'd have to write a reporter for Karma rather than Mocha, and in that case Mocha's reporter options would not apply, unless I'm mistaken. If there's something else you're trying to do instead (e.g. if there's a way to use Mocha's reporter to control what's on Karma's debug page?) I'd want to be sure that it works and isn't too hacky for Mocha to support before we change things to make it possible to use reporter options with it -- Mocha's browser reporter is pretty special-cased and I'm not familiar with how it fits with Karma. |
Thank for reply. First of all, i'm not talking about the reporter FOR karma ( like karma-mocha-reporter package ) but for Mocha reporters. The goal is to use mocha reporter like mochawesome. But when i'm using mocha from karma the mocha reporter option are not correctly handled in mocha. Form example using npm script: "scripts": {
"mocha": "mocha test/my_app.unit.js --reporter mochawesome --reporter-options reportDir=./test/reports/,reportFilename=my_app.report"
}, everything will be alright ! But when is use karma config file like this: module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [ 'mocha', 'chai' ],
// list of files / patterns to load in the browser
files: [
'test/**/*.unit.js'
],
// Pass configuration options directly to mocha
client: {
mocha: {
reporter: 'mochawesome',
reporterOptions: {
reportDir: 'test/reports/',
reportFilename: 'my_app.report',
reportTitle: 'My App Report'
}
}
}
})
} The karmaconf.client.mocha.reporterOptions are not correctly handle by mocha. In fact when using the npm script part, the reporter's options are send to mocha by Mocha constructor, while when using karma config ( which will use karma-mocha package ) the parameters will be handled by the setup methods. BUT, the setup method ( which is call in karma-mocha package in adapter.js at line 250 ) won't be able to set config properly. Because setup method expect that passed options are callable settings method. here the setup methods: /**
* Setup mocha with the given setting options.
*/
mocha.setup = function (opts) {
if (typeof opts === 'string') {
opts = { ui: opts };
}
for (var opt in opts) {
if (opts.hasOwnProperty(opt)) {
this[opt](opts[opt]);
}
}
return this;
}; I order to fix the usage of mocha reporter inside the karma package, you could: add the prototype that i had add. Or rewrite the setup methods to handle all potential mocha options. I hope that i'm clearer. My request is not for karma reporter but for mocha reporter inside karma. You could make a quick test using the repo: https://github.com/Itee/karma-mocha-reporterOption-crash |
Hi @Itee, I don't think that this is going to work, regardless of whether Mocha is changed; as far as I'm aware Mochawesome saves report files, and the Mocha instance running in Karma is running in the browser, where you can't save files. For instance, I believe if you run this without Basically, it's not (directly) an issue of whether you want to use a Karma reporter or a Mocha reporter, it's an issue of whether you want to use a reporter that's meant to be run on the server or a reporter that's meant to be run in a browser. Mocha reporters are usually meant to be run on the server, so without being specifically designed for the browser I'm not sure any of them will work in Karma regardless of Mocha's setup code. |
Ok ! So if i fully understand what you are saying, the only way to get full (html) report from reporters like mochawesome under karma running mocha, should be an package like 'karma-mocha-reporter' (but no for console) that handle karma output that come from mocha, and generate report on that output ? |
Right -- that's definitely going to be the case for anything that writes files, and as far as I'm aware is the way it has to be done in general. |
Prerequisites
common mistake
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend avoiding the use of globally installed Mocha.Description
Mocha crash when setup option that are not prototyped (a.k.a function)
Error is: Uncaught TypeError: this[opt] is not a function at node_modules/mocha/mocha.js:135
Steps to Reproduce
Create a karma boilerplate and setup in karma.conf.js:
Expected behavior: This to be fixed ?
Actual behavior: This crash the test run when set reporter options in karma.conf.js
Reproduces how often: 100%
Versions
Mocha version: 4.0.1
Node version: 8.7.0
System: Win10 x64
Shell: any
Browser: any
Third party: Karma v1.7.1
No transpiling
Additional Information
https://github.com/Itee/karma-mocha-reporterOption-crash
PR: #3069
The text was updated successfully, but these errors were encountered: