diff --git a/test/config/type/TestInclude.ts b/test/config/type/TestInclude.ts index e3603d7..80dc078 100644 --- a/test/config/type/TestInclude.ts +++ b/test/config/type/TestInclude.ts @@ -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('/'); + }); +}); diff --git a/test/config/type/TestStream.ts b/test/config/type/TestStream.ts new file mode 100644 index 0000000..f38baa7 --- /dev/null +++ b/test/config/type/TestStream.ts @@ -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}`); + } + }); +}); +