-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): cover config loading, graph styles
- Loading branch information
Showing
4 changed files
with
182 additions
and
59 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
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 |
---|---|---|
@@ -1,8 +1,60 @@ | ||
import { IncludeOptions } from '@apextoaster/js-yaml-schema'; | ||
import { expect } from 'chai'; | ||
import { DEFAULT_SAFE_SCHEMA } from 'js-yaml'; | ||
import { match, stub } from 'sinon'; | ||
|
||
import { initConfig } from '../../src/config'; | ||
|
||
describe('config', () => { | ||
describe('init config', () => { | ||
it('should load a valid config'); | ||
it('should throw on invalid config'); | ||
it('should load a valid config', async () => { | ||
const path = 'valid.yml'; | ||
const include: IncludeOptions = { | ||
exists: stub(), | ||
join: stub().returns(path), | ||
read: stub().returns(` | ||
logger: | ||
level: info | ||
name: test | ||
projects: [] | ||
`), | ||
resolve: stub(), | ||
schema: DEFAULT_SAFE_SCHEMA, | ||
}; | ||
|
||
const config = await initConfig(path, include); | ||
expect(include.read).to.have.been.calledWith(path, match.object); | ||
expect(config.logger.name).to.equal('test'); | ||
}); | ||
|
||
it('should throw on invalid config', async () => { | ||
const include: IncludeOptions = { | ||
exists: stub(), | ||
join: stub().returnsArg(0), | ||
read: stub().returns(` | ||
logger: [] | ||
projects: {} | ||
`), | ||
resolve: stub(), | ||
schema: DEFAULT_SAFE_SCHEMA, | ||
}; | ||
|
||
await expect(initConfig('./invalid.yml', include)).to.eventually.be.rejectedWith(Error); | ||
}); | ||
|
||
it('should throw on missing paths', async () => { | ||
const err = new Error(); | ||
Reflect.set(err, 'code', 'ENOENT'); | ||
|
||
const include: IncludeOptions = { | ||
exists: stub().returns(false), | ||
join: stub().returnsArg(0), | ||
read: stub().throws(err), | ||
resolve: stub(), | ||
schema: DEFAULT_SAFE_SCHEMA, | ||
}; | ||
|
||
await expect(initConfig('.fake', include)).to.eventually.be.rejectedWith(Error); | ||
}); | ||
}); | ||
}); |
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