Jeff Williams 85cbed9c0c change loading process for plugins and Markdown highlighters; remove jsdoc/path
We now simply use `require()` to load plugins and Markdown highlighters.

Note that `@jsdoc/util.path.commonPrefix`, unlike `jsdoc/path.commonPrefix`, does not append `path.sep` to the return value.

Includes other minor cleanup.
2019-01-27 15:18:28 -08:00

71 lines
2.2 KiB
JavaScript

/* global jsdoc */
describe('module names', () => {
const env = require('jsdoc/env');
const path = require('path');
let doclets;
const pwd = env.pwd;
let srcParser = null;
const sourceFiles = env.sourceFiles.slice(0);
const sourcePaths = env.opts._.slice(0);
beforeEach(() => {
env.opts._ = [path.normalize(`${env.pwd}/test/fixtures/modules/data/`)];
env.pwd = env.dirname;
env.sourceFiles = [];
srcParser = jsdoc.createParser();
require('jsdoc/src/handlers').attachTo(srcParser);
});
afterEach(() => {
env.opts._ = sourcePaths;
env.pwd = pwd;
env.sourceFiles = sourceFiles;
});
it('should create a name from the file path when no documented module name exists', () => {
const filename = 'test/fixtures/modules/data/mod-1.js';
env.sourceFiles.push(filename);
doclets = srcParser.parse(
path.normalize( path.join(env.pwd, filename) )
);
expect(doclets.length).toBeGreaterThan(1);
expect(doclets[0].longname).toBe('module:mod-1');
});
// Windows-specific test
if ( /^win/.test(require('os').platform()) ) {
it('should always use forward slashes when creating a name from the file path', () => {
const Doclet = require('jsdoc/doclet').Doclet;
let doclet;
env.sourceFiles = [
'C:\\Users\\Jane Smith\\myproject\\index.js',
'C:\\Users\\Jane Smith\\myproject\\lib\\mymodule.js'
];
env.opts._ = [];
doclet = new Doclet('/** @module */', {
lineno: 1,
filename: 'C:\\Users\\Jane Smith\\myproject\\lib\\mymodule.js'
});
expect(doclet.name).toBe('lib/mymodule');
});
}
it('should use the documented module name if available', () => {
const filename = 'test/fixtures/modules/data/mod-2.js';
env.sourceFiles.push(filename);
doclets = srcParser.parse(
path.normalize( path.join(env.pwd, filename) )
);
expect(doclets.length).toBeGreaterThan(1);
expect(doclets[0].longname).toBe('module:my/module/name');
});
});