Skip to content

Commit 84eaef0

Browse files
committed
Issue a deprecation warning if both jasmine.js and jasmine.json are found
Jasmine incorrectly loads both files if they're both found. This will be fixed in the next major relase.
1 parent 882bd5a commit 84eaef0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/runner_base.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ class RunnerBase {
7878
if (configFilePath) {
7979
await this.loadSpecificConfigFile_(configFilePath);
8080
} else {
81+
let numFound = 0;
82+
8183
for (const ext of ['json', 'js']) {
8284
try {
8385
await this.loadSpecificConfigFile_(`spec/support/jasmine.${ext}`);
86+
numFound++;
8487
} catch (e) {
8588
if (e.code !== 'MODULE_NOT_FOUND' // CommonJS
8689
&& e.code !== 'ERR_MODULE_NOT_FOUND' // ESM
@@ -89,6 +92,15 @@ class RunnerBase {
8992
}
9093
}
9194
}
95+
96+
if (numFound > 1) {
97+
console.warn(
98+
'Deprecation warning: Jasmine found and loaded both jasmine.js ' +
99+
'and jasmine.json\n' +
100+
'config files. In a future version, only the first file found ' +
101+
'will be loaded.'
102+
);
103+
}
92104
}
93105
}
94106

spec/shared_runner_behaviors.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,27 @@ function sharedRunnerBehaviors(makeRunner) {
308308
pathEndingWith('spec/fixtures/sample_project/spec/fixture_spec.js')
309309
]);
310310
});
311+
312+
it('warns if both default config files are found', async function() {
313+
spyOn(Loader.prototype, 'load').and.callFake(function (path) {
314+
if (path.endsWith('jasmine.js') || path.endsWith('jasmine.json')) {
315+
return Promise.resolve({});
316+
} else {
317+
const e = new Error(`Module not found: ${path}`);
318+
e.code = 'MODULE_NOT_FOUND';
319+
return Promise.reject(e);
320+
}
321+
});
322+
spyOn(console, 'warn');
323+
324+
await this.fixtureJasmine.loadConfigFile();
325+
326+
expect(console.warn).toHaveBeenCalledWith(
327+
'Deprecation warning: Jasmine found and loaded both jasmine.js ' +
328+
'and jasmine.json\nconfig files. In a future version, only the ' +
329+
'first file found will be loaded.'
330+
);
331+
});
311332
});
312333
});
313334

0 commit comments

Comments
 (0)