jasmine / jasmine-npm

A jasmine runner for node projects.
MIT License
377 stars 145 forks source link

read config from jasmine #129

Closed wzr1337 closed 5 years ago

wzr1337 commented 6 years ago

Hi all,

I would like to read the config used with jasmine while executing my tests. I also need to extend the jasmine.json file with certain information I need to configure my tests. As I do not want to separate the configuration information, I would love to see a method that returns the current config in its full beauty

Jasmine.prototype.loadConfigFile = function(configFilePath) {
  try {
    var absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
    var config = require(absoluteConfigFilePath);
    this.loadConfig(config);
  } catch (e) {
    if(configFilePath || e.code != 'MODULE_NOT_FOUND') { throw e; }
  }
};

Jasmine.prototype.loadConfig = function(config) {
  this.specDir = config.spec_dir || this.specDir;

  if (config.stopSpecOnExpectationFailure !== undefined) {
    this.env.throwOnExpectationFailure(config.stopSpecOnExpectationFailure);
  }

  if (config.stopOnSpecFailure !== undefined) {
    this.env.stopOnSpecFailure(config.stopOnSpecFailure);
  }

  if (config.random !== undefined) {
    this.env.randomizeTests(config.random);
  }

  if(config.helpers) {
    this.addHelperFiles(config.helpers);
  }

  if(config.spec_files) {
    this.addSpecFiles(config.spec_files);
  }
};

does not store the configuration with jasmine, so I can not retrieve it.

like so:

Jasmine.prototype.loadConfig = function(config) {
  this.specDir = config.spec_dir || this.specDir;

  this.config = Object.assign(config, {spec_dir: this.specDir}); //new code

  if (config.stopSpecOnExpectationFailure !== undefined) {
    this.env.throwOnExpectationFailure(config.stopSpecOnExpectationFailure);
  }

  if (config.stopOnSpecFailure !== undefined) {
    this.env.stopOnSpecFailure(config.stopOnSpecFailure);
  }

  if (config.random !== undefined) {
    this.env.randomizeTests(config.random);
  }

  if(config.helpers) {
    this.addHelperFiles(config.helpers);
  }

  if(config.spec_files) {
    this.addSpecFiles(config.spec_files);
  }
};

/** new code
*
*/
Jasmine.prototype.getConfig = function() {
 return this.config
};

Are there more people needing this? In this case I would file a PR..

slackersoft commented 6 years ago

What parts of Jasmine's configuration do you need inside your test suite? Hopefully none, as your tests success shouldn't be dependent on which other tests were run or ordering or any of the other things you've configured for Jasmine. In general I would recommend against having configuration that is actually used by the test suite itself (exceptions like OS specific options or settings not withstanding).

If you still want some additional configuration to use within your suite, I don't think that belongs in Jasmine's config file.

Hope this helps. Thanks for using Jasmine!

slackersoft commented 5 years ago

We haven't heard anything further on this, so I'm going to close it.