Skip to content

Commit 2f014c9

Browse files
committed
Improved interface for programmatically adding files
* Added Jasmine#addHelperFile * Added more clearly named synonyms for Jasmine#addSpecFiles and Jasmine#addHelperFiles, and marked the old ones deprecated
1 parent 9ce96bd commit 2f014c9

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed

lib/jasmine.js

+52-2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ Jasmine.prototype.addSpecFile = function(filePath) {
114114
this.specFiles.push(filePath);
115115
};
116116

117+
/**
118+
* Adds a helper file to the list that will be loaded when the suite is executed.
119+
* @function
120+
* @name Jasmine#addHelperFile
121+
* @param {string} filePath The path to the file to be loaded.
122+
*/
123+
Jasmine.prototype.addHelperFile = function(filePath) {
124+
this.helperFiles.push(filePath);
125+
};
126+
117127
/**
118128
* Add a custom reporter to the Jasmine environment.
119129
* @function
@@ -329,8 +339,48 @@ Jasmine.prototype.loadConfig = function(config) {
329339
}
330340
};
331341

332-
Jasmine.prototype.addHelperFiles = addFiles('helperFiles');
333-
Jasmine.prototype.addSpecFiles = addFiles('specFiles');
342+
/**
343+
* Adds files that match the specified patterns to the list of spec files.
344+
* @function
345+
* @name Jasmine#addMatchingSpecFiles
346+
* @param {Array<string>} patterns An array of spec file paths
347+
* or {@link https://github.com/isaacs/node-glob#glob-primer|globs} that match
348+
* spec files. Each path or glob will be evaluated relative to the spec directory.
349+
*/
350+
Jasmine.prototype.addMatchingSpecFiles = addFiles('specFiles');
351+
/**
352+
* Adds files that match the specified patterns to the list of helper files.
353+
* @function
354+
* @name Jasmine#addMatchingHelperFiles
355+
* @param {Array<string>} patterns An array of helper file paths
356+
* or {@link https://github.com/isaacs/node-glob#glob-primer|globs} that match
357+
* helper files. Each path or glob will be evaluated relative to the spec directory.
358+
*/
359+
Jasmine.prototype.addMatchingHelperFiles = addFiles('helperFiles');
360+
361+
362+
// Deprecated synonyms for the above. These are confusingly named (addSpecFiles
363+
// doesn't just do N of what addSpecFile does) but they've been around a long
364+
// time and there might be quite a bit of code that uses them.
365+
366+
/**
367+
* Synonym for {@link Jasmine#addMatchingSpecFiles}
368+
* @function
369+
* @name Jasmine#addSpecFiles
370+
* @deprecated Use {@link Jasmine#addMatchingSpecFiles|addMatchingSpecFiles},
371+
* {@link Jasmine#loadConfig|loadConfig}, or {@link Jasmine#loadConfigFile|loadConfigFile}
372+
* instead.
373+
*/
374+
Jasmine.prototype.addSpecFiles = Jasmine.prototype.addMatchingSpecFiles;
375+
/**
376+
* Synonym for {@link Jasmine#addMatchingHelperFiles}
377+
* @name Jasmine#addHelperFiles
378+
* @function
379+
* @deprecated Use {@link Jasmine#addMatchingHelperFiles|addMatchingHelperFiles},
380+
* {@link Jasmine#loadConfig|loadConfig}, or {@link Jasmine#loadConfigFile|loadConfigFile}
381+
* instead.
382+
*/
383+
Jasmine.prototype.addHelperFiles = Jasmine.prototype.addMatchingHelperFiles;
334384

335385
Jasmine.prototype.addRequires = function(requires) {
336386
var jasmineRunner = this;

spec/jasmine_spec.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,40 @@ describe('Jasmine', function() {
3535
});
3636
});
3737

38-
it('adds spec files', function() {
39-
expect(this.testJasmine.specFiles).toEqual([]);
40-
this.testJasmine.addSpecFile('some/file/path.js');
41-
expect(this.testJasmine.specFiles).toEqual(['some/file/path.js']);
38+
describe('#addSpecFile', function() {
39+
it('adds the provided path to the list of spec files', function () {
40+
expect(this.testJasmine.specFiles).toEqual([]);
41+
this.testJasmine.addSpecFile('some/file/path.js');
42+
expect(this.testJasmine.specFiles).toEqual(['some/file/path.js']);
43+
});
44+
});
45+
46+
describe('#addHelperFile', function() {
47+
it('adds the provided path to the list of helper files', function () {
48+
expect(this.testJasmine.helperFiles).toEqual([]);
49+
this.testJasmine.addHelperFile('some/file/path.js');
50+
expect(this.testJasmine.helperFiles).toEqual(['some/file/path.js']);
51+
});
4252
});
4353

4454
describe('Methods that specify files via globs', function() {
4555
describe('#addSpecFiles', function() {
4656
hasCommonFileGlobBehavior('addSpecFiles', 'specFiles');
4757
});
4858

59+
describe('#addMatchingSpecFiles', function() {
60+
hasCommonFileGlobBehavior('addMatchingSpecFiles', 'specFiles');
61+
});
62+
4963
describe('#addHelperFiles', function() {
5064
hasCommonFileGlobBehavior('addHelperFiles', 'helperFiles');
5165
});
5266

67+
describe('#addMatchingHelperFiles', function() {
68+
hasCommonFileGlobBehavior('addMatchingHelperFiles', 'helperFiles');
69+
});
70+
71+
5372
function hasCommonFileGlobBehavior(method, destProp) {
5473
it('adds a file with an absolute path', function() {
5574
var aFile = path.join(this.testJasmine.projectBaseDir, this.testJasmine.specDir, 'spec/command_spec.js');

0 commit comments

Comments
 (0)