Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DIY0R committed Dec 13, 2024
1 parent e9ecf84 commit 7d65925
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/checker.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: checker
name: Testing CI

on:
workflow_dispatch:
pull_request:

jobs:
commitlint:
runs-on: ubuntu-22.04
Expand All @@ -23,3 +24,44 @@ jobs:
- name: Validate PR commits with commitlint
if: github.event_name == 'pull_request'
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose

lint-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node:
- 20
- 21
- 22
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install

- name: Run Prettier
run: npm run prettier

- name: Run Lint
run: npm run lint

- name: Run Test
run: npm run test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/dist
/node_modules
/build
/test

# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"prettier:fix": "prettier lib/**/**.js -w",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test":"node --test ./test/clap-peer.js",
"prepare": "husky",
"release": "release-it"
},
Expand Down
21 changes: 21 additions & 0 deletions test/clap-peer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const assert = require('assert');
const { describe, test, after } = require('node:test');
const { ClapPeer, EVENTS } = require('..');

describe('Clap-Peer', () => {
test('two neighbors', async () => {
const message = { hello: 'hello' };
const node_1 = await ClapPeer(0, 'A');
const node_2 = await ClapPeer(0, 'B');
await node_2.connect({ host: '127.0.0.1', port: node_1.port });
node_2.publish(node_1.nodeId, message);
const messageDm = await new Promise(res => {
node_1.on(EVENTS.DM, res);
});
assert.deepEqual(messageDm.message, message);
});

after(() => {
process.exit();
});
});

0 comments on commit 7d65925

Please sign in to comment.