Skip to content

Commit

Permalink
v0.2.0 (#2)
Browse files Browse the repository at this point in the history
* v0.2.0

* updated GitHub action configs

* updated GitHub action job name
  • Loading branch information
Thesephi committed Mar 5, 2024
1 parent 3a592f5 commit cc6ba63
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pull Request
on:
pull_request:
branches:
- main

jobs:
integrity-checks:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Verify formatting
run: deno fmt --check

- name: Run linter
run: deno lint --ignore=\*\*\/\*_test.ts

- name: Run tests
run: deno test -A
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Verify formatting
run: deno fmt --check

- name: Run linter
run: deno lint --ignore=\*\*\/\*_test.ts

- name: Run tests
run: deno test -A

- name: Publish package
run: npx jsr publish
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## [0.1.2] - 2024-04-03
## [0.2.0] - 2024-03-05

### Changed

- upgraded dependency to `@oak/oak@14.2.0`

## [0.1.2] - 2024-03-04

### Added

Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# oak-routing-ctrl

routing-controllers -like library for `jsr:@oak/oak` (https://jsr.io/@oak/oak)
[![Built with the Deno Standard Library](https://raw.githubusercontent.com/denoland/deno_std/main/badge.svg)](https://jsr.io/@std)

routing-controllers -like library for the [Oak](https://jsr.io/@oak/oak)
framework (`jsr:@oak/oak`) 🚗 🐿️ 🦕

```ts
@Controller("/api/v1/pokemon")
class MyPokedex {
@Get("/:id")
viewEntry(ctx) {
if (ctx.params.id === "0025") return "Pikachu";
}
}
```

## Forewords

Expand All @@ -15,6 +28,15 @@ replacement for routing-controllers, as it attempts to conform to
yet. There's currently no plan to support TypeScript "experimental" decorators,
but if you feel strongly for it, please feel free to fork this repo!

## Installation

Prerequisite:
[Deno](https://docs.deno.com/runtime/manual/getting_started/installation)

```bash
deno add @dklab/oak-routing-ctrl
```

## Example Usage

```ts
Expand Down
4 changes: 2 additions & 2 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export {
Context,
RouteContext,
Router,
} from "jsr:@oak/oak@^14.1.1";
} from "jsr:@oak/oak@^14.2.0";

export type {
Next,
RouteParams,
RouterMiddleware,
State,
} from "jsr:@oak/oak@^14.1.1";
} from "jsr:@oak/oak@^14.2.0";
17 changes: 17 additions & 0 deletions dev_deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export { assert, assertEquals } from "jsr:@std/assert@^0.218.2";

export {
assertSpyCall,
assertSpyCalls,
spy,
stub,
} from "jsr:@std/testing@^0.218.2/mock";

export {
afterEach,
beforeEach,
describe,
it,
} from "jsr:@std/testing@^0.218.2/bdd";

export type { Spy, Stub } from "jsr:@std/testing@^0.218.2/mock";
5 changes: 3 additions & 2 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "@dklab/oak-routing-ctrl",
"version": "0.1.2",
"version": "0.2.0",
"exports": {
".": "./mod.ts"
}
},
"exclude": ["**/*_test.ts", "dev_deps.ts"]
}
30 changes: 30 additions & 0 deletions src/Put_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
assertEquals,
assertSpyCall,
assertSpyCalls,
spy,
stub,
} from "../dev_deps.ts";
import { debug } from "./utils/logger.ts";
import { register, store } from "./Store.ts";
import { Put } from "./Put.ts";

Deno.test("@Put decorator", () => {
// @TODO check why spies don't work
// const spyStoreRegister = spy(register);
// const spyLoggerDebug = spy(debug);

class _ {
@Put("/bar")
doSomething() {}
}

// assertSpyCalls(spyLoggerDebug, 1);
// assertSpyCalls(spyStoreRegister, 1);
// assertSpyCall(spyStoreRegister, 0, {
// args: ["put", "/bar", "doSomething"],
// returned: undefined,
// });

assertEquals(store.get("doSomething")?.get("put"), "/bar");
});
50 changes: 50 additions & 0 deletions src/utils/logger_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { debug } from "./logger.ts";
import {
afterEach,
assertSpyCall,
assertSpyCalls,
beforeEach,
stub,
} from "../../dev_deps.ts";
import type { Stub } from "../../dev_deps.ts";
import { describe, it } from "../../dev_deps.ts";

let stubConsoleDebug: Stub;

beforeEach(() => {
stubConsoleDebug = stub(console, "debug", () => {});
});

afterEach(() => {
stubConsoleDebug.restore();
});

describe("debug logger", () => {
it("behaves without DEBUG env var", () => {
const stubbedGetDebugEnv = stubGetEnv("DEBUG", undefined);
try {
debug("foo");
assertSpyCalls(stubConsoleDebug, 0);
} finally {
stubbedGetDebugEnv.restore();
}
});

it("behaves with DEBUG env var", () => {
const stubbedGetDebugEnv = stubGetEnv("DEBUG", "true");
try {
debug("bar");
assertSpyCall(stubConsoleDebug, 0, { args: ["bar"] });
} finally {
stubbedGetDebugEnv.restore();
}
});
});

function stubGetEnv(envName: string, stubValue: string | undefined): Stub {
return stub(
Deno.env,
"get",
(key) => key === envName ? stubValue : Deno.env.get(key),
);
}

0 comments on commit cc6ba63

Please sign in to comment.