2019-10-29 03:41:52 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import { BaseError } from 'noicejs';
|
|
|
|
import { join } from 'path';
|
|
|
|
|
2019-11-16 01:22:13 +00:00
|
|
|
import { includeType, resolvePath } from '../../../src/config/type/Include';
|
2019-10-29 03:41:52 +00:00
|
|
|
import { NotFoundError } from '../../../src/error/NotFoundError';
|
|
|
|
import { describeLeaks, itLeaks } from '../../helpers/async';
|
|
|
|
|
|
|
|
const TEST_ROOT = '../test/config/type';
|
2019-11-16 01:01:28 +00:00
|
|
|
const CONFIG_MISSING = 'missing.yml';
|
2019-10-29 03:41:52 +00:00
|
|
|
|
|
|
|
describeLeaks('include config type', async () => {
|
|
|
|
itLeaks('should resolve existing files', async () => {
|
|
|
|
expect(includeType.resolve(join(TEST_ROOT, 'include.yml'))).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should throw when resolving missing files', async () => {
|
|
|
|
expect(() => {
|
2019-11-16 01:01:28 +00:00
|
|
|
includeType.resolve(join(TEST_ROOT, CONFIG_MISSING));
|
2019-10-29 03:41:52 +00:00
|
|
|
}).to.throw(NotFoundError);
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should construct data from file', async () => {
|
|
|
|
expect(includeType.construct(join(TEST_ROOT, 'include.yml'))).to.equal('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should throw when constructing missing files', async () => {
|
|
|
|
expect(() => {
|
2019-11-16 01:01:28 +00:00
|
|
|
includeType.construct(join(TEST_ROOT, CONFIG_MISSING));
|
|
|
|
}).to.throw(BaseError);
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should throw when resolving missing files', async () => {
|
|
|
|
expect(() => {
|
|
|
|
includeType.resolve(join(TEST_ROOT, CONFIG_MISSING));
|
2019-10-29 03:41:52 +00:00
|
|
|
}).to.throw(BaseError);
|
|
|
|
});
|
|
|
|
});
|
2019-11-16 01:22:13 +00:00
|
|
|
|
|
|
|
describeLeaks('resolve path helper', async () => {
|
|
|
|
itLeaks('should resolve relative paths relative to dirname', async () => {
|
|
|
|
expect(resolvePath('./index.js')).to.equal(join(__dirname, 'index.js'));
|
|
|
|
});
|
|
|
|
|
|
|
|
itLeaks('should resolve absolute paths to themselves', async () => {
|
|
|
|
expect(resolvePath('/')).to.equal('/');
|
|
|
|
});
|
|
|
|
});
|