1
0
Fork 0

cover include path helper

This commit is contained in:
ssube 2019-11-15 19:22:13 -06:00 committed by Sean Sube
parent fb60b09db8
commit 79210654f0
2 changed files with 49 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import { expect } from 'chai';
import { BaseError } from 'noicejs';
import { join } from 'path';
import { includeType } from '../../../src/config/type/Include';
import { includeType, resolvePath } from '../../../src/config/type/Include';
import { NotFoundError } from '../../../src/error/NotFoundError';
import { describeLeaks, itLeaks } from '../../helpers/async';
@ -36,3 +36,13 @@ describeLeaks('include config type', async () => {
}).to.throw(BaseError);
});
});
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('/');
});
});

View File

@ -0,0 +1,38 @@
import { expect } from 'chai';
import { streamType } from '../../../src/config/type/Stream';
import { NotFoundError } from '../../../src/error/NotFoundError';
import { describeLeaks, itLeaks } from '../../helpers/async';
const TEST_STREAMS = [{
name: 'stderr',
stream: process.stderr,
}, {
name: 'stdin',
stream: process.stdin,
}, {
name: 'stdout',
stream: process.stdout,
}];
describeLeaks('stream config type', async () => {
itLeaks('should resolve allowed streams', async () => {
expect(streamType.resolve('stderr')).to.equal(true);
expect(streamType.resolve('stdout')).to.equal(true);
});
itLeaks('should throw when stream is not allowed', async () => {
expect(() => streamType.resolve('stdin')).to.throw(NotFoundError);
});
itLeaks('should throw when stream does not exist', async () => {
expect(() => streamType.resolve('imaginary')).to.throw(NotFoundError);
});
itLeaks('should construct streams', async () => {
for (const {name, stream} of TEST_STREAMS) {
expect(streamType.construct(name)).to.equal(stream, `should construct stream ${name}`);
}
});
});