61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { IncludeOptions } from '@apextoaster/js-yaml-schema';
|
|
import { expect } from 'chai';
|
|
import { DEFAULT_SAFE_SCHEMA } from 'js-yaml';
|
|
import { match, stub } from 'sinon';
|
|
|
|
import { initConfig } from '../../src/config';
|
|
|
|
describe('config', () => {
|
|
describe('init config', () => {
|
|
it('should load a valid config', async () => {
|
|
const path = 'valid.yml';
|
|
const include: IncludeOptions = {
|
|
exists: stub(),
|
|
join: stub().returns(path),
|
|
read: stub().returns(`
|
|
logger:
|
|
level: info
|
|
name: test
|
|
projects: []
|
|
`),
|
|
resolve: stub(),
|
|
schema: DEFAULT_SAFE_SCHEMA,
|
|
};
|
|
|
|
const config = await initConfig(path, include);
|
|
expect(include.read).to.have.been.calledWith(path, match.object);
|
|
expect(config.logger.name).to.equal('test');
|
|
});
|
|
|
|
it('should throw on invalid config', async () => {
|
|
const include: IncludeOptions = {
|
|
exists: stub(),
|
|
join: stub().returnsArg(0),
|
|
read: stub().returns(`
|
|
logger: []
|
|
projects: {}
|
|
`),
|
|
resolve: stub(),
|
|
schema: DEFAULT_SAFE_SCHEMA,
|
|
};
|
|
|
|
await expect(initConfig('./invalid.yml', include)).to.eventually.be.rejectedWith(Error);
|
|
});
|
|
|
|
it('should throw on missing paths', async () => {
|
|
const err = new Error();
|
|
Reflect.set(err, 'code', 'ENOENT');
|
|
|
|
const include: IncludeOptions = {
|
|
exists: stub().returns(false),
|
|
join: stub().returnsArg(0),
|
|
read: stub().throws(err),
|
|
resolve: stub(),
|
|
schema: DEFAULT_SAFE_SCHEMA,
|
|
};
|
|
|
|
await expect(initConfig('.fake', include)).to.eventually.be.rejectedWith(Error);
|
|
});
|
|
});
|
|
});
|