Skip to content

Commit

Permalink
add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
YieldRay committed Dec 25, 2023
1 parent 572b106 commit 10df0a7
Show file tree
Hide file tree
Showing 16 changed files with 619 additions and 87 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ci

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
deno:
- v1.x
- canary
os:
- ubuntu-22.04
- windows-2022
- macOS-12

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
submodules: true

- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Run tests canary
run: deno task test

- name: Generate lcov
run: deno task cov:gen

- name: Upload coverage
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
name: ${{ matrix.os }}-${{ matrix.deno }}
files: cov.lcov

lint:
runs-on: ubuntu-22.04
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
submodules: false
persist-credentials: false

- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: canary

- name: Format
run: deno fmt --check

- name: Lint
run: deno task lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
docs/
coverage/
cov.lcov
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![deno.land/x](https://shield.deno.dev/x/json_rpc_ts)](https://deno.land/x/json_rpc_ts)

A strictly typed json-rpc(2.0) implemention, zero dependency, minimal abstraction, with simple api
A strictly typed json-rpc(2.0) implementation, zero dependency, minimal abstraction, with simple api

> Specification <https://www.jsonrpc.org/specification>
Expand All @@ -14,19 +14,29 @@ const methodSet = {
minus: ([a, b]: [number, number]) => a - b,
}

// initialize all methods with the constructor
const server = new JSONRPCServer(methodSet)

// or add methods manually
const server = new JSONRPCServer<typeof methodSet>()
server.setMethod('upper', methodSet.upper)
server.setMethod('lower', methodSet.lower)
server.setMethod('plus', methodSet.plus)
server.setMethod('minus', methodSet.minus)

// (optional) provide a generic parameter to enable ts check
const client = new JSONRPCClient<typeof methodSet>((json) =>
server.process(json)
)

// request, Notification and batch are always async
assertEquals(await client.request('upper', 'hello'), 'HELLO')

assertEquals(
await client.batch(
client.createRequest('upper', 'nihao'),
// notifaction does not have response, even when response errors
client.createNotifaction('upper'),
// Notification does not have response, even when response errors
client.createNotification('upper'),
client.createRequest('upper', 'shijie'),
client.createRequest('plus', [1, 1]),
),
Expand Down Expand Up @@ -85,3 +95,13 @@ const httpServer = Deno.serve(
},
)
```

# build for JavaScript

To use this library without typescript, you have to build it to javascript.

```sh
git clone https://github.com/YieldRay/json-rpc-ts.git
cd json-rpc-ts
esbuild --bundle src/index.ts --outdir=dist --format=esm
```
29 changes: 25 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
{
"compilerOptions": {
"strict": true,
"useUnknownInCatchVariables": true,
"noImplicitOverride": true
},
"imports": {
"std/": "https://deno.land/std@0.209.0/"
},
"tasks": {
"docs": "deno doc --html --name=json-rpc-ts --output=./docs/ ./src/index.ts"
"lint": "deno lint",
"fmt": "deno fmt",
"docs": "deno doc --html --name=json-rpc-ts --output=./docs/ ./mod.ts",
"test": "deno test --parallel --coverage --trace-ops",
"cov:gen": "deno coverage coverage --lcov --output=cov.lcov",
"cov:view": "deno coverage --html coverage",
"cov:clean": "rm -rf ./coverage/ cov.lcov"
},
"fmt": {
"lineWidth": 80,
"semiColons": false,
"indentWidth": 4,
"singleQuote": true,
"proseWrap": "preserve",
"include": ["*"],
"exclude": []
}
"include": [
"src",
".github",
"deno.json",
"README.md",
"mod.ts"
]
},
"exclude": [
".git",
"docs",
"coverage"
]
}
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./src/index.ts"
export * from './src/index.ts'

0 comments on commit 10df0a7

Please sign in to comment.