Skip to content

Commit

Permalink
feat: update CI test
Browse files Browse the repository at this point in the history
  • Loading branch information
luoingly committed Feb 21, 2025
1 parent 0408d0e commit b06c4e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,65 @@ name: Node.js CI
on:
push:
branches: [master]

# Allows you to run this workflow manually from the Actions tab
pull_request:
branches:
- master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
node-version: [16.x, 18.x, 20.x]
redis-version: [6]
mongodb-version: ['5.0']

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}

- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: ${{ matrix.mongodb-version }}

- uses: pnpm/[email protected]
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false

- name: Install dependencies
run: pnpm install
- run: pnpm test && pnpm coverage

- name: Run tests
run: pnpm test
env:
CI: true

- name: Run coverage and upload
if: matrix.node-version == '18.x'
run: |
pnpm coverage
env:
CI: true

- name: Upload coverage to Codecov
if: matrix.node-version == '18.x'
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"deploy:init": "cross-env NODE_ENV=production node manage.js",
"deploy:start": "npx pm2 start pm2.config.json",
"pretest": "cross-env NODE_ENV=test node test/pretest.js",
"test": "cross-env NODE_ENV=test node test/pretest.js && nyc ava && node test/posttest.js",
"test": "cross-env-shell NODE_ENV=test \"node test/pretest.js && nyc ava && node test/posttest.js\"",
"report": "nyc report --reporter=html",
"posttest": "cross-env NODE_ENV=test node test/posttest.js",
"lint": "eslint .",
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/group/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test.serial('Update Group 2', async (t) => {
const user = await request
.get('/api/user/admin')

t.true(user.body.user.gid.includes(2))
t.true(user.body.user.groups.some(group => group.gid === 2))
})

test.serial('Update Group 2 -- update members', async (t) => {
Expand All @@ -71,12 +71,12 @@ test.serial('Update Group 2 -- update members', async (t) => {
let r = await request
.get('/api/user/admin')

t.false(r.body.user.gid.includes(2))
t.false(r.body.user.groups.some(group => group.gid === 2))

r = await request
.get(`/api/user/${user.uid}`)

t.true(r.body.user.gid.includes(2))
t.true(r.body.user.groups.some(group => group.gid === 2))
})

test.serial('Delete Group 2', async (t) => {
Expand All @@ -92,7 +92,7 @@ test.serial('Delete Group 2', async (t) => {
const user = await request
.get('/api/user/admin')

t.false(user.body.user.gid.includes(2))
t.false(user.body.user.groups.some(group => group.gid === 2))
})

test('The length of group title should be greater than 3', async (t) => {
Expand Down
1 change: 0 additions & 1 deletion test/controllers/user/visitor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ test('User list', async (t) => {
t.truthy(Array.isArray(res.body.list))

t.truthy(res.body.list[0].uid)
t.truthy(res.body.list[0].nick)
})

test('Failed to update any user', async (t) => {
Expand Down

0 comments on commit b06c4e0

Please sign in to comment.