Skip to content

Commit

Permalink
Issue a deprecation warning if both jasmine.js and jasmine.json are f…
Browse files Browse the repository at this point in the history
…ound

Jasmine incorrectly loads both files if they're both found. This will be
fixed in the next major relase.
  • Loading branch information
sgravrock committed Jul 22, 2023
1 parent 882bd5a commit 84eaef0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/runner_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.'
);
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions spec/shared_runner_behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
});
});
});

Expand Down

0 comments on commit 84eaef0

Please sign in to comment.