diff --git a/lib/runner_base.js b/lib/runner_base.js index 85e7cc6..663635a 100644 --- a/lib/runner_base.js +++ b/lib/runner_base.js @@ -78,9 +78,12 @@ class RunnerBase { if (configFilePath) { await this.loadSpecificConfigFile_(configFilePath); } else { + let numFound = 0; + for (const ext of ['json', 'js']) { try { await this.loadSpecificConfigFile_(`spec/support/jasmine.${ext}`); + numFound++; } catch (e) { if (e.code !== 'MODULE_NOT_FOUND' // CommonJS && e.code !== 'ERR_MODULE_NOT_FOUND' // ESM @@ -89,6 +92,15 @@ class RunnerBase { } } } + + if (numFound > 1) { + console.warn( + 'Deprecation warning: Jasmine found and loaded both jasmine.js ' + + 'and jasmine.json\n' + + 'config files. In a future version, only the first file found ' + + 'will be loaded.' + ); + } } } diff --git a/spec/shared_runner_behaviors.js b/spec/shared_runner_behaviors.js index 569f9b6..ac4be58 100644 --- a/spec/shared_runner_behaviors.js +++ b/spec/shared_runner_behaviors.js @@ -308,6 +308,27 @@ function sharedRunnerBehaviors(makeRunner) { pathEndingWith('spec/fixtures/sample_project/spec/fixture_spec.js') ]); }); + + it('warns if both default config files are found', async function() { + spyOn(Loader.prototype, 'load').and.callFake(function (path) { + if (path.endsWith('jasmine.js') || path.endsWith('jasmine.json')) { + return Promise.resolve({}); + } else { + const e = new Error(`Module not found: ${path}`); + e.code = 'MODULE_NOT_FOUND'; + return Promise.reject(e); + } + }); + spyOn(console, 'warn'); + + await this.fixtureJasmine.loadConfigFile(); + + expect(console.warn).toHaveBeenCalledWith( + 'Deprecation warning: Jasmine found and loaded both jasmine.js ' + + 'and jasmine.json\nconfig files. In a future version, only the ' + + 'first file found will be loaded.' + ); + }); }); });