Skip to content

Commit 95bc5b6

Browse files
authored
Fix #7: No needless async functions (#8)
* Fix #7: No needless async functions * Adapt tests to async less
1 parent 1041362 commit 95bc5b6

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ async function readSocketConfig (filePath) {
100100

101101
/**
102102
* @param {string} fileContent
103-
* @returns {Promise<SocketYml>}
103+
* @returns {SocketYml}
104104
* @throws {SocketValidationError}
105105
*/
106-
async function parseSocketConfig (fileContent) {
106+
function parseSocketConfig (fileContent) {
107107
/** @type {unknown} */
108108
let parsedContent
109109

@@ -114,7 +114,7 @@ async function parseSocketConfig (fileContent) {
114114
}
115115

116116
if (parsedContent && typeof parsedContent === 'object' && !('version' in parsedContent)) {
117-
const parsedV1 = await parseV1SocketConfig(parsedContent)
117+
const parsedV1 = parseV1SocketConfig(parsedContent)
118118
if (parsedV1) {
119119
return parsedV1
120120
}
@@ -167,9 +167,9 @@ class SocketValidationError extends Error {
167167

168168
/**
169169
* @param {object} parsedV1Content
170-
* @returns {Promise<SocketYml | undefined>}
170+
* @returns {SocketYml | undefined}
171171
*/
172-
async function parseV1SocketConfig (parsedV1Content) {
172+
function parseV1SocketConfig (parsedV1Content) {
173173
if (!validateV1(parsedV1Content)) {
174174
return
175175
}

test/parse.spec.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
} = require('../index.js')
1414

1515
chai.use(chaiAsPromised)
16-
chai.should()
16+
const should = chai.should()
1717

1818
/** @type {import('../index.js').SocketYml} */
1919
const defaults = {
@@ -27,7 +27,7 @@ describe('parseSocketConfig()', () => {
2727
it('should read and parse socket.yml', async () => {
2828
const fileContent = await readFile(path.resolve(__dirname, 'sample.yml'), 'utf8')
2929

30-
await parseSocketConfig(fileContent).should.eventually.become({
30+
parseSocketConfig(fileContent).should.deep.equal({
3131
'githubApp': {
3232
'enabled': true,
3333
'projectReportsEnabled': true,
@@ -47,7 +47,7 @@ describe('parseSocketConfig()', () => {
4747
it('should read and parse socket.yml v1', async () => {
4848
const fileContent = await readFile(path.resolve(__dirname, 'sample-v1.yml'), 'utf8')
4949

50-
await parseSocketConfig(fileContent).should.eventually.become({
50+
parseSocketConfig(fileContent).should.deep.equal({
5151
'githubApp': {
5252
'enabled': true,
5353
'projectReportsEnabled': false,
@@ -62,34 +62,37 @@ describe('parseSocketConfig()', () => {
6262
})
6363
})
6464

65-
it('should throw on invalid document structure', async () => {
66-
await parseSocketConfig(`
65+
it('should throw on invalid document structure', () => {
66+
should.Throw(() => {
67+
parseSocketConfig(`
6768
projectIgnorePaths: true
6869
`)
69-
.should.be.rejectedWith(SocketValidationError, /Invalid config definition/)
70+
}, SocketValidationError, /Invalid config definition/)
7071
})
7172

72-
it('should throw error when not parseable', async () => {
73-
await parseSocketConfig(`
73+
it('should throw error when not parseable', () => {
74+
should.Throw(() => {
75+
parseSocketConfig(`
7476
foo: abc, {{ bcd }} {{ cde }}
7577
bar: {{ def }} {{ efg }}
76-
`).should.be.rejectedWith(/Error when parsing socket\.yml config/)
78+
`)
79+
}, /Error when parsing socket\.yml config/)
7780
})
7881

79-
it('should not return unknown properties', async () => {
80-
await parseSocketConfig(`
82+
it('should not return unknown properties', () => {
83+
parseSocketConfig(`
8184
version: 2
8285
foo: true
8386
`)
84-
.should.eventually.become(defaults)
87+
.should.deep.equal(defaults)
8588
})
8689

87-
it('should coerce types', async () => {
88-
await parseSocketConfig(`
90+
it('should coerce types', () => {
91+
parseSocketConfig(`
8992
version: 2
9093
projectIgnorePaths: foobar
9194
`)
92-
.should.eventually.become({
95+
.should.deep.equal({
9396
...defaults,
9497
projectIgnorePaths: ['foobar'],
9598
})

0 commit comments

Comments
 (0)