Skip to content

Commit

Permalink
fix: types, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Nov 15, 2021
1 parent 3439249 commit bbf1785
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "TypeSafe unit style Application Framework written in TypeScript for Node.js.",
"main": "index.js",
"scripts": {
"test": "jest",
"test": "./run-tests $@",
"test:watch": "yarn test --watch",
"clean": "lerna run clean",
"lint": "eslint 'packages/*/{src,test}/**/*.ts'",
Expand Down
3 changes: 1 addition & 2 deletions packages/util/src/Async/AsyncCallback.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Promisify} from "..";
import {bind} from "../decorator";
import {Fn} from "../interfaces";
import {Promisify, Fn} from "../interfaces";
import {isUndefined} from "../is";

export class AsyncCallback<T> implements AsyncIterable<T> {
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/Logger/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as os from "os";
import {format} from "util";
import {assert} from "..";
import {assert} from "../assert";
import {fn} from "../function";
import {isDefined, isFunction, isInstanceOf, isNumber, isUndefined} from "../is";
import {Perf} from "../Perf";
Expand Down
10 changes: 6 additions & 4 deletions packages/util/src/Node/Env.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {assert} from "..";
import {Dict} from "./interfaces";
import {assert} from "../assert";

export type EnvKey = string | number | symbol;
export type EnvDefaultValue = string | undefined;

export class Env<T extends Record<string, EnvDefaultValue>> {
export class Env<T extends Dict<string>> {
readonly #store: Map<keyof T, EnvDefaultValue>;

constructor(env: Record<string, EnvDefaultValue>) {
constructor(env: Dict<string>) {
this.#store = new Map(Object.entries(env));
}

public static factory<T extends Record<string, EnvDefaultValue>>(env = process.env) {
public static factory<T extends Dict<string>>(env = process.env) {
return new this<T>(env);
}

Expand Down
1 change: 1 addition & 0 deletions packages/util/src/Node/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./Argv";
export * from "./Program";
export * from "./Env";
export * from "./interfaces";
1 change: 1 addition & 0 deletions packages/util/src/Node/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Dict<T> = NodeJS.Dict<T>;
2 changes: 1 addition & 1 deletion packages/util/src/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {debugLogFormat, Logger, SeverityLevel, StdOutTransport} from "..";
import {debugLogFormat, Logger, SeverityLevel, StdOutTransport} from "../Logger";

if (process.env.NODE_ENV === "test" && process.env.LOGGER_ENABLE === "Y") {
Logger.setSeverity(SeverityLevel.DEBUG);
Expand Down
9 changes: 7 additions & 2 deletions packages/util/test/src/node/Env.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {Env} from "../../../src";
import {Dict, Env} from "../../../src";

interface ITestEnv extends Dict<string> {
foo: string;
baz?: string;
}

describe("Env", () => {
test("get/ensure", () => {
const env = Env.factory<{foo: string; baz?: string}>({foo: "bar", baz: undefined});
const env = Env.factory<ITestEnv>({foo: "bar", baz: undefined});

expect(env.get("foo")).toBe("bar");
expect(env.get("baz")).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

docker run --rm --name redis-test -p 6379:6379 -d redis:alpine || exit 1

yarn test
jest $@

docker stop redis-test

0 comments on commit bbf1785

Please sign in to comment.