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

@@ -42,8 +42,7 @@ async function zipStandaloneDist(jasmineVersion) {
'lib/jasmine-core/jasmine.js',
'lib/jasmine-core/jasmine-html.js',
'lib/jasmine-core/jasmine.css',
'lib/jasmine-core/boot0.js',
'lib/jasmine-core/boot1.js',
'lib/jasmine-core/boot.js',
],
destDir: 'lib/jasmine-' + jasmineVersion
},

View File

@@ -34,16 +34,20 @@ function concatFiles() {
const configs = [
{
src: [
{ literal: '(function() {' },
'src/html/requireHtml.js',
'src/html/ResultsNode.js',
'src/html/QueryString.js',
'src/html/**/*.js'
{ glob: 'src/html/**/*.js', exclude: 'src/html/requireSuffix.js' },
'src/html/requireSuffix.js',
{ literal: '})()' },
],
dest: 'lib/jasmine-core/jasmine-html.js',
},
{
dest: 'lib/jasmine-core/jasmine.js',
src: [
{ literal: '(function() {' },
'src/core/requireCore.js',
'src/core/matchers/requireMatchers.js',
'src/core/base.js',
@@ -53,20 +57,18 @@ function concatFiles() {
'src/core/Env.js',
'src/core/PrettyPrinter',
'src/core/Suite',
'src/core/**/*.js',
{ glob: 'src/core/**/*.js', exclude: 'src/core/requireSuffix.js'},
{
template: 'src/version.js',
data: {version: pkg.version}
},
'src/core/requireSuffix.js',
{ literal: '})()' },
],
},
{
dest: 'lib/jasmine-core/boot0.js',
src: ['src/boot/boot0.js'],
},
{
dest: 'lib/jasmine-core/boot1.js',
src: ['src/boot/boot1.js'],
dest: 'lib/jasmine-core/boot.js',
src: ['src/boot/boot.js'],
},
{
dest: 'lib/jasmine-core.js',
@@ -82,25 +84,28 @@ function concatFiles() {
src.unshift(licenseBanner);
function expand(srcListEntry) {
if (typeof srcListEntry === 'object') {
if (typeof srcListEntry === 'object' && !srcListEntry.glob) {
return srcListEntry;
}
return glob.sync(srcListEntry)
.sort(function (a, b) {
// Match the sort order of previous build tools, so that the
// output is the same.
a = a.toLowerCase();
b = b.toLowerCase();
const matches = glob.sync(
srcListEntry.glob ?? srcListEntry,
{ignore: srcListEntry.exclude}
);
return matches.sort(function (a, b) {
// Match the sort order of previous build tools, so that the
// output is the same.
a = a.toLowerCase();
b = b.toLowerCase();
if (a < b) {
return -1;
} else if (a === b) {
return 0;
} else {
return 1;
}
});
if (a < b) {
return -1;
} else if (a === b) {
return 0;
} else {
return 1;
}
});
}
const srcs = src.flatMap(expand);
@@ -114,6 +119,8 @@ function concatFiles() {
if (s.template) {
const template = fs.readFileSync(s.template, {encoding: 'utf8'});
content = ejs.render(template, s.data);
} else if (s.literal) {
content = s.literal;
} else {
content = fs.readFileSync(s, {encoding: 'utf8'});
}

View File

@@ -1,8 +1,9 @@
verifyNoGlobals(() => require('../lib/jasmine-core.js').noGlobals());
let jasmineCore;
verifyNoGlobals(() => { jasmineCore = require('../lib/jasmine-core.js'); });
jasmineCore.installGlobals();
const Jasmine = require('jasmine');
const jasmineCore = require('../lib/jasmine-core.js');
const runner = new Jasmine({jasmineCore: jasmineCore});
const runner = new Jasmine({jasmineCore});
runner.loadConfigFile('./spec/support/jasmine.json');
runner.exitOnCompletion = false;