Skip to content

Commit

Permalink
feat: lots of updates (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bugs5382 authored Jun 25, 2024
2 parents 60de797 + d33a4e3 commit 79b4f4e
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 118 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
jest.config.ts
/__tests__/*
vitest.config.ts
release.config.cjs
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug Report
about: Report a bug
labels: bug
---

## Search terms

<!-- Include keywords that might help others with the same problem find this issue -->

## Environment

- Fastify plugin version:
- TypeScript version:
- Node.js version:
- OS:

## Expected Behavior

<!-- How did you expect your code to work? -->

## Actual Behavior

<!-- What does this plugin fail to do? -->

## Steps to reproduce the bug

11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Question
about: Ask a question
labels: question
---

## Search terms

<!-- Include keywords that might help others with the same question find this issue -->

## Question
15 changes: 15 additions & 0 deletions .github/pr-title-checker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"LABEL": {
"name": "title needs formatting",
"color": "EEEEEE"
},
"CHECKS": {
"prefixes": ["[Bot] docs: "],
"regexp": "^(feat|fix|docs|test|ci|chore)!?(\\(.*\\))?!?:.*"
},
"MESSAGES": {
"success": "PR title is valid",
"failure": "PR title is invalid",
"notice": "PR Title needs to pass regex '^(feat|fix|docs|test|ci|chore)!?(\\(.*\\))?!?:.*"
}
}
52 changes: 52 additions & 0 deletions .github/workflows/dependabot-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Dependabot Auto-Merge

on:
pull_request_target:
types: [review_requested]

permissions:
contents: write
pull-requests: write
packages: read

jobs:
Dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GH_TOKEN }}"
skip-commit-verification: true
- name: Checkout repository
uses: actions/checkout@v4
- name: Approve PR, if not already approved
run: |
gh pr checkout "$PR_URL"
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ]; then
gh pr review --approve "$PR_URL"
else
echo "PR Already Approved.";
fi
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Run unit tests
run: |
npm test
- name: Aggregate Dependabot PRs
id: aggregate_prs
run: |
PR_URL=$(gh pr list --json state:open author:dependabot[bot] base:$PR_BASE_BRANCH -q '.[].url' | jq -r 'join(" ")')
echo "::set-output name=pr_url::$PR_URL"
env:
PR_BASE_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Merge aggregated PRs
if: steps.aggregate_prs.outputs.pr_url != ''
run: |
gh pr merge --auto --merge ${{ steps.aggregate_prs.outputs.pr_url }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
47 changes: 35 additions & 12 deletions .github/workflows/ci.yaml → .github/workflows/deploy-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: GitHub CI
name: "Deploy: CI"
on:
push:
branches: [ 'main' ]

permissions:
contents: write
issues: write
pull-requests: write
id-token: write

jobs:
Test:
runs-on: ubuntu-latest
services:
rabbitmq:
image: rabbitmq:3-alpine
image: rabbitmq:3.13.3-alpine
ports:
- 5672:5672
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
strategy:
matrix:
node-version: [ 20.x, 'lts/*' ]
Expand All @@ -29,16 +30,15 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install --ignore-scripts
- name: Run Lint Fix
run: npm run lint:fix
- name: Run Unit Tests
run: npm run test
env:
RABBITMQ_URL: amqp://guest:guest@localhost:5672
Release:
runs-on: ubuntu-latest
needs: [ 'Test' ]
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -59,3 +59,26 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Docs:
runs-on: ubuntu-latest
needs: [ 'Release' ]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: NPM Install
run: npm install --ignore-scripts
- name: Generate Typedoc documentation
run: npm run typedoc
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GH_TOKEN }}
publish_dir: ./docs
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
29 changes: 29 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "PR: Lint Title"

on:
pull_request_target:
types: [opened, edited, reopened, synchronize]

# IMPORTANT: No checkout actions, scripts, or builds should be added to this workflow. Permissions should always be used
# with extreme caution. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
permissions: {}

# PR updates can happen in quick succession, leading to this
# workflow being trigger a number of times. This limits it
# to one run per PR.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}


jobs:
Validate:
permissions:
contents: read
pull-requests: read
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- uses: thehanimo/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
configuration_path: ".github/pr-title-checker-config.json"
41 changes: 41 additions & 0 deletions .github/workflows/pr-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "PR: Unit Tests"

on:
pull_request:
branches:
- main
types:
- opened
- synchronize

jobs:
Test:
name: Run Unit tests
runs-on: ubuntu-latest
services:
rabbitmq:
image: rabbitmq:3.13.3-alpine
ports:
- 5672:5672
strategy:
matrix:
node-version: [ 20.x, 'lts/*' ]
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install --ignore-scripts
- name: Run Lint Fix
run: npm run lint:fix
- name: Run Unit Tests
run: npm run test
env:
RABBITMQ_URL: amqp://guest:guest@localhost:5672
- name: Check test results
run: exit ${{ steps.Test.outputs.test_result }}
id: check_test_result
6 changes: 4 additions & 2 deletions __tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { describe, expect, test, beforeEach, afterEach } from 'vitest'
import fastifyRabbit from '../src'
import { createDeferred, expectEvent, sleep } from './__utils__/utils'

const RABBITMQ_URL = process.env.RABBITMQ_URL || `amqp://guest:guest@localhost`

describe('fastify-rabbitmq sample app tests', () => {
describe('no namespace', () => {
let app: FastifyInstance
Expand All @@ -14,7 +16,7 @@ describe('fastify-rabbitmq sample app tests', () => {
app = fastify()

await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost'
connection: RABBITMQ_URL
})

await app.listen()
Expand Down Expand Up @@ -95,7 +97,7 @@ describe('fastify-rabbitmq sample app tests', () => {
app = fastify()

await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost',
connection: RABBITMQ_URL,
namespace: 'unittest'
})

Expand Down
36 changes: 9 additions & 27 deletions __tests__/rabbitmq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { errors } from '../src/errors'

let app: FastifyInstance

const RABBITMQ_URL = process.env.RABBITMQ_URL || `amqp://guest:guest@localhost`

beforeEach(() => {
app = fastify()
})
Expand Down Expand Up @@ -59,11 +61,11 @@ describe('plugin fastify-rabbitmq tests', () => {
test("register - can't be registered twice", async () => {
try {
await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost'
connection: RABBITMQ_URL
})

await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost'
connection: RABBITMQ_URL
})
} catch (err) {
expect(err).toEqual(new errors.FASTIFY_RABBIT_MQ_ERR_SETUP_ERRORS('Already registered.'))
Expand All @@ -73,12 +75,12 @@ describe('plugin fastify-rabbitmq tests', () => {
test("register - can't be registered twice - namespace", async () => {
try {
await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost',
connection: RABBITMQ_URL,
namespace: 'error'
})

await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost',
connection: RABBITMQ_URL,
namespace: 'error'
})
} catch (err) {
Expand Down Expand Up @@ -112,7 +114,7 @@ describe('plugin fastify-rabbitmq tests', () => {
test('ensure basic properties are accessible via namespace', async () => {
try {
await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost',
connection: RABBITMQ_URL,
namespace: 'unittest'
}).ready().then(async () => {
expect(app.rabbitmq.unittest).toHaveProperty('acquire')
Expand All @@ -135,7 +137,7 @@ describe('plugin fastify-rabbitmq tests', () => {
test('register with log level: debug', async () => {
try {
await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost',
connection: RABBITMQ_URL,
logLevel: 'debug'
}).ready().then(async () => {
expect(app.rabbitmq.unittest).toHaveProperty('createConsumer')
Expand All @@ -149,7 +151,7 @@ describe('plugin fastify-rabbitmq tests', () => {
test('register with log level: trace', async () => {
try {
await app.register(fastifyRabbit, {
connection: 'amqp://guest:guest@localhost',
connection: RABBITMQ_URL,
logLevel: 'trace'
}).ready().then(async () => {
expect(app.rabbitmq.unittest).toHaveProperty('createConsumer')
Expand All @@ -159,25 +161,5 @@ describe('plugin fastify-rabbitmq tests', () => {
/* should not error */
}
})

test('host does not exist', async () => {
try {
await app.register(fastifyRabbit, {
connection: 'amqp://doesnotexist'
})
} catch (e) {
expect(e).toBeTruthy()
}
})

test('invalid protocol', async () => {
try {
await app.register(fastifyRabbit, {
connection: 'xamqp://localhost'
})
} catch (e) {
expect(e).toBeTruthy()
}
})
})
})
Loading

0 comments on commit 79b4f4e

Please sign in to comment.