modules.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. describe('module names', function() {
  3. var env = require('jsdoc/env');
  4. var path = require('jsdoc/path');
  5. var doclets;
  6. var pwd = env.pwd;
  7. var srcParser = null;
  8. var sourceFiles = env.sourceFiles.slice(0);
  9. var sourcePaths = env.opts._.slice(0);
  10. beforeEach(function() {
  11. env.opts._ = [path.normalize(env.pwd + '/test/fixtures/modules/data/')];
  12. env.pwd = env.dirname;
  13. env.sourceFiles = [];
  14. srcParser = jasmine.createParser();
  15. require('jsdoc/src/handlers').attachTo(srcParser);
  16. });
  17. afterEach(function() {
  18. env.opts._ = sourcePaths;
  19. env.pwd = pwd;
  20. env.sourceFiles = sourceFiles;
  21. });
  22. it('should create a name from the file path when no documented module name exists', function() {
  23. var filename = 'test/fixtures/modules/data/mod-1.js';
  24. env.sourceFiles.push(filename);
  25. doclets = srcParser.parse(
  26. path.normalize( path.join(env.pwd, filename) )
  27. );
  28. expect(doclets.length).toBeGreaterThan(1);
  29. expect(doclets[0].longname).toBe('module:mod-1');
  30. });
  31. // Windows-specific test
  32. if ( /^win/.test(require('os').platform()) ) {
  33. it('should always use forward slashes when creating a name from the file path', function() {
  34. var Doclet = require('jsdoc/doclet').Doclet;
  35. var doclet;
  36. env.sourceFiles = [
  37. 'C:\\Users\\Jane Smith\\myproject\\index.js',
  38. 'C:\\Users\\Jane Smith\\myproject\\lib\\mymodule.js'
  39. ];
  40. env.opts._ = [];
  41. doclet = new Doclet('/** @module */', {
  42. lineno: 1,
  43. filename: 'C:\\Users\\Jane Smith\\myproject\\lib\\mymodule.js'
  44. });
  45. expect(doclet.name).toBe('lib/mymodule');
  46. });
  47. }
  48. it('should use the documented module name if available', function() {
  49. var filename = 'test/fixtures/modules/data/mod-2.js';
  50. env.sourceFiles.push(filename);
  51. doclets = srcParser.parse(
  52. path.normalize( path.join(env.pwd, filename) )
  53. );
  54. expect(doclets.length).toBeGreaterThan(1);
  55. expect(doclets[0].longname).toBe('module:my/module/name');
  56. });
  57. });