Skip to content

Commit

Permalink
Merge pull request #53 from lafayette/github-actions
Browse files Browse the repository at this point in the history
switch to github actions, fix some tests
  • Loading branch information
titarenko authored Oct 17, 2024
2 parents 37c84a6 + 31a0ada commit 688f3d8
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 60 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: main

on:
push:
branches:
- master
pull_request:
branches:
- master

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

jobs:
linter:
name: run eslint
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: latest

- name: Install Node.js dependencies
run: npm install --include=dev

- name: Run linter with report
run: npm run lint
continue-on-error: true

- name: Save linting report
run: npx eslint --output-file eslint_report.json --format json .
continue-on-error: true

- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report-json: "eslint_report.json"
tests:
name: run tests and coverage report
runs-on: ubuntu-latest
env:
NODE_ENV: development
BUHOI_REDIS: redis://localhost:6379
BUHOI_MQ: amqp://guest:guest@localhost:5672
services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
rabbitmq:
image: rabbitmq
env:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
ports:
- 5672:5672
steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: latest

- name: Install Node.js dependencies
run: npm install --include=dev

- name: Install Mocha reporter
run: npm install mocha-ctrf-json-reporter

- name: Run tests
run: npx mocha -r should --reporter mocha-ctrf-json-reporter --require tests/mocha-hooks.js --recursive tests
continue-on-error: true

- name: Add annotations
run: npx github-actions-ctrf ctrf-report.json
working-directory: ctrf

- name: Create tests coverage report
run: npm run test-coverage
continue-on-error: true

- name: Send report to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: .nyc_output/coverage.lcov
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@
"devDependencies": {
"@eslint/compat": "1.1.1",
"@stylistic/eslint-plugin": "2.6.1",
"axios": "1.7.3",
"coveralls": "3.1.1",
"axios": "1.7.7",
"coveralls-next": "^4.2.1",
"eslint": "9.8.0",
"eslint-plugin-unused-imports": "4.0.1",
"husky": "9.1.4",
"lint-staged": "15.2.7",
"mocha": "10.7.0",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "17.0.0",
"should": "13.2.3",
"should-sinon": "0.0.6",
"sinon": "18.0.0",
"sinon": "19.0.2",
"webpack-dev-middleware": "7.3.0",
"webpack-hot-middleware": "2.26.1"
},
"scripts": {
"precommit": "lint-staged",
"prepush": "npm t",
"lint": "eslint .",
"test": "npm run lint && mocha -r should --recursive tests",
"cover": "npm run lint && nyc mocha -r should --recursive tests && nyc report --reporter=html && xdg-open coverage/index.html",
"travis-coveralls": "npm run lint && nyc mocha -r should --recursive tests && nyc report --reporter=text-lcov | coveralls",
"test": "mocha -r should --require tests/mocha-hooks.js --recursive tests",
"test-coverage": "nyc npm run test && nyc report --reporter=text-lcov > .nyc_output/coverage.lcov",
"release-patch": "npm t && npm version patch && npm publish && git push",
"release-minor": "npm t && npm version minor && npm publish && git push",
"release-major": "npm t && npm version major && npm publish && git push"
Expand Down
65 changes: 33 additions & 32 deletions tests/arg-parsing.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-env mocha */

const Promise = require('bluebird')
const request = Promise.promisify(require('request'))
const fs = require('fs')

const request = require('./request')
const todos = require('./app/features/todos')
const users = require('./app/features/users')

Expand All @@ -13,64 +10,68 @@ describe('buhoi arg parsing', function () {
})

it('should treat no content as empty arg array', async function () {
const { statusCode } = await request({
const { status } = await request({
url: 'https://localhost:3001/rpc/todos.publicProcedure',
method: 'POST',
headers: { 'content-type': 'application/json' },
strictSSL: false,
method: 'post',
headers: { 'Content-Type': 'application/json' },
timeout: 1000,
validateStatus: () => true,
})
todos.publicProcedureSpy.calledOnce.should.eql(true)
todos.publicProcedureSpy.lastCall.args.slice(0, -2).should.eql([])
statusCode.should.eql(200)
status.should.eql(200)
})

it('should treat no args in qs as empty arg array', async function () {
const { statusCode } = await request({
it('should treat no args in params as empty arg array', async function () {
const { status } = await request({
url: 'https://localhost:3001/rpc/todos.publicProcedure',
method: 'GET',
strictSSL: false,
method: 'get',
headers: { 'Content-Type': 'application/json' },
timeout: 1000,
validateStatus: () => true,
})
todos.publicProcedureSpy.calledOnce.should.eql(true)
todos.publicProcedureSpy.lastCall.args.slice(0, -2).should.eql([])
statusCode.should.eql(200)
status.should.eql(200)
})

it('should respond with 500 if args are invalid JSON', async function () {
const { statusCode } = await request({
const { status } = await request({
url: 'https://localhost:3001/rpc/todos.publicProcedure',
method: 'GET',
qs: { args: 'arg' },
strictSSL: false,
method: 'get',
headers: { 'Content-Type': 'application/json' },
params: { args: 'arg' },
timeout: 1000,
validateStatus: () => true,
})
statusCode.should.eql(500)
status.should.eql(500)
})

it('should respond with 500 if body does not contains array of args', async function () {
const { statusCode } = await request({
const { status } = await request({
url: 'https://localhost:3001/rpc/todos.publicProcedure',
method: 'POST',
json: 'dolphin',
strictSSL: false,
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: 'dolphin',
timeout: 1000,
validateStatus: () => true,
})
statusCode.should.eql(500)
status.should.eql(500)
})

it('should receive forms with files', async function () {
const { statusCode } = await request({
const form = new FormData()
form.append('user_id', 10)
form.append('avatar', new Blob(await fs.createReadStream(`${__dirname}/app/public/index.html`).toArray()))

const { status } = await request({
url: 'https://localhost:3001/rpc/users.uploadAvatar',
method: 'POST',
formData: {
user_id: 10,
avatar: fs.createReadStream(`${__dirname}/app/public/index.html`),
},
strictSSL: false,
method: 'post',
data: form,
timeout: 1000,
validateStatus: () => true,
})
statusCode.should.eql(200)
status.should.eql(200)
users.uploadAvatarSpy.calledOnce.should.eql(true)
const args = users.uploadAvatarSpy.lastCall.args
args[0].should.have.property('user_id')
Expand Down
23 changes: 14 additions & 9 deletions tests/mocha-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

const buhoi = require('../src')

before(() => buhoi.start(buhoi.config.simple({
featuresPath: `${__dirname}/app/features`,
publicPath: `${__dirname}/app/public`,
webpackConfigPath: `${__dirname}/app/pages/webpack.config.js`,
isAuthorized: (session, feature, _procedure) =>
feature !== 'secrets' || (session && session.startsWith('dodo')),
})))

after(() => buhoi.stop())
exports.mochaHooks = {
async beforeAll () {
await buhoi.start(buhoi.config.simple({
featuresPath: `${__dirname}/app/features`,
publicPath: `${__dirname}/app/public`,
webpackConfigPath: `${__dirname}/app/pages/webpack.config.js`,
isAuthorized: (session, feature, _procedure) =>
feature !== 'secrets' || (session && session.startsWith('dodo')),
}))
},
async afterAll () {
await buhoi.stop()
},
}
3 changes: 0 additions & 3 deletions tests/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const https = require('https')

module.exports = function (params) {
return axios({
headers: {
'Content-Type': 'application/json',
},
timeout: 1000,
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
validateStatus: status => status < 500,
Expand Down

0 comments on commit 688f3d8

Please sign in to comment.