From 84eaef04d2615b6cd8257433e1bbcc24cbb29201 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 22 Jul 2023 08:22:19 -0700 Subject: [PATCH] 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. --- lib/runner_base.js | 12 ++++++++++++ spec/shared_runner_behaviors.js | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) 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.' + ); + }); }); });