From b881b0077d07239ed75ca150d38e3fd2060a64ee Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sun, 5 Oct 2025 09:03:27 -0700 Subject: [PATCH] Warn if jasmine-core is loaded as an ES module in browsers --- lib/jasmine-core/jasmine.js | 11 +++++++++++ src/core/Env.js | 8 ++++++++ src/core/requireCore.js | 3 +++ 3 files changed, 22 insertions(+) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 4f7c6a91..f2230d10 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -118,6 +118,9 @@ var getJasmineRequireObj = (function() { j$.private.matchers = jRequire.requireMatchers(jRequire, j$); j$.private.asyncMatchers = jRequire.requireAsyncMatchers(jRequire, j$); + j$.private.loadedAsBrowserEsm = + globalThis.document && !globalThis.document.currentScript; + return j$; }; @@ -1594,6 +1597,14 @@ getJasmineRequireObj().Env = function(j$) { this.execute = async function(runablesToRun) { installGlobalErrors(); + // Karma incorrectly loads jasmine-core as an ES module. It isn't one, + // and we don't test that configuration. Warn about it. + if (j$.private.loadedAsBrowserEsm) { + this.deprecated( + "jasmine-core isn't an ES module but it was loaded as one. This is not a supported configuration." + ); + } + if (parallelLoadingState) { validateConfigForParallel(); } diff --git a/src/core/Env.js b/src/core/Env.js index 52eefbe7..ad39d25c 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -402,6 +402,14 @@ getJasmineRequireObj().Env = function(j$) { this.execute = async function(runablesToRun) { installGlobalErrors(); + // Karma incorrectly loads jasmine-core as an ES module. It isn't one, + // and we don't test that configuration. Warn about it. + if (j$.private.loadedAsBrowserEsm) { + this.deprecated( + "jasmine-core isn't an ES module but it was loaded as one. This is not a supported configuration." + ); + } + if (parallelLoadingState) { validateConfigForParallel(); } diff --git a/src/core/requireCore.js b/src/core/requireCore.js index fc63800b..77d45121 100644 --- a/src/core/requireCore.js +++ b/src/core/requireCore.js @@ -94,6 +94,9 @@ var getJasmineRequireObj = (function() { j$.private.matchers = jRequire.requireMatchers(jRequire, j$); j$.private.asyncMatchers = jRequire.requireAsyncMatchers(jRequire, j$); + j$.private.loadedAsBrowserEsm = + globalThis.document && !globalThis.document.currentScript; + return j$; };