jasmine-core.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Note: Only available on Node.
  3. * @module jasmine-core
  4. */
  5. const jasmineRequire = require('./jasmine-core/jasmine.js');
  6. module.exports = jasmineRequire;
  7. const boot = (function() {
  8. let jasmine, jasmineInterface;
  9. return function bootWithoutGlobals(reinitialize) {
  10. if (!jasmineInterface || reinitialize === true) {
  11. jasmine = jasmineRequire.core(jasmineRequire);
  12. const env = jasmine.getEnv({ suppressLoadErrors: true });
  13. jasmineInterface = jasmineRequire.interface(jasmine, env);
  14. }
  15. return {jasmine, jasmineInterface};
  16. };
  17. }());
  18. /**
  19. * Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
  20. * If boot is called multiple times, the same object is returned every time
  21. * unless true is passed.
  22. * @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
  23. * @type {function}
  24. * @return {jasmine}
  25. */
  26. module.exports.boot = function(reinitialize) {
  27. const {jasmine, jasmineInterface} = boot(reinitialize);
  28. for (const k in jasmineInterface) {
  29. global[k] = jasmineInterface[k];
  30. }
  31. return jasmine;
  32. };
  33. /**
  34. * Boots a copy of Jasmine and returns an object containing the properties
  35. * that would normally be added to the global object. If noGlobals is called
  36. * multiple times, the same object is returned every time unless true is passed.
  37. *
  38. * @param {boolean} [reinitialize=false] Whether to create a new copy of Jasmine if one already exists
  39. * @example
  40. * const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
  41. */
  42. module.exports.noGlobals = function(reinitialize) {
  43. const {jasmineInterface} = boot(reinitialize);
  44. return jasmineInterface;
  45. };
  46. const path = require('path'),
  47. fs = require('fs');
  48. const rootPath = path.join(__dirname, 'jasmine-core'),
  49. bootFiles = ['boot0.js', 'boot1.js'],
  50. legacyBootFiles = ['boot.js'],
  51. cssFiles = [],
  52. jsFiles = [],
  53. jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles);
  54. fs.readdirSync(rootPath).forEach(function(file) {
  55. if(fs.statSync(path.join(rootPath, file)).isFile()) {
  56. switch(path.extname(file)) {
  57. case '.css':
  58. cssFiles.push(file);
  59. break;
  60. case '.js':
  61. if (jsFilesToSkip.indexOf(file) < 0) {
  62. jsFiles.push(file);
  63. }
  64. break;
  65. }
  66. }
  67. });
  68. module.exports.files = {
  69. self: __filename,
  70. path: rootPath,
  71. bootDir: rootPath,
  72. bootFiles: bootFiles,
  73. cssFiles: cssFiles,
  74. jsFiles: ['jasmine.js'].concat(jsFiles),
  75. imagesDir: path.join(__dirname, '../images')
  76. };