Skip to content

Commit f7f054a

Browse files
amir78729mimshins
andauthored
refactor: improve encapsulation (#31)
* refactor to improve encapsulation * improve context type * test: add FixedQueue tests * test: add 100% coverage to devtool tests * test: add 100% coverage to client socket manager utils * test: increase ClientSocketManager coverage * test: increase SocketClientProvider coverage * test: increase SocketClientProvider coverage * test(core): update tests for improving test coverage --------- Co-authored-by: mimshins <mostafa.sh.coderino@gmail.com>
1 parent 4a97376 commit f7f054a

44 files changed

Lines changed: 4691 additions & 5858 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/fair-showers-slide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@tapsioss/react-client-socket-manager": patch
3+
"@tapsioss/client-socket-manager": patch
4+
---
5+
6+
Increase test coverage.
7+

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.changeset/**/*.md
2+
!.changeset/**/README.md
3+
**/CHANGELOG.md
4+
**/dist
5+
**/node_modules
6+
pnpm-lock.*
7+
LICENSE

eslint.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import { config, configs as tsLintConfigs } from "typescript-eslint";
1111
export default config(
1212
jsLint.configs.recommended,
1313
...tsLintConfigs.recommendedTypeChecked,
14-
/* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */
14+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1515
importPlugin.flatConfigs.recommended,
1616
importPlugin.flatConfigs.typescript,
17-
/* eslint-enable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */
1817
prettierRecommendedConfig,
1918
{
2019
files: ["*.ts", "*.tsx"],

package.json

Lines changed: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,41 @@
1010
"changesets:apply": "changeset version",
1111
"changesets:status": "changeset status --since=main",
1212
"release": "pnpm build && changeset publish --tag latest",
13-
"build": "wireit",
14-
"test": "vitest",
13+
"test": "pnpm -r --parallel run test",
14+
"build": "pnpm -r run build",
15+
"format:check": "wireit",
16+
"format:write": "wireit",
1517
"lint": "wireit",
16-
"dev": "pnpm --filter @repo/playground run dev",
17-
"build:core": "wireit",
18-
"build:react": "wireit"
18+
"dev": "pnpm --filter @repo/playground run dev"
1919
},
2020
"wireit": {
21-
"build": {
22-
"dependencies": [
23-
"build:core",
24-
"build:react"
25-
]
21+
"format:check": {
22+
"command": "prettier . --check --cache",
23+
"files": [
24+
"./.prettierrc",
25+
"./.prettierignore",
26+
"**/*.{js,jsx,ts,tsx,md,json,css}",
27+
"!**/dist/**/*",
28+
"!pnpm-lock.yaml"
29+
],
30+
"output": []
31+
},
32+
"format:write": {
33+
"command": "prettier . --write --cache",
34+
"files": [
35+
"./.prettierrc",
36+
"./.prettierignore",
37+
"**/*.{js,jsx,ts,tsx,md,json,css}",
38+
"!**/dist/**/*",
39+
"!pnpm-lock.yaml"
40+
],
41+
"output": []
2642
},
2743
"lint": {
2844
"dependencies": [
2945
"lint:ts",
30-
"lint:ecma"
46+
"lint:ecma",
47+
"format:check"
3148
]
3249
},
3350
"lint:ts": {
@@ -47,77 +64,50 @@
4764
"./eslint.config.js"
4865
],
4966
"output": []
50-
},
51-
"build:react": {
52-
"command": "pnpm --filter @tapsioss/react-client-socket-manager run build",
53-
"files": [
54-
"./packages/react/tsconfig.json",
55-
"./packages/react/tsconfig.*.json",
56-
"./packages/react/src/**/*",
57-
"!./packages/react/src/**/*.test.{ts,tsx}"
58-
],
59-
"output": [
60-
"./packages/react/dist/**/*",
61-
"./packages/react/dist/**/*.tsbuildinfo"
62-
],
63-
"dependencies": [
64-
"build:core"
65-
]
66-
},
67-
"build:core": {
68-
"command": "pnpm --filter @tapsioss/client-socket-manager run build",
69-
"files": [
70-
"./packages/core/tsconfig.json",
71-
"./packages/core/tsconfig.*.json",
72-
"./packages/core/src/**/*",
73-
"!./packages/react/src/**/*.test.{ts,tsx}"
74-
],
75-
"output": [
76-
"./packages/core/dist/**/*",
77-
"./packages/core/dist/**/*.tsbuildinfo"
78-
]
7967
}
8068
},
8169
"devDependencies": {
8270
"@changesets/changelog-github": "^0.5.1",
83-
"@changesets/cli": "^2.29.4",
84-
"@eslint/js": "^9.28.0",
85-
"@lit/react": "^1.0.7",
86-
"@testing-library/dom": "^10.4.0",
87-
"@testing-library/jest-dom": "^6.6.3",
71+
"@changesets/cli": "^2.29.5",
72+
"@eslint/js": "^9.33.0",
73+
"@lit/react": "^1.0.8",
74+
"@testing-library/dom": "^10.4.1",
75+
"@testing-library/jest-dom": "^6.6.4",
8876
"@testing-library/react": "^16.3.0",
8977
"@testing-library/user-event": "^14.6.1",
9078
"@types/eslint__js": "^8.42.3",
9179
"@types/express": "^5.0.3",
92-
"@types/node": "^20.19.0",
93-
"@types/react": "^19.1.6",
94-
"@types/react-dom": "^19.1.6",
95-
"@vitejs/plugin-react": "^4.5.1",
80+
"@types/node": "^20.19.10",
81+
"@types/react": "^19.1.9",
82+
"@types/react-dom": "^19.1.7",
83+
"@vitejs/plugin-react": "^4.7.0",
84+
"@vitest/coverage-v8": "^3.2.4",
9685
"@vitest/eslint-plugin": "1.1.32-beta.3",
97-
"eslint": "^9.28.0",
98-
"eslint-config-prettier": "^9.1.0",
86+
"eslint": "^9.33.0",
87+
"eslint-config-prettier": "^9.1.2",
9988
"eslint-import-resolver-typescript": "^3.10.1",
10089
"eslint-plugin-eslint-comments": "^3.2.0",
101-
"eslint-plugin-import": "^2.31.0",
102-
"eslint-plugin-prettier": "^5.4.1",
90+
"eslint-plugin-import": "^2.32.0",
91+
"eslint-plugin-prettier": "^5.5.4",
10392
"eslint-plugin-react": "^7.37.5",
10493
"eslint-plugin-react-hooks": "^5.2.0",
10594
"eslint-plugin-react-refresh": "^0.4.20",
10695
"express": "^4.21.2",
10796
"jsdom": "^26.1.0",
10897
"npm-run-all": "^4.1.5",
109-
"prettier": "^3.5.3",
110-
"prettier-plugin-organize-imports": "^4.1.0",
111-
"react": "^19.1.0",
112-
"react-dom": "^19.1.0",
98+
"prettier": "^3.6.2",
99+
"prettier-plugin-organize-imports": "^4.2.0",
100+
"react": "^19.1.1",
101+
"react-dom": "^19.1.1",
113102
"shx": "^0.3.4",
114103
"socket.io": "^4.8.1",
115104
"socket.io-client": "^4.8.1",
116-
"tsx": "^4.19.4",
117-
"typescript": "^5.8.3",
118-
"typescript-eslint": "^8.33.1",
105+
"tsup": "^8.5.0",
106+
"tsx": "^4.20.3",
107+
"typescript": "^5.9.2",
108+
"typescript-eslint": "^8.39.0",
119109
"vite-tsconfig-paths": "^5.1.4",
120-
"vitest": "^3.2.2",
110+
"vitest": "^3.2.4",
121111
"wireit": "^0.14.12"
122112
}
123113
}

packages/core/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ Show devtool in the browser programmatically.
221221
##### Parameters
222222

223223
- `options`: Optional parameters.
224-
- `zIndex`: Z-index of the devtool, overrides the previous z-index of the devtool.
224+
- `zIndex`: Z-index of the devtool, overrides the previous z-index of the
225+
devtool.
225226

226227
#### `hideDevtool`
227228

packages/core/package.json

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
"version": "0.6.0",
44
"type": "module",
55
"packageManager": "pnpm@9.15.0",
6-
"main": "./dist/cjs/index.js",
7-
"module": "./dist/esm/index.js",
8-
"types": "./dist/cjs/index.d.ts",
6+
"main": "./dist/index.cjs",
7+
"module": "./dist/index.js",
8+
"types": "./dist/index.d.ts",
99
"files": [
1010
"./dist",
11-
"./README.md",
12-
"./LICENSE"
11+
"README.md",
12+
"LICENSE"
1313
],
1414
"exports": {
1515
".": {
16-
"require": "./dist/cjs/index.js",
17-
"import": "./dist/esm/index.js",
18-
"types": "./dist/cjs/index.d.ts"
16+
"types": "./dist/index.d.ts",
17+
"import": "./dist/index.js",
18+
"require": "./dist/index.cjs"
1919
}
2020
},
2121
"keywords": [
@@ -33,12 +33,27 @@
3333
},
3434
"scripts": {
3535
"clear": "shx rm -rf dist",
36-
"build:cjs": "tsc --project ./tsconfig.cjs.json",
37-
"build:esm": "tsc --project ./tsconfig.esm.json",
36+
"test": "vitest run",
37+
"test:dev": "vitest",
3838
"prebuild": "pnpm run clear",
39-
"build": "run-p build:*",
39+
"build": "wireit",
4040
"release": "pnpm publish . --tag latest --access public --no-git-checks"
4141
},
42+
"wireit": {
43+
"build": {
44+
"command": "tsup",
45+
"files": [
46+
"./tsconfig.json",
47+
"./tsup.config.ts",
48+
"./src/**/*",
49+
"!./src/**/*.test.{ts,tsx}"
50+
],
51+
"output": [
52+
"./dist/**/*",
53+
"./dist/**/*.tsbuildinfo"
54+
]
55+
}
56+
},
4257
"devDependencies": {
4358
"@repo/test-helpers": "workspace:*"
4459
},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+
import { ClientSocketManager } from "./index.ts";
3+
4+
vi.mock("socket.io-client", () => ({
5+
io: () => {
6+
throw new Error("Connection failed");
7+
},
8+
}));
9+
10+
describe("ClientSocketManager: constructor error handling", () => {
11+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
12+
13+
beforeEach(() => {
14+
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
15+
});
16+
17+
afterEach(() => {
18+
consoleErrorSpy.mockRestore();
19+
});
20+
21+
it("should handle constructor error and log to console", () => {
22+
const socketManager = new ClientSocketManager("http://localhost:3000", {});
23+
24+
expect(consoleErrorSpy).toHaveBeenCalledWith(
25+
"Failed to initialize socket connection",
26+
expect.objectContaining({
27+
uri: "http://localhost:3000",
28+
path: "/socket.io",
29+
err: expect.any(Error) as unknown,
30+
}),
31+
);
32+
33+
expect(socketManager).toBeDefined();
34+
});
35+
});

0 commit comments

Comments
 (0)