Skip to content
This repository was archived by the owner on Dec 3, 2022. It is now read-only.

Question: which reporter to use for jasmine-ts to file? #23

Closed
tomer-ben-david opened this issue May 10, 2018 · 4 comments
Closed

Question: which reporter to use for jasmine-ts to file? #23

tomer-ben-david opened this issue May 10, 2018 · 4 comments

Comments

@tomer-ben-david
Copy link

So that I can see the report in Jenkins for example.

This is what I currently have, no report files produced, what should I use to produce report files (preferably readable by Jenkins..)

  "reporters": [
    {
      "name": "jasmine-spec-reporter#SpecReporter",  
      "options": {
        "displayStacktrace": "all"
      }
    }
  ]

Thanks.

@Pineapples
Copy link

It depends on what reporter you would like to use, I use a JUnit reporter from the package jasmine-reporters.

To use the reporter you need to use a helper file and then initialize the reporter in the helper file:

const JUnitReporter = require('jasmine-reporters').JUnitXmlReporter;

jasmine.getEnv().addReporter(new JUnitReporter({
    savePath: '.jasmine'
}));

@ert78gb
Copy link
Collaborator

ert78gb commented Apr 16, 2021

Version 0.3.2 support the --reporter command line parameter. I think the question also answered, but feel free to reopen the issue and describe what is missing.

@ert78gb ert78gb closed this as completed Apr 16, 2021
@nagyzsolthun
Copy link

How to use the --reporter command line parameter? E.g. jasmine-ts --reporter jasmine-reporters#JUnitXmlReporter fails with "No specs found"

@ert78gb
Copy link
Collaborator

ert78gb commented Apr 26, 2021

As described in the jasmine documentation. :)

Prior to 0.3.2 jasmine-ts the jasmine config file were parsed and the reporters were set based on that. Jasmine has a built-in command line argument that can handle reporters. So I removed this feature because it had increased the complexity of this lib. Because the changes of the reporter initialisation and the config file structure should be tracked.

The jasmine documentation is not perfect, it does not mention how to provide the --reporter argument.
The reporter argument should be a node module which is a default export class it will be instantiated.
The relevant code
As you see from the referenced code the reporter will be loaded by require(env.reporter) so the value of the argument should be

  • relative path to the loadConfig.js file.
  • absolute path
  • node module
    The first option is not a real option.

The common practice is you define a helper file

const { SpecReporter } = require('jasmine-spec-reporter')

jasmine.getEnv().clearReporters()
jasmine.getEnv().addReporter(new SpecReporter({
      prefixes: {
        failed: ':( ',
        pending: '? ',
        successful: ':) '
      }
    }
))

Finally, I try to answer to your question:

  • create a reporter file, default export the class
  • set --reporter with absolute file path
// custom-reporter.js
const { SpecReporter } = require('jasmine-spec-reporter')

class CustomReporter extends SpecReporter {
  constructor() {
    super({
      prefixes: {
        failed: ':( ',
        pending: '? ',
        successful: ':) '
      }
    });
  }
}

module.exports = CustomReporter

I think the --reporter argument is useful when your IDE use a custom reporter to visualise the test results like IntelliJ does.

There are 2 open PR (jasmine/jasmine-npm#77 , jasmine/jasmine-npm#159) in the jasmine-npm repo that try to add the deleted feature to the core lib.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants