Skip to content

Commit

Permalink
fix(core): configure jest
Browse files Browse the repository at this point in the history
Romakita committed Feb 19, 2022
1 parent f8957eb commit 81511d6
Showing 59 changed files with 586 additions and 582 deletions.
1 change: 1 addition & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
"packages/testing/**",
"packages/**/ExpressRouter.ts",
"packages/**/RouteService.ts",
"packages/core",
"packages/platform/platform-test-utils",
"packages/platform/platform-serverless",
"packages/platform/platform-serverless-http",
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -94,13 +94,14 @@
"@tsed/logger": ">=6.0.2",
"ajv": "8.9.0",
"axios": "0.21.1",
"barrelsby": "^2.3.2",
"change-case": "4.1.2",
"globby": "11.0.3",
"lerna": "4.0.0",
"microbundle": "0.13.0",
"rxjs": "^6.5.2",
"source-map-support": "0.5.19",
"uuid": "8.3.2",
"rxjs": "^6.5.2"
"uuid": "8.3.2"
},
"devDependencies": {
"@commitlint/cli": "^16.1.0",
14 changes: 14 additions & 0 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
...require("@tsed/jest-config")(__dirname, "core"),
coverageThreshold: {
global: {
statements: 97.95,
branches: 89.65,
functions: 96.04,
lines: 98.17
}
}
};
7 changes: 5 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"private": false,
"source": "./src/index.ts",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"typings": "./lib/types/index.d.ts",
"exports": {
"types": "./lib/types/index.d.ts",
@@ -13,9 +14,11 @@
"default": "./lib/esm/index.js"
},
"scripts": {
"build": "yarn run build:esm && yarn run build:cjs",
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\"",
"build:cjs": "tsc --build tsconfig.compile.json",
"build:esm": "tsc --build tsconfig.compile.esm.json"
"build:esm": "tsc --build tsconfig.compile.esm.json",
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
},
"dependencies": {
"reflect-metadata": "^0.1.13",
5 changes: 2 additions & 3 deletions packages/core/src/decorators/configurable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {expect} from "chai";
import {Configurable, descriptorOf, NotConfigurable} from "../../src";

class Test {
@@ -8,11 +7,11 @@ class Test {
describe("Configurable", () => {
it("should set attribut as configurable", () => {
Configurable()(Test, "test");
expect(descriptorOf(Test, "test").configurable).to.eq(true);
expect(descriptorOf(Test, "test").configurable).toBe(true);
});

it("should set attribut as not configurable", () => {
NotConfigurable()(Test, "test");
expect(descriptorOf(Test, "test").configurable).to.eq(false);
expect(descriptorOf(Test, "test").configurable).toBe(false);
});
});
7 changes: 1 addition & 6 deletions packages/core/src/decorators/configurable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* @module common/core
*/
import {descriptorOf} from "../utils";

/** */
import {descriptorOf} from "../utils/objects/descriptorOf";

export function Configurable(value: boolean = true): Function {
return (target: any, propertyKey: string) => {
17 changes: 11 additions & 6 deletions packages/core/src/decorators/deprecated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {expect} from "chai";
import {Deprecated} from "../../src";
import {Deprecated} from "./deprecated";
import {deprecate} from "util";

class Test {
test() {}
}
jest.mock("util");

describe("Deprecated", () => {
it("should wrap method as deprecated", () => {
expect(Deprecated("test")(Test, "test", {value: Test.prototype.test}).value).to.be.a("function");
class Test {
@Deprecated("test")
test() {}
}

new Test();

expect(deprecate).toHaveBeenCalledWith(expect.any(Function), "test");
});
});
2 changes: 1 addition & 1 deletion packages/core/src/decorators/deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Type} from "../domain/Type";
import {deprecate} from "util";
import {Type} from "../domain/Type";
/**
* The `@Deprecated()` decorators wraps the given method in such a way that it is marked as deprecated.
*
17 changes: 8 additions & 9 deletions packages/core/src/decorators/enumerable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {expect} from "chai";
import {Enumerable, getEnumerableKeys, NotEnumerable} from "../../src";

class Test1 {
@@ -46,16 +45,16 @@ class Test2 extends Parent1 {

describe("Enumerable", () => {
it("should have some keys with Test1", () => {
expect(getEnumerableKeys(new Test1())).to.deep.eq(["test", "name"]);
expect(Object.keys(new Test1())).to.deep.eq(["test"]);
expect(Object.getOwnPropertyNames(new Test1())).to.deep.eq(["test"]);
expect(Reflect.ownKeys(new Test2())).to.deep.eq(["prop", "test", "_privateTest"]);
expect(getEnumerableKeys(new Test1())).toEqual(["test", "name"]);
expect(Object.keys(new Test1())).toEqual(["test"]);
expect(Object.getOwnPropertyNames(new Test1())).toEqual(["test"]);
expect(Reflect.ownKeys(new Test2())).toEqual(["prop", "test", "_privateTest"]);
});

it("should have some keys with Test2", () => {
expect(getEnumerableKeys(new Test2())).to.deep.eq(["prop", "test", "first", "privateTest", "name", "parentProp"]);
expect(Object.keys(new Test2())).to.deep.eq(["prop", "test", "_privateTest"]);
expect(Object.getOwnPropertyNames(new Test2())).to.deep.eq(["prop", "test", "_privateTest"]);
expect(Reflect.ownKeys(new Test2())).to.deep.eq(["prop", "test", "_privateTest"]);
expect(getEnumerableKeys(new Test2())).toEqual(["prop", "test", "first", "privateTest", "name", "parentProp"]);
expect(Object.keys(new Test2())).toEqual(["prop", "test", "_privateTest"]);
expect(Object.getOwnPropertyNames(new Test2())).toEqual(["prop", "test", "_privateTest"]);
expect(Reflect.ownKeys(new Test2())).toEqual(["prop", "test", "_privateTest"]);
});
});
7 changes: 1 addition & 6 deletions packages/core/src/decorators/enumerable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* @module common/core
*/
import {descriptorOf} from "../utils";

/** */
import {descriptorOf} from "../utils/objects/descriptorOf";

export function Enumerable(value: boolean = true): Function {
return (target: any, propertyKey: string) => {
14 changes: 0 additions & 14 deletions packages/core/src/decorators/index.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/core/src/decorators/notConfigurable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/**
* @module common/core
*/
import {Configurable} from "./configurable";
/** */

export function NotConfigurable(): Function {
return Configurable(false);
}
5 changes: 1 addition & 4 deletions packages/core/src/decorators/notEnumerable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/**
* @module common/core
*/
import {Enumerable} from "./enumerable";
/** */

export function NotEnumerable(): Function {
return Enumerable(false);
}
5 changes: 1 addition & 4 deletions packages/core/src/decorators/readOnly.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/**
* @module common/core
*/
import {Writable} from "./writable";
/** */

export function Readonly(): Function {
return Writable(false);
}
5 changes: 2 additions & 3 deletions packages/core/src/decorators/writable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {expect} from "chai";
import {descriptorOf, Readonly, Writable} from "../../src";

class Test {}

describe("Writable", () => {
it("should set attribut as writable", () => {
Writable()(Test, "test");
expect(descriptorOf(Test, "test").writable).to.eq(true);
expect(descriptorOf(Test, "test").writable).toBe(true);
});
it("should set attribut as readonly", () => {
Readonly()(Test, "test");
expect(descriptorOf(Test, "test").writable).to.eq(false);
expect(descriptorOf(Test, "test").writable).toBe(false);
});
});
7 changes: 1 addition & 6 deletions packages/core/src/decorators/writable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* @module common/core
*/
import {descriptorOf} from "../utils";

/** */
import {descriptorOf} from "../utils/objects/descriptorOf";

export function Writable(value: boolean = true): Function {
return (target: any, propertyKey: string) => {
29 changes: 14 additions & 15 deletions packages/core/src/domain/AnyToPromise.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {catchAsyncError, isStream} from "@tsed/core";
import {expect} from "chai";
import {createReadStream} from "fs";
import {of} from "rxjs";
import {AnyToPromise, AnyToPromiseStatus} from "./AnyToPromise";
@@ -21,7 +20,7 @@ describe("AnyToPromise", () => {
return "test";
});

expect(result).to.deep.equal({state: "RESOLVED", data: "test", type: "DATA"});
expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
});

it("should handle async value", async () => {
@@ -31,7 +30,7 @@ describe("AnyToPromise", () => {
return "test";
});

expect(result).to.deep.equal({state: "RESOLVED", data: "test", type: "DATA"});
expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
});
it("should handle canceled async value", async () => {
const resolver = new AnyToPromise();
@@ -40,7 +39,7 @@ describe("AnyToPromise", () => {
return AnyToPromiseStatus.CANCELED;
});

expect(result).to.deep.equal({state: "CANCELED"});
expect(result).toEqual({state: "CANCELED"});
});
it("should handle response with data", async () => {
const resolver = new AnyToPromise();
@@ -56,7 +55,7 @@ describe("AnyToPromise", () => {
};
});

expect(result).to.deep.equal({
expect(result).toEqual({
state: "RESOLVED",
data: "data",
headers: {
@@ -73,7 +72,7 @@ describe("AnyToPromise", () => {
return undefined;
});

expect(result).to.deep.equal({state: "RESOLVED", data: undefined, type: "DATA"});
expect(result).toEqual({state: "RESOLVED", data: undefined, type: "DATA"});
});
it("should handle observable", async () => {
const resolver = new AnyToPromise();
@@ -82,7 +81,7 @@ describe("AnyToPromise", () => {
return of("test");
});

expect(result).to.deep.equal({state: "RESOLVED", data: "test", type: "DATA"});
expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
});
it("should handle buffer", async () => {
const resolver = new AnyToPromise();
@@ -91,8 +90,8 @@ describe("AnyToPromise", () => {
return Buffer.from("test");
});

expect(Buffer.isBuffer(result.data)).to.equal(true);
expect(result.type).to.equal("BUFFER");
expect(Buffer.isBuffer(result.data)).toBe(true);
expect(result.type).toBe("BUFFER");
});
it("should handle stream", async () => {
const resolver = new AnyToPromise();
@@ -101,8 +100,8 @@ describe("AnyToPromise", () => {
return createReadStream(__dirname + "/__mock__/response.txt");
});

expect(result.type).to.equal("STREAM");
expect(isStream(result.data)).to.equal(true);
expect(result.type).toBe("STREAM");
expect(isStream(result.data)).toBe(true);
});

it("should catch error", async () => {
@@ -112,7 +111,7 @@ describe("AnyToPromise", () => {
return "test";
});

expect(result).to.deep.equal({state: "RESOLVED", data: "test", type: "DATA"});
expect(result).toEqual({state: "RESOLVED", data: "test", type: "DATA"});
});

it("should handle async error", async () => {
@@ -124,7 +123,7 @@ describe("AnyToPromise", () => {
});
});

expect(error?.message).to.deep.equal("test");
expect(error?.message).toEqual("test");
});

it("should handle sync error", async () => {
@@ -136,7 +135,7 @@ describe("AnyToPromise", () => {
});
});

expect(error?.message).to.deep.equal("test");
expect(error?.message).toEqual("test");
});

it("should handle next callback with error", async () => {
@@ -149,6 +148,6 @@ describe("AnyToPromise", () => {
});
});

expect(error?.message).to.deep.equal("test");
expect(error?.message).toEqual("test");
});
});
Loading

0 comments on commit 81511d6

Please sign in to comment.