Redesigned moudule system

* Top level private APIs (e.g. jasmine.private.whatever) are no longer
  exposed
* jasmineRequire is no longer exposed
* core is self-booting
* Globals are automatically created in browsers. (They can subsequently
  be removed by user code if desired.)
* Globals are *not* automatically created in Node. An installGlobals
  function is exported instead. The jasmine package calls installGlobals
  unless configured not to do so.
* In Node, the same instance is returned each time jasmine-core is
  imported. A reset function is exported. It effectively resets all state
  by discarding the env and creating a new one. This allows mulitple
  sequential runs within the same process to be independent of each
  other, but does not allow multiple concurrent runs. (That probably never
  worked anyway.)

Fixes #2094
This commit is contained in:
Steve Gravrock
2026-02-15 13:41:19 -08:00
parent 03006080d4
commit f12f4395f0
127 changed files with 1336 additions and 1367 deletions
+75 -51
View File
@@ -1,6 +1,6 @@
/*
Copyright (c) 2008-2019 Pivotal Labs
Copyright (c) 2008-2025 The Jasmine developers
Copyright (c) 2008-2026 The Jasmine developers
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -22,27 +22,44 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// eslint-disable-next-line no-var
var jasmineRequire = window.jasmineRequire || require('./jasmine.js');
(function() {
// eslint-disable-next-line no-unused-vars
const getJasmineHtmlRequireObj = (function() {
'use strict';
const htmlRequire = {};
jasmineRequire.html = function(j$) {
j$.private.ResultsNode = jasmineRequire.ResultsNode();
j$.private.ResultsStateBuilder = jasmineRequire.ResultsStateBuilder(j$);
j$.private.htmlReporterUtils = jasmineRequire.htmlReporterUtils(j$);
j$.private.AlertsView = jasmineRequire.AlertsView(j$);
j$.private.OverallStatusBar = jasmineRequire.OverallStatusBar(j$);
j$.private.Banner = jasmineRequire.Banner(j$);
j$.private.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
j$.private.PerformanceView = jasmineRequire.PerformanceView(j$);
j$.private.TabBar = jasmineRequire.TabBar(j$);
j$.HtmlReporterV2Urls = jasmineRequire.HtmlReporterV2Urls(j$);
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
j$.QueryString = jasmineRequire.QueryString();
j$.private.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
};
function getJasmineHtmlRequire() {
return htmlRequire;
}
jasmineRequire.ResultsNode = function() {
htmlRequire.html = function(j$, private$) {
if (!private$) {
private$ = {};
}
private$.ResultsNode = htmlRequire.ResultsNode();
private$.ResultsStateBuilder = htmlRequire.ResultsStateBuilder(
j$,
private$
);
private$.htmlReporterUtils = htmlRequire.htmlReporterUtils(j$, private$);
private$.AlertsView = htmlRequire.AlertsView(j$, private$);
private$.OverallStatusBar = htmlRequire.OverallStatusBar(j$, private$);
private$.Banner = htmlRequire.Banner(j$, private$);
private$.SummaryTreeView = htmlRequire.SummaryTreeView(j$, private$);
private$.FailuresView = htmlRequire.FailuresView(j$, private$);
private$.PerformanceView = htmlRequire.PerformanceView(j$, private$);
private$.TabBar = htmlRequire.TabBar(j$, private$);
j$.HtmlReporterV2Urls = htmlRequire.HtmlReporterV2Urls(j$, private$);
j$.HtmlReporterV2 = htmlRequire.HtmlReporterV2(j$, private$);
j$.QueryString = htmlRequire.QueryString();
private$.HtmlSpecFilterV2 = htmlRequire.HtmlSpecFilterV2();
};
return getJasmineHtmlRequire;
})();
getJasmineHtmlRequireObj().ResultsNode = function() {
'use strict';
function ResultsNode(result, type, parent) {
@@ -68,7 +85,7 @@ jasmineRequire.ResultsNode = function() {
return ResultsNode;
};
jasmineRequire.QueryString = function() {
getJasmineHtmlRequireObj().QueryString = function() {
'use strict';
/**
@@ -154,10 +171,10 @@ jasmineRequire.QueryString = function() {
return QueryString;
};
jasmineRequire.AlertsView = function(j$) {
getJasmineHtmlRequireObj().AlertsView = function(j$, private$) {
'use strict';
const { createDom } = j$.private.htmlReporterUtils;
const { createDom } = private$.htmlReporterUtils;
const errorBarClassName = 'jasmine-bar jasmine-errored';
const afterAllMessagePrefix = 'AfterAll ';
@@ -273,10 +290,10 @@ jasmineRequire.AlertsView = function(j$) {
return AlertsView;
};
jasmineRequire.Banner = function(j$) {
getJasmineHtmlRequireObj().Banner = function(j$, private$) {
'use strict';
const { createDom } = j$.private.htmlReporterUtils;
const { createDom } = private$.htmlReporterUtils;
class Banner {
#navigateWithNewParam;
@@ -435,10 +452,10 @@ jasmineRequire.Banner = function(j$) {
return Banner;
};
jasmineRequire.FailuresView = function(j$) {
getJasmineHtmlRequireObj().FailuresView = function(j$, private$) {
'use strict';
const { createDom } = j$.private.htmlReporterUtils;
const { createDom } = private$.htmlReporterUtils;
class FailuresView {
#urlBuilder;
@@ -602,7 +619,7 @@ jasmineRequire.FailuresView = function(j$) {
return FailuresView;
};
jasmineRequire.htmlReporterUtils = function(j$) {
getJasmineHtmlRequireObj().htmlReporterUtils = function(j$, private$) {
'use strict';
function createDom(type, attrs, childrenArrayOrVarArgs) {
@@ -655,10 +672,10 @@ jasmineRequire.htmlReporterUtils = function(j$) {
return { createDom, noExpectations };
};
jasmineRequire.HtmlReporterV2 = function(j$) {
getJasmineHtmlRequireObj().HtmlReporterV2 = function(j$, private$) {
'use strict';
const { createDom, noExpectations } = j$.private.htmlReporterUtils;
const { createDom, noExpectations } = private$.htmlReporterUtils;
const specListTabId = 'jasmine-specListTab';
const failuresTabId = 'jasmine-failuresTab';
@@ -714,14 +731,14 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#config = options.env ? options.env.configuration() : {};
this.#stateBuilder = new j$.private.ResultsStateBuilder();
this.#stateBuilder = new private$.ResultsStateBuilder();
this.#alerts = new j$.private.AlertsView(this.#urlBuilder);
this.#statusBar = new j$.private.OverallStatusBar(this.#urlBuilder);
this.#alerts = new private$.AlertsView(this.#urlBuilder);
this.#statusBar = new private$.OverallStatusBar(this.#urlBuilder);
this.#statusBar.showRunning();
this.#alerts.addBar(this.#statusBar.rootEl);
this.#tabBar = new j$.private.TabBar(
this.#tabBar = new private$.TabBar(
[
{ id: specListTabId, label: 'Spec List' },
{ id: failuresTabId, label: 'Failures' },
@@ -740,11 +757,11 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
this.#alerts.addBar(this.#tabBar.rootEl);
this.#progress = new ProgressView();
this.#banner = new j$.private.Banner(
this.#banner = new private$.Banner(
this.#queryString.navigateWithNewParam.bind(this.#queryString),
true
);
this.#failures = new j$.private.FailuresView(this.#urlBuilder);
this.#failures = new private$.FailuresView(this.#urlBuilder);
this.#htmlReporterMain = createDom(
'div',
{ className: 'jasmine_html-reporter' },
@@ -825,13 +842,13 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
}
const results = this.#find('.jasmine-results');
const summary = new j$.private.SummaryTreeView(
const summary = new private$.SummaryTreeView(
this.#urlBuilder,
this.#filterSpecs
);
summary.addResults(this.#stateBuilder.topResults);
results.appendChild(summary.rootEl);
const perf = new j$.private.PerformanceView();
const perf = new private$.PerformanceView();
perf.addResults(this.#stateBuilder.topResults);
results.appendChild(perf.rootEl);
this.#tabBar.showTab(specListTabId);
@@ -935,7 +952,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
return HtmlReporterV2;
};
jasmineRequire.HtmlReporterV2Urls = function(j$) {
getJasmineHtmlRequireObj().HtmlReporterV2Urls = function(j$, private$) {
'use strict';
// TODO unify with V2 UrlBuilder?
@@ -986,7 +1003,7 @@ jasmineRequire.HtmlReporterV2Urls = function(j$) {
config.seed = seed;
}
const specFilter = new j$.private.HtmlSpecFilterV2({
const specFilter = new private$.HtmlSpecFilterV2({
filterParams: () => ({
path: this.queryString.getParam('path'),
spec: this.queryString.getParam('spec')
@@ -1008,7 +1025,7 @@ jasmineRequire.HtmlReporterV2Urls = function(j$) {
return HtmlReporterV2Urls;
};
jasmineRequire.HtmlSpecFilterV2 = function() {
getJasmineHtmlRequireObj().HtmlSpecFilterV2 = function() {
class HtmlSpecFilterV2 {
#getFilterParams;
@@ -1050,10 +1067,10 @@ jasmineRequire.HtmlSpecFilterV2 = function() {
return HtmlSpecFilterV2;
};
jasmineRequire.OverallStatusBar = function(j$) {
getJasmineHtmlRequireObj().OverallStatusBar = function(j$, private$) {
'use strict';
const { createDom } = j$.private.htmlReporterUtils;
const { createDom } = private$.htmlReporterUtils;
const staticClassNames = 'jasmine-overall-result jasmine-bar';
class OverallStatusBar {
@@ -1159,8 +1176,8 @@ jasmineRequire.OverallStatusBar = function(j$) {
return OverallStatusBar;
};
jasmineRequire.PerformanceView = function(j$) {
const createDom = j$.private.htmlReporterUtils.createDom;
getJasmineHtmlRequireObj().PerformanceView = function(j$, private$) {
const createDom = private$.htmlReporterUtils.createDom;
const MAX_SLOW_SPECS = 20;
class PerformanceView {
@@ -1258,12 +1275,12 @@ jasmineRequire.PerformanceView = function(j$) {
return PerformanceView;
};
jasmineRequire.ResultsStateBuilder = function(j$) {
getJasmineHtmlRequireObj().ResultsStateBuilder = function(j$, private$) {
'use strict';
class ResultsStateBuilder {
constructor() {
this.topResults = new j$.private.ResultsNode({}, '', null);
this.topResults = new private$.ResultsNode({}, '', null);
this.currentParent = this.topResults;
this.suitesById = {};
this.totalSpecsDefined = 0;
@@ -1341,10 +1358,10 @@ jasmineRequire.ResultsStateBuilder = function(j$) {
return ResultsStateBuilder;
};
jasmineRequire.SummaryTreeView = function(j$) {
getJasmineHtmlRequireObj().SummaryTreeView = function(j$, private$) {
'use strict';
const { createDom, noExpectations } = j$.private.htmlReporterUtils;
const { createDom, noExpectations } = private$.htmlReporterUtils;
class SummaryTreeView {
#urlBuilder;
@@ -1450,8 +1467,8 @@ jasmineRequire.SummaryTreeView = function(j$) {
return SummaryTreeView;
};
jasmineRequire.TabBar = function(j$) {
const createDom = j$.private.htmlReporterUtils.createDom;
getJasmineHtmlRequireObj().TabBar = function(j$, private$) {
const createDom = private$.htmlReporterUtils.createDom;
class TabBar {
#tabs;
@@ -1527,3 +1544,10 @@ jasmineRequire.TabBar = function(j$) {
return TabBar;
};
(function() {
'use strict';
getJasmineHtmlRequireObj().html(jasmine);
})();
})()