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

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
@@ -24,70 +24,25 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
/**
* Note: Only available on Node.
* @module jasmine-core
*/
const path = require('path');
const fs = require('fs');
const {
globals,
installGlobals,
private$
} = require('./jasmine-core/jasmine.js');
const jasmineRequire = require('./jasmine-core/jasmine.js');
module.exports = jasmineRequire;
const bootWithoutGlobals = (function() {
let jasmine, jasmineInterface;
return function bootWithoutGlobals(reinitialize) {
if (!jasmineInterface || reinitialize === true) {
jasmine = jasmineRequire.core(jasmineRequire);
const env = jasmine.getEnv({ suppressLoadErrors: true });
jasmineInterface = jasmineRequire.interface(jasmine, env);
}
return { jasmine, jasmineInterface };
};
})();
/**
* Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
* @param {boolean} [reinitialize=true] Whether to create a new copy of Jasmine if one already exists
* @type {function}
* @return {jasmine}
*/
module.exports.boot = function(reinitialize) {
if (reinitialize === undefined) {
reinitialize = true;
}
const { jasmine, jasmineInterface } = bootWithoutGlobals(reinitialize);
for (const k in jasmineInterface) {
global[k] = jasmineInterface[k];
}
return jasmine;
};
/**
* Boots a copy of Jasmine and returns an object containing the properties
* that would normally be added to the global object. If noGlobals is called
* multiple times, the same object is returned every time.
*
* @example
* const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
*/
module.exports.noGlobals = function() {
const { jasmineInterface } = bootWithoutGlobals(false);
return jasmineInterface;
};
const path = require('path'),
fs = require('fs');
function reset() {
private$.currentEnv_ = null;
const env = jasmine.getEnv({ suppressLoadErrors: true });
rebindInterface(env);
}
const rootPath = path.join(__dirname, 'jasmine-core'),
bootFiles = ['boot0.js', 'boot1.js'],
legacyBootFiles = ['boot.js'],
bootFiles = ['boot.js'],
cssFiles = [],
jsFiles = [],
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles);
jsFilesToSkip = ['jasmine.js'].concat(bootFiles);
fs.readdirSync(rootPath).forEach(function(file) {
if (fs.statSync(path.join(rootPath, file)).isFile()) {
@@ -104,12 +59,35 @@ fs.readdirSync(rootPath).forEach(function(file) {
}
});
module.exports.files = {
self: __filename,
path: rootPath,
bootDir: rootPath,
bootFiles: bootFiles,
cssFiles: cssFiles,
jsFiles: ['jasmine.js'].concat(jsFiles),
imagesDir: path.join(__dirname, '../images')
/**
* Note: Only available on Node.
*
* In addition to the members documented here, this module's exports include all
* {@link globals}.
* @module jasmine-core
*/
module.exports = {
...globals,
/**
* Copies Jasmine globals (jasmine, describe, it, etc) to the specified
* object or to globalThis.
* @function
* @param {object} [dest] - The object to copy globals to.
*/
installGlobals,
/**
* Resets all of jasmine-core's state, including removing specs, suites, and
* reporters, and resetting configuration to the default.
* @function
*/
reset,
files: {
self: __filename,
path: rootPath,
bootDir: rootPath,
bootFiles: bootFiles,
cssFiles: cssFiles,
jsFiles: ['jasmine.js'].concat(jsFiles),
imagesDir: path.join(__dirname, '../images')
}
};

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
@@ -24,19 +24,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
/**
This file finishes 'booting' Jasmine, performing all of the necessary
initialization before executing the loaded environment and all of a project's
specs. This file should be loaded after `boot0.js` but before any project
source files or spec files are loaded. Thus this file can also be used to
customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can
be customized directly. If you only wish to configure the Jasmine env, you
can load another file that calls `jasmine.getEnv().configure({...})`
after `boot0.js` is loaded and before this file is loaded.
*/
(function() {
const env = jasmine.getEnv();
const urls = new jasmine.HtmlReporterV2Urls();
@@ -49,11 +36,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
env.configure(urls.configFromCurrentUrl());
window.addEventListener('load', function() {
const currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
// The HTML reporter needs to be set up here so it can access the DOM. Other
// reporters can be added at any time before env.execute() is called.
const htmlReporter = new jasmine.HtmlReporterV2({ env, urls });
env.addReporter(htmlReporter);
env.execute();
});
};
})();

View File

@@ -1,68 +0,0 @@
/*
Copyright (c) 2008-2019 Pivotal Labs
Copyright (c) 2008-2025 The Jasmine developers
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
'use strict';
/**
This file starts the process of "booting" Jasmine. It initializes Jasmine,
makes its globals available, and creates the env. This file should be loaded
after `jasmine.js` and `jasmine_html.js`, but before `boot1.js` or any project
source files or spec files are loaded.
*/
(function() {
const jasmineRequire = window.jasmineRequire || require('./jasmine.js');
/**
* ## Require & Instantiate
*
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
*/
const jasmine = jasmineRequire.core(jasmineRequire),
global = jasmine.getGlobal();
global.jasmine = jasmine;
/**
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
*/
jasmineRequire.html(jasmine);
/**
* Create the Jasmine environment. This is used to run all specs in a project.
*/
const env = jasmine.getEnv();
/**
* ## The Global Interface
*
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
*/
const jasmineInterface = jasmineRequire.interface(jasmine, env);
/**
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
*/
for (const property in jasmineInterface) {
global[property] = jasmineInterface[property];
}
})();

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

File diff suppressed because it is too large Load Diff