Skip to content

Commit b51ad7d

Browse files
author
Martin R. Hufsky
committed
Allow to run without jasmine.json
1 parent 42e9886 commit b51ad7d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

lib/command.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ function help(options) {
164164
print('Options:');
165165
print('%s\tturn off color in spec output', lPad('--no-color', 18));
166166
print('%s\tfilter specs to run only those that match the given string', lPad('--filter=', 18));
167-
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));
167+
print('%s\t[true|false] stop spec execution on expectation failure', lPad('--stop-on-failure=', 18));
168168
print('');
169-
print('The path to your jasmine.json can be configured by setting the JASMINE_CONFIG_PATH environment variable');
169+
print('The given arguments take precedence over options in your jasmine.json');
170+
print('The path to your optional jasmine.json can be configured by setting the JASMINE_CONFIG_PATH environment variable');
170171
}
171172

172173
function version(options) {

lib/jasmine.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ Jasmine.prototype.loadHelpers = function() {
8383
};
8484

8585
Jasmine.prototype.loadConfigFile = function(configFilePath) {
86-
var absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
87-
var config = require(absoluteConfigFilePath);
88-
this.loadConfig(config);
86+
try {
87+
var absoluteConfigFilePath = path.resolve(this.projectBaseDir, configFilePath || 'spec/support/jasmine.json');
88+
var config = require(absoluteConfigFilePath);
89+
this.loadConfig(config);
90+
} catch (e) {
91+
if(configFilePath || e.code != 'MODULE_NOT_FOUND') { throw e; }
92+
}
8993
};
9094

9195
Jasmine.prototype.loadConfig = function(config) {

spec/jasmine_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ describe('Jasmine', function() {
209209
]);
210210
});
211211

212+
it('throw error if specified configuration file doesn\'t exist', function() {
213+
var jasmine = this.fixtureJasmine;
214+
function load() { jasmine.loadConfigFile('missing.json'); }
215+
expect(load).toThrow();
216+
});
217+
218+
it('no error if default configuration file doesn\'t exist', function() {
219+
var jasmine = this.fixtureJasmine;
220+
function load() {
221+
jasmine.projectBaseDir += '/missing';
222+
jasmine.loadConfigFile();
223+
}
224+
expect(load).not.toThrow();
225+
});
226+
212227
it('loads the default configuration file', function() {
213228
this.fixtureJasmine.loadConfigFile();
214229
expect(this.fixtureJasmine.specFiles).toEqual([

0 commit comments

Comments
 (0)