-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config/include): handle more errors in include
- Loading branch information
Showing
6 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect } from 'chai'; | ||
import { join } from 'path'; | ||
|
||
import { loadConfig } from '../../src/config'; | ||
import { NotFoundError } from '../../src/error/NotFoundError'; | ||
import { describeLeaks, itLeaks } from '../helpers/async'; | ||
|
||
describeLeaks('load config helper', async () => { | ||
itLeaks('should load an existing config', async () => { | ||
const config = await loadConfig('config-stderr.yml', join(__dirname, '..', 'docs')); | ||
expect(config.data.logger.name).to.equal('salty-dog'); | ||
}); | ||
|
||
itLeaks('should throw when config is missing', async () => { | ||
return expect(loadConfig('missing.yml', join(__dirname, '..', 'docs'))).to.eventually.be.rejectedWith(NotFoundError); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { envType } from '../../../src/config/type/Env'; | ||
import { NotFoundError } from '../../../src/error/NotFoundError'; | ||
import { VERSION_INFO } from '../../../src/version'; | ||
import { describeLeaks, itLeaks } from '../../helpers/async'; | ||
|
||
describeLeaks('env config type', async () => { | ||
itLeaks('should throw on missing variables', async () => { | ||
expect(() => { | ||
envType.resolve('DOES_NOT_EXIST_'); | ||
}).to.throw(NotFoundError); | ||
}); | ||
|
||
itLeaks('should resolve existing variables', async () => { | ||
expect(envType.resolve('CI_COMMIT_SHA')).to.equal(true); | ||
}); | ||
|
||
itLeaks('should construct a value from variables', async () => { | ||
expect(envType.construct('CI_COMMIT_SHA')).to.equal(VERSION_INFO.git.commit); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect } from 'chai'; | ||
import { BaseError } from 'noicejs'; | ||
import { join } from 'path'; | ||
|
||
import { includeType } from '../../../src/config/type/Include'; | ||
import { NotFoundError } from '../../../src/error/NotFoundError'; | ||
import { describeLeaks, itLeaks } from '../../helpers/async'; | ||
|
||
const TEST_ROOT = '../test/config/type'; | ||
|
||
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(() => { | ||
includeType.resolve(join(TEST_ROOT, 'missing.yml')); | ||
}).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(() => { | ||
includeType.construct(join(TEST_ROOT, 'missing.yml')); | ||
}).to.throw(BaseError); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { regexpType } from '../../../src/config/type/Regexp'; | ||
import { describeLeaks, itLeaks } from '../../helpers/async'; | ||
|
||
describeLeaks('regexp config type', async () => { | ||
itLeaks('match slashed strings', async () => { | ||
expect(regexpType.resolve('/foo/')).to.equal(true); | ||
}); | ||
|
||
itLeaks('should match flags', async () => { | ||
const regexp: RegExp = regexpType.construct('/foo/g'); | ||
expect(regexp.flags).to.equal('g'); | ||
}); | ||
|
||
itLeaks('should not match bare strings', async () => { | ||
expect(regexpType.resolve('foo')).to.equal(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |