diff --git a/.github/workflows/checker.yaml b/.github/workflows/checker.yaml index 7c0ac81..444dca2 100644 --- a/.github/workflows/checker.yaml +++ b/.github/workflows/checker.yaml @@ -1,8 +1,9 @@ -name: checker +name: Testing CI on: workflow_dispatch: pull_request: + jobs: commitlint: runs-on: ubuntu-22.04 @@ -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 diff --git a/.gitignore b/.gitignore index 92b38f4..c1c0e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /dist /node_modules /build -/test + # Logs logs *.log diff --git a/package.json b/package.json index 87a9f5b..9c3eeb1 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/clap-peer.js b/test/clap-peer.js new file mode 100644 index 0000000..822e672 --- /dev/null +++ b/test/clap-peer.js @@ -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(); + }); +});