env-cmd/test/utils.spec.ts
Todd Bluhm 56ed009d7b
Convert EnvCmd to Typescript
- Complete rewrite and reorganization
- Expose a usable programmatic API
- Support Async .env files by accepting javascript files
- Update all libraries/dependencies
- Support for more options in the future by using commanderjs
- More thorough test cases and code-coverage
- Better handling of signal terminations for both parent and child
processes
- Use ESLint Standard with Typescript
2019-05-04 02:16:03 -05:00

56 lines
1.7 KiB
TypeScript

import * as os from 'os'
import * as process from 'process'
import { assert } from 'chai'
import * as sinon from 'sinon'
import { resolveEnvFilePath, parseArgList, isPromise } from '../src/utils'
describe('utils', (): void => {
describe('resolveEnvFilePath', (): void => {
const homePath = os.homedir()
const currentDir = process.cwd()
afterEach((): void => {
sinon.restore()
})
it('should return an absolute path, given a relative path', (): void => {
const res = resolveEnvFilePath('./bob')
assert.equal(res, `${currentDir}/bob`)
})
it('should return an absolute path, given a path with ~ for home directory', (): void => {
const res = resolveEnvFilePath('~/bob')
assert.equal(res, `${homePath}/bob`)
})
it('should not attempt to replace ~ if home dir does not exist', (): void => {
sinon.stub(os, 'homedir')
const res = resolveEnvFilePath('~/bob')
assert.equal(res, `${currentDir}/~/bob`)
})
})
describe('parseArgList', (): void => {
it('should parse a cli arg list', (): void => {
const res = parseArgList('thanks,for,all,the,fish')
assert.lengthOf(res, 5)
assert.includeOrderedMembers(res, ['thanks', 'for', 'all', 'the', 'fish'])
})
})
describe('isPromise', (): void => {
it('should return true for bluebird promise', (): void => {
const res = isPromise(Promise.resolve())
assert.isTrue(res)
})
it('should return true for native promise', (): void => {
const res = isPromise(Promise.resolve())
assert.isTrue(res)
})
it('should return false for plain object', (): void => {
const res = isPromise({})
assert.isFalse(res)
})
})
})