mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
It turns out that JSDoc's dependency-injection needs are pretty simple; we mostly just need to pass around some data, plus some logging functions. That means the previous solution was overengineered, even though it was still pretty lightweight. Now we just put everything in the `Env` object and pass that around instead.
94 lines
2.5 KiB
JavaScript
94 lines
2.5 KiB
JavaScript
/*
|
|
Copyright 2019 the JSDoc Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import EventEmitter from 'node:events';
|
|
|
|
import Env from '../../../lib/env.js';
|
|
|
|
describe('@jsdoc/core.Env', () => {
|
|
it('is a constructor', () => {
|
|
function factory() {
|
|
return new Env();
|
|
}
|
|
|
|
expect(factory).not.toThrow();
|
|
});
|
|
|
|
describe('properties', () => {
|
|
const env = new Env();
|
|
|
|
it('has an `args` property', () => {
|
|
expect(env.args).toBeArray();
|
|
});
|
|
|
|
it('has a `conf` property', () => {
|
|
expect(env.conf).toBeObject();
|
|
});
|
|
|
|
it('has a `config` getter', () => {
|
|
expect(env.config).toBe(env.conf);
|
|
});
|
|
|
|
it('has an `emitter` property that contains an event emitter', () => {
|
|
expect(env.emitter).toBeInstanceOf(EventEmitter);
|
|
});
|
|
|
|
it('has an `env` getter', () => {
|
|
expect(env.env).toBe(env);
|
|
});
|
|
|
|
it('has a `get` method that returns the value of the specified property', () => {
|
|
expect(env.get('sourceFiles')).toBe(env.sourceFiles);
|
|
});
|
|
|
|
it('has a `log` property that contains logging functions', () => {
|
|
expect(env.log).toBeObject();
|
|
|
|
for (const key of Object.keys(env.log)) {
|
|
expect(env.log[key]).toBeFunction();
|
|
}
|
|
});
|
|
|
|
it('has an `options` getter', () => {
|
|
expect(env.options).toBe(env.opts);
|
|
});
|
|
|
|
it('has an `opts` property', () => {
|
|
expect(env.opts).toBeObject();
|
|
});
|
|
|
|
it('has a `run` object with `start` and `finish` properties', () => {
|
|
expect(env.run).toBeObject();
|
|
expect(env.run.finish).toBeNull();
|
|
expect(env.run.start).toBeInstanceOf(Date);
|
|
});
|
|
|
|
it('has a `sourceFiles` property', () => {
|
|
expect(env.sourceFiles).toBeArray();
|
|
});
|
|
|
|
it('has a `tags` property', () => {
|
|
expect(env.tags).toBeNull();
|
|
});
|
|
|
|
it('has a `version` object with `number` and `revision` properties', () => {
|
|
expect(env.version).toBeObject();
|
|
expect(Object.hasOwn(env.version, 'number')).toBeTrue();
|
|
expect(Object.hasOwn(env.version, 'revision')).toBeTrue();
|
|
});
|
|
});
|
|
});
|