Skip to content

Commit e9d734c

Browse files
committed
feat: replace mocha by native node test runner
1 parent 47ebf38 commit e9d734c

11 files changed

+3316
-4400
lines changed

.mocharc.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default [
55
...labegStyle,
66
{
77
rules: {
8-
// Ругается на reflect-metadata, удалить при переходе не нативные декораторы
8+
// Drop usage reflect-metadata, use self store for metadata
99
"@typescript-eslint/no-unsafe-type-assertion": "off"
1010
}
1111
}

package-lock.json

Lines changed: 3288 additions & 4373 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"scripts": {
2424
"lint": "eslint --fix ./src/ ./tests/",
25-
"test": "mocha",
25+
"test": "node --import ./ts-loader.js --test --test-reporter=spec --test-reporter-destination=stdout \"tests/**/*.spec.ts\"",
26+
"coverage": "node --import ./ts-loader.js --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info \"tests/**/*.spec.ts\"",
2627
"build": "tsc --project tsconfig.build.json && node ./dist/index.js",
2728
"prepublishOnly": "npm run lint && npm run build && npm run test",
2829
"release": "cliff-jumper --name 'ts-serializable' --package-path '.' --no-skip-changelog --no-skip-tag",
@@ -36,15 +37,12 @@
3637
"@commitlint/config-conventional": "^19.6.0",
3738
"@favware/cliff-jumper": "^5.0.0",
3839
"@labeg/code-style": "^5.5.0",
40+
"@swc-node/register": "^1.10.9",
3941
"@types/chai": "^5.0.1",
40-
"@types/mocha": "^10.0.10",
4142
"chai": "^5.1.2",
4243
"husky": "^9.1.7",
4344
"lint-staged": "^15.3.0",
44-
"mocha": "^11.0.1",
4545
"reflect-metadata": "^0.2.2",
46-
"ts-node": "^10.9.2",
47-
"tsx": "^4.19.2",
4846
"typescript": "^5.7.2"
4947
},
5048
"keywords": [

tests/base-functions.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
/* eslint-disable max-lines-per-function */
33
import("reflect-metadata"); // Polyfill
44
import {assert} from "chai";
5+
import {describe, it} from "node:test";
56

67
import type {User as IUser, Friend as IFriend} from "./models/User";
78

89
describe("Base functions", () => {
910
it("user from method fromJSON must be instance of User", async () => {
1011
const {User} = await import("./models/User");
11-
const json = await import("./jsons/json-generator.json", {assert: {type: "json"}});
12+
const json = await import("./jsons/json-generator.json", {with: {type: "json"}});
13+
1214
const [object] = Reflect.get(json, "default") as typeof json;
1315

1416
const user = new User().fromJSON(object);
@@ -42,7 +44,7 @@ describe("Base functions", () => {
4244

4345
it("user from static method fromJSON must be instance of User", async () => {
4446
const {User} = await import("./models/User");
45-
const json = await import("./jsons/json-generator.json", {assert: {type: "json"}});
47+
const json = await import("./jsons/json-generator.json", {with: {type: "json"}});
4648
const [object] = Reflect.get(json, "default") as typeof json;
4749

4850
const user: IUser = User.fromJSON(object);
@@ -76,7 +78,7 @@ describe("Base functions", () => {
7678

7779
it("user from method fromString must be instance of User", async () => {
7880
const {User} = await import("./models/User");
79-
const json = await import("./jsons/json-generator.json", {assert: {type: "json"}});
81+
const json = await import("./jsons/json-generator.json", {with: {type: "json"}});
8082
const [object] = Reflect.get(json, "default") as typeof json;
8183

8284
const user = new User().fromString(JSON.stringify(object));
@@ -110,7 +112,7 @@ describe("Base functions", () => {
110112

111113
it("user from static method fromString must be instance of User", async () => {
112114
const {User} = await import("./models/User");
113-
const json = await import("./jsons/json-generator.json", {assert: {type: "json"}});
115+
const json = await import("./jsons/json-generator.json", {with: {type: "json"}});
114116
const [object] = Reflect.get(json, "default") as typeof json;
115117

116118
const user: IUser = User.fromString(JSON.stringify(object));

tests/decorators.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import("reflect-metadata"); // Polyfill
44
import {assert} from "chai";
5-
5+
import {describe, it} from "node:test";
66
import type {User as IUser} from "./models/User";
77
import type {FriendExt} from "./models/UserExt";
88

99
describe("Decorators", () => {
1010
it("user property marked as jsonIgnore must by dropped", async () => {
1111
const {User} = await import("./models/User");
12-
const json: Record<string, unknown>[] = await import("./jsons/json-generator.json", {assert: {type: "json"}});
12+
const json: Record<string, unknown>[] = await import("./jsons/json-generator.json", {with: {type: "json"}});
1313

1414
const user = new User().fromJSON(json[0]);
1515
user.isExpanded = true;
@@ -20,7 +20,7 @@ describe("Decorators", () => {
2020

2121
it("class can be extended by decorator jsonObject", async () => {
2222
const {UserExt} = await import("./models/UserExt");
23-
const json = await import("./jsons/json-generator.json", {assert: {type: "json"}});
23+
const json = await import("./jsons/json-generator.json", {with: {type: "json"}});
2424
const [object] = Reflect.get(json, "default") as typeof json;
2525

2626
const user = new UserExt().fromJSON(object);

tests/deep-copy.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import("reflect-metadata"); // Polyfill
44
import {assert} from "chai";
5+
import {describe, it} from "node:test";
56

67
describe("Bonus features", () => {
78
it("serializable must support deep copy", async () => {
89
const {User} = await import("./models/User");
9-
const json: Record<string, unknown>[] = await import("./jsons/json-generator.json", {assert: {type: "json"}});
10+
const json: Record<string, unknown>[] = await import("./jsons/json-generator.json", {with: {type: "json"}});
1011

1112
const user1 = new User().fromJSON(json[0]);
1213
const user2 = new User().fromJSON(user1);

tests/generated.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {assert} from "chai";
22
import {TestClass as TestClass1} from "./models/generated/generated1.js";
33
import {TestClass as TestClass2} from "./models/generated/generated2.js";
44
import {TestClass as TestClass3} from "./models/generated/generated3.js";
5+
import {describe, it} from "node:test";
56

67
// Think about guessing complex union types in the future.
78
describe.skip("Nested classes", () => {

tests/naming-strategy.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import("reflect-metadata"); // Polyfill
44
import {assert} from "chai";
55
import type {FriendSnake} from "./models/UserSnake";
66
import {SnakeCaseNamingStrategy} from "../src";
7+
import {describe, it} from "node:test";
78

89
describe("Naming strategies", () => {
910
it("deserialize must support snack case naming by fromJson parameters", async () => {
1011
const {UserSnake} = await import("./models/UserSnake");
11-
const json = await import("./jsons/json-generator-snake.json", {assert: {type: "json"}});
12+
const json = await import("./jsons/json-generator-snake.json", {with: {type: "json"}});
1213
const [object] = Reflect.get(json, "default") as typeof json;
1314

1415
const user = new UserSnake().fromJSON(
@@ -45,7 +46,7 @@ describe("Naming strategies", () => {
4546

4647
it("deserialize must support snack case naming by jsonObject decorator", async () => {
4748
const {UserSnakeObject} = await import("./models/UserSnake");
48-
const json = await import("./jsons/json-generator-snake.json", {assert: {type: "json"}});
49+
const json = await import("./jsons/json-generator-snake.json", {with: {type: "json"}});
4950
const [object] = Reflect.get(json, "default") as typeof json;
5051

5152
const user = new UserSnakeObject().fromJSON(object);
@@ -79,7 +80,7 @@ describe("Naming strategies", () => {
7980

8081
it("serializer must support snack case naming by jsonObject decorator", async () => {
8182
const {UserSnakeObject} = await import("./models/UserSnake");
82-
const json = await import("./jsons/json-generator-snake.json", {assert: {type: "json"}});
83+
const json = await import("./jsons/json-generator-snake.json", {with: {type: "json"}});
8384
const [object] = Reflect.get(json, "default") as typeof json;
8485

8586
const user = new UserSnakeObject().fromJSON(object);
@@ -117,7 +118,7 @@ describe("Naming strategies", () => {
117118

118119
it("method fromJSON must support snack case naming by jsonName decorator", async () => {
119120
const {UserNaming} = await import("./models/UserName");
120-
const json = await import("./jsons/user-naming.json", {assert: {type: "json"}});
121+
const json = await import("./jsons/user-naming.json", {with: {type: "json"}});
121122
const pjson = Reflect.get(json, "default") as typeof json;
122123

123124
const user = new UserNaming().fromJSON(pjson);
@@ -130,7 +131,7 @@ describe("Naming strategies", () => {
130131

131132
it("serializable must support deep copy with naming strategy", async () => {
132133
const {UserSnakeObject} = await import("./models/UserSnake");
133-
const json = await import("./jsons/json-generator-snake.json", {assert: {type: "json"}});
134+
const json = await import("./jsons/json-generator-snake.json", {with: {type: "json"}});
134135
const [object] = Reflect.get(json, "default") as typeof json;
135136

136137
const user1 = new UserSnakeObject().fromJSON(object);

tests/readme-samples.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import("reflect-metadata"); // Polyfill
33
import {assert} from "chai";
44
import {Serializable, SnakeCaseNamingStrategy, jsonObject, jsonProperty, jsonName} from "../src";
5+
import {describe, it} from "node:test";
56

67
describe("Readme samples", () => {
78
it("naming strategies sample", () => {

0 commit comments

Comments
 (0)