Skip to content

Commit

Permalink
Fix #7: No needless async functions (#8)
Browse files Browse the repository at this point in the history
* Fix #7: No needless async functions

* Adapt tests to async less
  • Loading branch information
voxpelli authored Dec 14, 2022
1 parent 1041362 commit 95bc5b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ async function readSocketConfig (filePath) {

/**
* @param {string} fileContent
* @returns {Promise<SocketYml>}
* @returns {SocketYml}
* @throws {SocketValidationError}
*/
async function parseSocketConfig (fileContent) {
function parseSocketConfig (fileContent) {
/** @type {unknown} */
let parsedContent

Expand All @@ -114,7 +114,7 @@ async function parseSocketConfig (fileContent) {
}

if (parsedContent && typeof parsedContent === 'object' && !('version' in parsedContent)) {
const parsedV1 = await parseV1SocketConfig(parsedContent)
const parsedV1 = parseV1SocketConfig(parsedContent)
if (parsedV1) {
return parsedV1
}
Expand Down Expand Up @@ -167,9 +167,9 @@ class SocketValidationError extends Error {

/**
* @param {object} parsedV1Content
* @returns {Promise<SocketYml | undefined>}
* @returns {SocketYml | undefined}
*/
async function parseV1SocketConfig (parsedV1Content) {
function parseV1SocketConfig (parsedV1Content) {
if (!validateV1(parsedV1Content)) {
return
}
Expand Down
33 changes: 18 additions & 15 deletions test/parse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
} = require('../index.js')

chai.use(chaiAsPromised)
chai.should()
const should = chai.should()

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

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

await parseSocketConfig(fileContent).should.eventually.become({
parseSocketConfig(fileContent).should.deep.equal({
'githubApp': {
'enabled': true,
'projectReportsEnabled': false,
Expand All @@ -62,34 +62,37 @@ describe('parseSocketConfig()', () => {
})
})

it('should throw on invalid document structure', async () => {
await parseSocketConfig(`
it('should throw on invalid document structure', () => {
should.Throw(() => {
parseSocketConfig(`
projectIgnorePaths: true
`)
.should.be.rejectedWith(SocketValidationError, /Invalid config definition/)
}, SocketValidationError, /Invalid config definition/)
})

it('should throw error when not parseable', async () => {
await parseSocketConfig(`
it('should throw error when not parseable', () => {
should.Throw(() => {
parseSocketConfig(`
foo: abc, {{ bcd }} {{ cde }}
bar: {{ def }} {{ efg }}
`).should.be.rejectedWith(/Error when parsing socket\.yml config/)
`)
}, /Error when parsing socket\.yml config/)
})

it('should not return unknown properties', async () => {
await parseSocketConfig(`
it('should not return unknown properties', () => {
parseSocketConfig(`
version: 2
foo: true
`)
.should.eventually.become(defaults)
.should.deep.equal(defaults)
})

it('should coerce types', async () => {
await parseSocketConfig(`
it('should coerce types', () => {
parseSocketConfig(`
version: 2
projectIgnorePaths: foobar
`)
.should.eventually.become({
.should.deep.equal({
...defaults,
projectIgnorePaths: ['foobar'],
})
Expand Down

0 comments on commit 95bc5b6

Please sign in to comment.