Skip to content

Commit 1041362

Browse files
bcomnesvoxpelli
andauthored
Expose a function to get the default config (#6)
* Expose a function to get the default config This is useful for filling in gaps where the user doesn't have a config. * Add test for getDefaultConfig() + tweak exception Co-authored-by: Pelle Wessman <[email protected]>
1 parent 5e9e708 commit 1041362

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,19 @@ async function parseV1SocketConfig (parsedV1Content) {
189189
return v2
190190
}
191191

192+
/** @returns {SocketYml} */
193+
function getDefaultConfig () {
194+
const config = { version: 2 }
195+
196+
if (!validate(config)) {
197+
throw new Error('Unexpectedly invalid default config')
198+
}
199+
200+
return config
201+
}
202+
192203
module.exports = {
204+
getDefaultConfig,
193205
parseSocketConfig,
194206
readSocketConfig,
195207
SocketValidationError,

test/parse.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ const chai = require('chai')
77
const chaiAsPromised = require('chai-as-promised')
88

99
const {
10+
getDefaultConfig,
1011
parseSocketConfig,
1112
SocketValidationError,
1213
} = require('../index.js')
1314

1415
chai.use(chaiAsPromised)
1516
chai.should()
1617

18+
/** @type {import('../index.js').SocketYml} */
1719
const defaults = {
20+
'version': 2,
1821
'githubApp': {},
1922
'issueRules': {},
2023
'projectIgnorePaths': [],
@@ -78,7 +81,7 @@ bar: {{ def }} {{ efg }}
7881
version: 2
7982
foo: true
8083
`)
81-
.should.eventually.become({ version: 2, ...defaults })
84+
.should.eventually.become(defaults)
8285
})
8386

8487
it('should coerce types', async () => {
@@ -87,9 +90,14 @@ version: 2
8790
projectIgnorePaths: foobar
8891
`)
8992
.should.eventually.become({
90-
version: 2,
9193
...defaults,
9294
projectIgnorePaths: ['foobar'],
9395
})
9496
})
9597
})
98+
99+
describe('getDefaultConfig()', () => {
100+
it('should return a default config', () => {
101+
getDefaultConfig().should.deep.equal(defaults)
102+
})
103+
})

0 commit comments

Comments
 (0)