Skip to content

Commit

Permalink
Allow to run without jasmine.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin R. Hufsky committed Feb 27, 2016
1 parent 42e9886 commit b51ad7d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ function help(options) {
print('Options:');
print('%s\tturn off color in spec output', lPad('--no-color', 18));
print('%s\tfilter specs to run only those that match the given string', lPad('--filter=', 18));
print('%s\t[true|false] stop spec execution on expectation failure. This takes precedence over the stopSpecOnExpectationFailure option in jasmine.json', lPad('--stop-on-failure=', 18));
print('%s\t[true|false] stop spec execution on expectation failure', lPad('--stop-on-failure=', 18));
print('');
print('The path to your jasmine.json can be configured by setting the JASMINE_CONFIG_PATH environment variable');
print('The given arguments take precedence over options in your jasmine.json');
print('The path to your optional jasmine.json can be configured by setting the JASMINE_CONFIG_PATH environment variable');
}

function version(options) {
Expand Down
10 changes: 7 additions & 3 deletions lib/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ Jasmine.prototype.loadHelpers = function() {
};

Jasmine.prototype.loadConfigFile = function(configFilePath) {
var absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
var config = require(absoluteConfigFilePath);
this.loadConfig(config);
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) {
Expand Down
15 changes: 15 additions & 0 deletions spec/jasmine_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ describe('Jasmine', function() {
]);
});

it('throw error if specified configuration file doesn\'t exist', function() {
var jasmine = this.fixtureJasmine;
function load() { jasmine.loadConfigFile('missing.json'); }
expect(load).toThrow();
});

it('no error if default configuration file doesn\'t exist', function() {
var jasmine = this.fixtureJasmine;
function load() {
jasmine.projectBaseDir += '/missing';
jasmine.loadConfigFile();
}
expect(load).not.toThrow();
});

it('loads the default configuration file', function() {
this.fixtureJasmine.loadConfigFile();
expect(this.fixtureJasmine.specFiles).toEqual([
Expand Down

0 comments on commit b51ad7d

Please sign in to comment.