Skip to content

Commit

Permalink
chore(): improve docs, improve jest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
chyzwar committed Dec 10, 2023
1 parent 582d117 commit 5abe6c6
Show file tree
Hide file tree
Showing 32 changed files with 194 additions and 140 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -23,11 +23,12 @@ jobs:
- name: Build
run: yarn build

- name: Build
- name: Units tests
run: yarn test

- name: Integration tests
run: yarn int

- name: Eslint
run: yarn lint
env:
NODE_OPTIONS: --max_old_space_size=4096

61 changes: 52 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,75 @@
# Hyper Project

![Github Actions](https://github.com/chyzwar/hyper/workflows/Build/badge.svg)

Experimental web framework for node.js

## Project status

I work on this as hobby project. This is not production ready. If you are looking for web framework I recommend fastify.js or hapi.js

## Why

```js
import {Server, BodyParser, Router} from "@hyper/http-server";
- no external dependacies
- native ESM support
- support for async/await
- support for http2
- clean code and testable
- great performance
- first class typescript support

```ts
import {
Server,
BodyParser,
Router,
RequestLogger
} from "@hyper/http-server";

const server = new Server({port: 3000});

const bodyParser = new BodyParser();
const requestLogger = new RequestLogger();
const router = new Router();
server.addLayer(bodyParser);

router.post("/", (req, res) => {
router.get("/", (req, res) => {
res.json({
message: "Hello World",
body: req.body,
});
});

server.addLayer(bodyParser);
router.post("/echo", (req, res) => {
res.json({
body: req.body,
});
});
server.addLayer(requestLogger);
server.addRouter(router);

server
.listen(3000)
.then(() => {
console.log("Server is listening");
.listen()
.then((address) => {
logger.info(`Server started on ${address.address}:${address.port}`);
})
.catch((error) => {
console.log("Failed to start", error);
});
```

## What is implemented

- middleware system simmilar to express
- simple router
- body parser
- isomorthic json logger
- isomorthinc http client
- request logging middleware
- mock request and response

## What is missing

- compresssion
- cookie parser
- documentation
- request schema validation
- etag/freshness and caching support
2 changes: 1 addition & 1 deletion jest.int.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default {
verbose: false,
maxWorkers: 8,
projects: [
"<rootDir>/packages/*/integration/jest.config.js",
"<rootDir>/packages/*/integration/jest.config.ts",
],
};
3 changes: 3 additions & 0 deletions packages/event-emitter/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### @hyper/event-emitter

Simple event emitter.
8 changes: 0 additions & 8 deletions packages/generic-types/jest.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions packages/generic-types/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type {Config} from "jest";

const config: Config = {
displayName: "@hyper/generic-types",
testEnvironment: "jsdom",
rootDir: "src",
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
};

export default config;
2 changes: 1 addition & 1 deletion packages/http-client/Readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# TCP Socket
### @hyper/http-client
3 changes: 2 additions & 1 deletion packages/http-client/examples/browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@chyzwar/tsconfig/lib.json",
"compilerOptions": {
"rootDir": "src"
"rootDir": "src",
"outDir": "dist"
},
"include": [
"src/**/*.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/http-client/examples/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@hyper/http-client-node-example",
"version": "0.0.1",
"type": "module",
"description": "Http Client in node example",
"scripts": {
"start": "ts-node src/main.ts"
Expand Down
1 change: 0 additions & 1 deletion packages/http-client/examples/node/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {HttpClient} from "@hyper/http-client";
import {Logger} from "@hyper/logger";


const logger = new Logger();

const client = new HttpClient(
Expand Down
Empty file.
5 changes: 4 additions & 1 deletion packages/http-client/examples/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

{
"extends": "@chyzwar/tsconfig/api.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": [
"src/**/*.ts",
"src/**/*.json"
Expand Down
7 changes: 7 additions & 0 deletions packages/http-client/integration/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import type {Config} from "jest";
const config: Config = {
testRegex: "(/__tests__/.*|(\\.|/)(int|spec))\\.(ts?|tsx?)$",
transformIgnorePatterns: ["/node_modules/(?!@hyper).+\\.js$"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
};

export default config;
2 changes: 2 additions & 0 deletions packages/http-server/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### @hyper/http-server

1 change: 1 addition & 0 deletions packages/http-server/examples/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"devDependencies": {
"@chyzwar/eslint-config": "^0.2.14",
"eslint": "^8.55.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
Expand Down
37 changes: 0 additions & 37 deletions packages/http-server/readme.md

This file was deleted.

1 change: 1 addition & 0 deletions packages/http/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### @hyper/http
15 changes: 15 additions & 0 deletions packages/logger/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "http://json.schemastore.org/swcrc",
"isModule": true,
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"dynamicImport": false
}
},
"module": {
"type": "es6",
"resolveFully": true
}
}
11 changes: 0 additions & 11 deletions packages/logger/jest.config.js

This file was deleted.

23 changes: 23 additions & 0 deletions packages/logger/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type {Config} from "@jest/types";

/**
* Use jest with ts-jest to transform
*
* @see https://facebook.github.io/jest/docs/en/configuration.html
*/
const config: Config.InitialOptions = {
displayName: "@hyper/logger",
testEnvironment: "jsdom",
rootDir: "src",
setupFiles: ["../jest.setup.js"],
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
};

export default config;
4 changes: 2 additions & 2 deletions packages/logger/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {jest} from "@jest/globals";
/* eslint-disable @typescript-eslint/no-empty-function */
import {URL} from "url";

Object.defineProperty(global.window.navigator, "sendBeacon", {
value: jest.fn(),
value: () => {},
writable: true,
});

Expand Down
1 change: 1 addition & 0 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@chyzwar/eslint-config": "^0.2.14",
"@chyzwar/tsconfig": "^0.2.14",
"@jest/globals": "^29.7.0",
"eslint": "^8.53.0",
"jest": "^29.7.0",
"typescript": "^5.2.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/utility-types/Readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Type Generics
### @hyper/utility-types
8 changes: 0 additions & 8 deletions packages/utility-types/jest.config.js

This file was deleted.

23 changes: 23 additions & 0 deletions packages/utility-types/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type {Config} from "@jest/types";

/**
* Use jest with ts-jest to transform
*
* @see https://facebook.github.io/jest/docs/en/configuration.html
*/
const config: Config.InitialOptions = {
displayName: "@hyper/utility-types",
testEnvironment: "jsdom",
rootDir: "src",
testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
};

export default config;

2 changes: 1 addition & 1 deletion packages/utility-types/src/__tests__/JSONValue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type JSONValue from "../JSONValue";
import type JSONValue from "../JSONValue.js";
import {describe, it, expect} from "@jest/globals";

describe("JSONValue", () => {
Expand Down
Loading

0 comments on commit 5abe6c6

Please sign in to comment.