Skip to content

More updates and maintenance #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .husky/pre-push

This file was deleted.

20 changes: 7 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -30,15 +30,12 @@
"build:1-declaration": "tsc -p declaration.tsconfig.json",
"build:2-schema-file": "echo \"console.log(JSON.stringify(require('.').socketYmlSchema, undefined, 2))\" | node > schema.json",
"build": "run-s build:*",
"check:dependency-check": "dependency-check '*.js' 'test/**/*.js' --no-dev",
"check:installed-check": "installed-check -i eslint-plugin-jsdoc",
"check:lint": "eslint --report-unused-disable-directives .",
"check:tsc": "tsc",
"check:type-coverage": "type-coverage --detail --strict --at-least 95 --ignore-files 'test/*'",
"check": "run-p -c --aggregate-output check:*",
"clean:declarations": "rm -rf $(find . -maxdepth 2 -type f -name '*.d.ts*')",
"clean": "run-p clean:*",
"prepare": "husky install",
"prepublishOnly": "git push --follow-tags && gh-release -y && run-s build",
"test:mocha": "c8 --reporter=lcov --reporter text mocha 'test/**/*.spec.js'",
"test-ci": "run-s test:*",
@@ -48,20 +45,17 @@
"version:git": "git add CHANGELOG.md"
},
"devDependencies": {
"@tsconfig/node14": "^14.1.3",
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@tsconfig/node22": "^22.0.1",
"@types/chai": "^5.2.2",
"@types/chai-as-promised": "^8.0.2",
"@types/mocha": "^10.0.0",
"@types/node": "^14.18.36",
"@types/node": "^22.15.19",
"c8": "^10.1.3",
"chai": "^4.3.6",
"chai": "^5.2.0",
"chai-as-promised": "^8.0.1",
"dependency-check": "^5.0.0-7",
"husky": "^8.0.3",
"installed-check": "^9.3.0",
"mocha": "^10.0.0",
"mocha": "^11.4.0",
"neostandard": "^0.12.0",
"npm-run-all2": "^6.0.2",
"npm-run-all2": "^8.0.2",
"type-coverage": "^2.24.1",
"typescript": "~5.8.3",
"auto-changelog": "^2.4.0",
37 changes: 18 additions & 19 deletions test/parse.spec.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const { readFile } = require('node:fs/promises')
const path = require('node:path')

const chai = require('chai')
const { expect } = chai
const { default: chaiAsPromised } = require('chai-as-promised')

const {
@@ -13,7 +14,6 @@ const {
} = require('../index.js')

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

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

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

parseSocketConfig(fileContent).should.deep.equal({
expect(parseSocketConfig(fileContent)).to.deep.equal({
githubApp: {
enabled: true,
projectReportsEnabled: false,
pullRequestAlertsEnabled: true,
},
issueRules: {},
projectIgnorePaths: [
'foo',
'bar',
],
projectIgnorePaths: ['foo', 'bar'],
version: 2,
})
})

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

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

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

it('should coerce types', () => {
parseSocketConfig(`
expect(
parseSocketConfig(`
version: 2
projectIgnorePaths: foobar
`)
.should.deep.equal({
...defaults,
projectIgnorePaths: ['foobar'],
})
).to.deep.equal({
...defaults,
projectIgnorePaths: ['foobar'],
})
})
})

describe('getDefaultConfig()', () => {
it('should return a default config', () => {
getDefaultConfig().should.deep.equal(defaults)
expect(getDefaultConfig()).to.deep.equal(defaults)
})
})
16 changes: 10 additions & 6 deletions test/read.spec.js
Original file line number Diff line number Diff line change
@@ -3,18 +3,20 @@
const path = require('node:path')

const chai = require('chai')
const { expect } = chai
const { default: chaiAsPromised } = require('chai-as-promised')

const {
readSocketConfig
} = require('../index.js')

chai.use(chaiAsPromised)
chai.should()

describe('readSocketConfig()', () => {
it('should read and parse socket.yml', async () => {
await readSocketConfig(path.resolve(__dirname, 'sample.yml')).should.eventually.become({
await expect(
readSocketConfig(path.resolve(__dirname, 'sample.yml'))
).to.eventually.deep.equal({
githubApp: {
enabled: true,
projectReportsEnabled: true,
@@ -32,12 +34,14 @@ describe('readSocketConfig()', () => {
})

it('should fail silently when file not found', async () => {
await readSocketConfig(path.resolve(__dirname, 'non-existing.yml'))
.should.eventually.become(undefined)
await expect(
readSocketConfig(path.resolve(__dirname, 'non-existing.yml'))
).to.eventually.equal(undefined)
})

it('should throw error when given a non-file', async () => {
await readSocketConfig(__dirname)
.should.be.rejectedWith(/Error when reading socket\.yml config file/)
await expect(
readSocketConfig(__dirname)
).to.be.rejectedWith(/Error when reading socket\.yml config file/)
})
})
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@tsconfig/node22/tsconfig.json",
"files": [
"index.js"
],