From 72ecc70c5d7d1493887cce730d2f465d7fb43667 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 20 Sep 2025 06:35:48 -0700 Subject: [PATCH] Move jasmine-core.js source from lib to src --- lib/jasmine-core.js | 40 +++++++++++--- scripts/lib/buildDistribution.js | 4 ++ src/boot/jasmine-core.js | 89 ++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 src/boot/jasmine-core.js diff --git a/lib/jasmine-core.js b/lib/jasmine-core.js index 868874bc..326ccab1 100644 --- a/lib/jasmine-core.js +++ b/lib/jasmine-core.js @@ -1,3 +1,27 @@ +/* +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. +*/ + /** * Note: Only available on Node. * @module jasmine-core @@ -16,9 +40,9 @@ const bootWithoutGlobals = (function() { jasmineInterface = jasmineRequire.interface(jasmine, env); } - return {jasmine, jasmineInterface}; + return { jasmine, jasmineInterface }; }; -}()); +})(); /** * Boots a copy of Jasmine and returns an object as described in {@link jasmine}. @@ -31,7 +55,7 @@ module.exports.boot = function(reinitialize) { reinitialize = true; } - const {jasmine, jasmineInterface} = bootWithoutGlobals(reinitialize); + const { jasmine, jasmineInterface } = bootWithoutGlobals(reinitialize); for (const k in jasmineInterface) { global[k] = jasmineInterface[k]; @@ -49,7 +73,7 @@ module.exports.boot = function(reinitialize) { * const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals(); */ module.exports.noGlobals = function() { - const {jasmineInterface} = bootWithoutGlobals(false); + const { jasmineInterface } = bootWithoutGlobals(false); return jasmineInterface; }; @@ -64,16 +88,16 @@ const rootPath = path.join(__dirname, 'jasmine-core'), jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles); fs.readdirSync(rootPath).forEach(function(file) { - if(fs.statSync(path.join(rootPath, file)).isFile()) { - switch(path.extname(file)) { + if (fs.statSync(path.join(rootPath, file)).isFile()) { + switch (path.extname(file)) { case '.css': cssFiles.push(file); - break; + break; case '.js': if (jsFilesToSkip.indexOf(file) < 0) { jsFiles.push(file); } - break; + break; } } }); diff --git a/scripts/lib/buildDistribution.js b/scripts/lib/buildDistribution.js index f92587ac..5832a3d0 100644 --- a/scripts/lib/buildDistribution.js +++ b/scripts/lib/buildDistribution.js @@ -70,6 +70,10 @@ function concatFiles() { { dest: 'lib/jasmine-core/boot1.js', src: ['src/boot/boot1.js'], + }, + { + dest: 'lib/jasmine-core.js', + src: ['src/boot/jasmine-core.js'], } ]; const licenseBanner = { diff --git a/src/boot/jasmine-core.js b/src/boot/jasmine-core.js new file mode 100644 index 00000000..6d8878fc --- /dev/null +++ b/src/boot/jasmine-core.js @@ -0,0 +1,89 @@ +/** + * Note: Only available on Node. + * @module jasmine-core + */ + +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'); + +const rootPath = path.join(__dirname, 'jasmine-core'), + bootFiles = ['boot0.js', 'boot1.js'], + legacyBootFiles = ['boot.js'], + cssFiles = [], + jsFiles = [], + jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles); + +fs.readdirSync(rootPath).forEach(function(file) { + if (fs.statSync(path.join(rootPath, file)).isFile()) { + switch (path.extname(file)) { + case '.css': + cssFiles.push(file); + break; + case '.js': + if (jsFilesToSkip.indexOf(file) < 0) { + jsFiles.push(file); + } + break; + } + } +}); + +module.exports.files = { + self: __filename, + path: rootPath, + bootDir: rootPath, + bootFiles: bootFiles, + cssFiles: cssFiles, + jsFiles: ['jasmine.js'].concat(jsFiles), + imagesDir: path.join(__dirname, '../images') +};