jasmine / jasmine-browser-runner

Serve and run your Jasmine specs in a browser
49 stars 23 forks source link

Custom reporter for jasmine via jasmine-browser-runner? #40

Closed bksglatz closed 1 year ago

bksglatz commented 1 year ago

Is there any way to get custom reporter for jasmine (like https://www.npmjs.com/package/jasmine-reporters) configured to be used with jasmine-browser-runner.

sgravrock commented 1 year ago

Yes. You can add it to the reporters array in your config file. With most reporters you can just specify the name of the module that exports the reporter constructor, but jasmine-reporters is more complex so you need to use a JS (not JSON) config file and do something like this:

// spec/support/jasmine-browser.js

const jasmineReporters = require('jasmine-reporters');
const junitReporter = new jasmineReporters.JUnitXmlReporter({
    // ...reporter configuration snipped...
});

module.exports = {
  reporters: [ junitReporter ],
  // ...other config properties snipped...
};

Depending on what the reporter you're using does, you might also want to set useConsoleReporter to false.

bksglatz commented 1 year ago

Im fine with using a ts/js file instead of a json file for configuration. I was Can i just forward the path to the js file as i do it for the json file via the same parameter when running jasmine-browser-runner?

Maybe consider extending the documentation. I wasn't able to find any information about how to add custom reporters or use a js configuration instead of json configuration or a list of all supported configuration values except those from the example file created during init.

Thx for the fast response and help. I will let you know if i was able to get it running this way.

bksglatz commented 1 year ago

Okay... Forget what i have written about the documentation. I wasn't able to find it ;) My fault... Everyting there: https://jasmine.github.io/api/browser-runner/edge/Configuration.html

HolgerJeromin commented 1 year ago

But perhaps there should be a link from https://github.com/jasmine/jasmine-browser-runner#readme to the full doc https://jasmine.github.io/api/browser-runner/edge/Configuration.html

bksglatz commented 1 year ago

Loading the reporter this way works fine. However the reporter does not work anymore or not the way i want it to work. But now that i know how to load reporters i can write my own :)

sgravrock commented 1 year ago

I'm glad that worked.

There's some discussion about the structure and discoverability of config docs at https://github.com/jasmine/jasmine.github.io/issues/161 .