jasmine-core.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  8. * Boots a copy of Jasmine and returns an object as described in {@link jasmine}.
  9. * @type {function}
  10. * @return {jasmine}
  11. */
  12. module.exports.boot = require('./jasmine-core/node_boot.js');
  13. /**
  14. * Boots a copy of Jasmine and returns an object containing the properties
  15. * that would normally be added to the global object. If noGlobals is called
  16. * multiple times, the same object is returned every time.
  17. *
  18. * Do not call boot() if you also call noGlobals().
  19. *
  20. * @example
  21. * const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();
  22. */
  23. module.exports.noGlobals = (function() {
  24. let jasmineInterface;
  25. return function bootWithoutGlobals() {
  26. if (!jasmineInterface) {
  27. const jasmine = jasmineRequire.core(jasmineRequire);
  28. const env = jasmine.getEnv({ suppressLoadErrors: true });
  29. jasmineInterface = jasmineRequire.interface(jasmine, env);
  30. }
  31. return jasmineInterface;
  32. };
  33. }());
  34. const path = require('path'),
  35. fs = require('fs');
  36. const rootPath = path.join(__dirname, 'jasmine-core'),
  37. bootFiles = ['boot0.js', 'boot1.js'],
  38. legacyBootFiles = ['boot.js'],
  39. nodeBootFiles = ['node_boot.js'],
  40. cssFiles = [],
  41. jsFiles = [],
  42. jsFilesToSkip = ['jasmine.js'].concat(bootFiles, legacyBootFiles, nodeBootFiles);
  43. fs.readdirSync(rootPath).forEach(function(file) {
  44. if(fs.statSync(path.join(rootPath, file)).isFile()) {
  45. switch(path.extname(file)) {
  46. case '.css':
  47. cssFiles.push(file);
  48. break;
  49. case '.js':
  50. if (jsFilesToSkip.indexOf(file) < 0) {
  51. jsFiles.push(file);
  52. }
  53. break;
  54. }
  55. }
  56. });
  57. module.exports.files = {
  58. path: rootPath,
  59. bootDir: rootPath,
  60. bootFiles: bootFiles,
  61. nodeBootFiles: nodeBootFiles,
  62. cssFiles: cssFiles,
  63. jsFiles: ['jasmine.js'].concat(jsFiles),
  64. imagesDir: path.join(__dirname, '../images')
  65. };