Warn if jasmine-core is loaded as an ES module in browsers

This commit is contained in:
Steve Gravrock
2025-10-05 09:03:27 -07:00
parent 67ef721c85
commit b881b0077d
3 changed files with 22 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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$;
};