mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
`@jsdoc/cli` deals with command-line arguments, and `@jsdoc/util` casts values to appropriate types.
116 lines
3.1 KiB
JavaScript
116 lines
3.1 KiB
JavaScript
describe('@jsdoc/config', () => {
|
|
const mockFs = require('mock-fs');
|
|
const config = require('../../index');
|
|
const defaults = require('../../lib/defaults');
|
|
|
|
afterEach(() => mockFs.restore());
|
|
|
|
it('exists', () => {
|
|
expect(config).toBeObject();
|
|
});
|
|
|
|
it('has a defaults object', () => {
|
|
expect(config.defaults).toBeObject();
|
|
});
|
|
|
|
it('has a loadSync method', () => {
|
|
expect(config.loadSync).toBeFunction();
|
|
});
|
|
|
|
describe('defaults', () => {
|
|
it('is ./lib/defaults', () => {
|
|
expect(config.defaults).toBe(defaults);
|
|
});
|
|
});
|
|
|
|
describe('loadSync', () => {
|
|
it('returns an object with `config` and `filepath` properties', () => {
|
|
mockFs({
|
|
'conf.json': '{}'
|
|
});
|
|
|
|
const conf = config.loadSync('conf.json');
|
|
|
|
expect(conf.config).toBeObject();
|
|
expect(conf.filepath).toEndWith('conf.json');
|
|
});
|
|
|
|
it('loads settings from the specified filepath if there is one', () => {
|
|
mockFs({
|
|
'conf.json': '{"foo":"bar"}'
|
|
});
|
|
|
|
const conf = config.loadSync('conf.json');
|
|
|
|
expect(conf.config.foo).toBe('bar');
|
|
});
|
|
|
|
it('finds the config file when no filepath is specified', () => {
|
|
mockFs({
|
|
'package.json': '{"jsdoc":{"foo":"bar"}}'
|
|
});
|
|
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config.foo).toBe('bar');
|
|
});
|
|
|
|
it('parses JSON config files that have an extension and contain comments', () => {
|
|
mockFs({
|
|
'.jsdocrc.json': '// comment\n{"foo":"bar"}'
|
|
});
|
|
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config.foo).toBe('bar');
|
|
});
|
|
|
|
it('parses JSON files that start with a BOM', () => {
|
|
mockFs({
|
|
'.jsdocrc.json': '\uFEFF{"foo":"bar"}'
|
|
});
|
|
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config.foo).toBe('bar');
|
|
});
|
|
|
|
it('parses YAML files that start with a BOM', () => {
|
|
mockFs({
|
|
'.jsdocrc.yaml': '\uFEFF{"foo":"bar"}'
|
|
});
|
|
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config.foo).toBe('bar');
|
|
});
|
|
|
|
it('provides the default config if the user config is an empty object', () => {
|
|
mockFs({
|
|
'.jsdocrc.json': '{}'
|
|
});
|
|
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config).toEqual(defaults);
|
|
});
|
|
|
|
it('provides the default config if there is no user config', () => {
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config).toEqual(defaults);
|
|
});
|
|
|
|
it('merges nested defaults with nested user settings as expected', () => {
|
|
mockFs({
|
|
'.jsdocrc.json': '{"tags":{"foo":"bar"}}'
|
|
});
|
|
|
|
const conf = config.loadSync();
|
|
|
|
expect(conf.config.tags.allowUnknownTags).toBe(defaults.tags.allowUnknownTags);
|
|
expect(conf.config.tags.foo).toBe('bar');
|
|
});
|
|
});
|
|
});
|