Skip to content

Commit d8d5473

Browse files
committedJun 21, 2021
Log a deprecation when a require has a path starting with . or ..
1 parent 0488650 commit d8d5473

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎lib/jasmine.js

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ Jasmine.prototype.loadRequires = function() {
105105
// TODO: In 4.0, switch to calling _loadFiles
106106
// (requires making this function async)
107107
this.requires.forEach(function(r) {
108+
if (r.startsWith('./') || r.startsWith("../")) {
109+
console.warn('DEPRECATION: requires with relative paths (in this case ' +
110+
`${r}) are currently resolved relative to the jasmine/lib/jasmine ` +
111+
'module but will be relative to the current working directory in ' +
112+
'Jasmine 4.0.');
113+
}
108114
require(r);
109115
});
110116
};

‎spec/jasmine_spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,34 @@ describe('Jasmine', function() {
333333
expect(this.loader.load).toHaveBeenCalledWith(jasmine.any(String), false);
334334
});
335335
});
336+
337+
it('logs a deprecation when a require has a path beginning with ../', function() {
338+
this.configObject.requires = ['../somefile.js'];
339+
spyOn(console, 'warn');
340+
341+
this.fixtureJasmine.loadConfig(this.configObject);
342+
expect(() => this.fixtureJasmine.loadRequires())
343+
.toThrowError(/^Cannot find module '\.\.\/somefile.js'/);
344+
345+
expect(console.warn).toHaveBeenCalledWith('DEPRECATION: requires ' +
346+
'with relative paths (in this case ../somefile.js) are currently ' +
347+
'resolved relative to the jasmine/lib/jasmine module but will be ' +
348+
'relative to the current working directory in Jasmine 4.0.');
349+
});
350+
351+
it('logs a deprecation when a require has a path beginning with ./', function() {
352+
this.configObject.requires = ['./somefile.js'];
353+
spyOn(console, 'warn');
354+
355+
this.fixtureJasmine.loadConfig(this.configObject);
356+
expect(() => this.fixtureJasmine.loadRequires())
357+
.toThrowError(/^Cannot find module '\.\/somefile.js'/);
358+
359+
expect(console.warn).toHaveBeenCalledWith('DEPRECATION: requires ' +
360+
'with relative paths (in this case ./somefile.js) are currently ' +
361+
'resolved relative to the jasmine/lib/jasmine module but will be ' +
362+
'relative to the current working directory in Jasmine 4.0.');
363+
});
336364
});
337365

338366
describe('from a file', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.