Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind decorator add support ContainerHelper events #212

Merged
merged 4 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"scripts": {
"build": "rimraf dist/ && tsc --project ./tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"build:watch": "npm run build && (concurrently \"tsc --project ./tsconfig.build.json -w\" \"tsc-alias -p tsconfig.build.json -w\")",
"dev": "tsx ./src/index.ts",
"start": "node ./dist/index.js",
"start:build": "yarn build && node ./dist/index.js",
"dev": "tsx --env-file=.env ./src/index.ts",
"start": "node --env-file=.env ./dist/index.js",
"start:build": "yarn build && node --env-file=.env ./dist/index.js",
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json,.jsonc,.json5,.yml,.yaml,.xml,.txt,.svg,.properties,.gradle,.java,.cpp,.c,.cs,.html,.css,.groovy,.gitignore,.npmignore,.toml,.env,.example,.sample,.ini,.php,.bat,.powershell,.ps1,.sh,.bash,.eslintrc",
"lint:fix": "eslint --ext .js,.jsx,.ts,.tsx,.json,.jsonc,.json5,.yml,.yaml,.xml,.txt,.svg,.properties,.gradle,.java,.cpp,.c,.cs,.html,.css,.groovy,.gitignore,.npmignore,.toml,.env,.example,.sample,.ini,.php,.bat,.powershell,.ps1,.sh,.bash,.eslintrc --fix",
"prepare": "husky",
Expand Down Expand Up @@ -63,14 +63,14 @@
"@odg/eslint-config": "*",
"@odg/tsconfig": "*",
"@types/node": ">=20",
"@vitest/coverage-v8": "^1",
"concurrently": "^9.1.0",
"@vitest/coverage-istanbul": "^1",
"concurrently": "^9.1.2",
"husky": "^9.1.7",
"lint-staged": "^15.2.10",
"lint-staged": "^15.4.1",
"rimraf": "*",
"tsc-alias": "^1.8.10",
"tsx": "^4.19.1",
"typescript": "^5.7.2",
"tsx": "^4.19.2",
"typescript": "^5.7.3",
"vite-tsconfig-paths": "^4",
"vitest": "^1"
},
Expand All @@ -83,12 +83,11 @@
"@odg/json-log": "*",
"@odg/log": "*",
"@odg/message": "*",
"dotenv": "^16.4.5",
"inversify": "^6.1.4",
"inversify": "^6.2.1",
"inversify-binding-decorators": "^4.0.0",
"playwright": "^1.49.0",
"playwright-core": "^1.49.0",
"playwright": "^1.49.1",
"playwright-core": "^1.49.1",
"reflect-metadata": "^0.2.2",
"zod": "^3.23"
"zod": "^3.24"
}
}
4 changes: 3 additions & 1 deletion src/app/Listeners/SearchEventListener.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { ContainerHelper } from "@odg/chemical-x";
import { type EventListenerInterface } from "@odg/events";
import { LoggerInterface } from "@odg/log";
import { inject } from "inversify";
import { fluentProvide } from "inversify-binding-decorators";

import { type EventBrowserParameters, type EventTypes } from "#types/EventsInterface";
import { ContainerName, type EventName } from "@enums";
import { ContainerName, EventName } from "@enums";
import { PageOrHandlerFactoryType } from "@factory";
import { type SearchPage } from "@pages/Google/SearchPage";

@ContainerHelper.registerListener(EventName.SearchPageEvent, ContainerName.SearchEventListeners, {})
@(fluentProvide(ContainerName.SearchEventListeners).inSingletonScope().done())
export class SearchEventListener implements EventListenerInterface<EventTypes, EventName.SearchPageEvent> {

Expand Down
12 changes: 3 additions & 9 deletions src/app/Provider/EventServiceProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ContainerHelper } from "@odg/chemical-x";
import {
EventBusInterface,
EventServiceProvider as EventServiceProviderBase,
Expand All @@ -9,7 +10,7 @@ import {
import { fluentProvide } from "inversify-binding-decorators";

import { type EventTypes } from "#types/EventsInterface";
import { ContainerName, EventName } from "@enums";
import { ContainerName } from "@enums";

import Container from "../Container";

Expand Down Expand Up @@ -72,14 +73,7 @@ export class EventServiceProvider<Events extends EventTypes> extends EventServic
*/
private getListeners(): EventListener<EventTypes> {
return {
[EventName.SearchPageEvent]: [
{
listener: this.container.get(ContainerName.SearchEventListeners),
options: {
once: false,
},
},
],
...ContainerHelper.getEvents(this.container.container),
};
}

Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "reflect-metadata";
import "dotenv/config";

import { ContainerName } from "@enums";

Expand Down
12 changes: 12 additions & 0 deletions tests/vitest/Containers/ProcessKernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ describe("Test process kernel", async () => {
expect(mock).toHaveBeenCalled();
expect(mock.mock.calls[0][0]).toBe("Waiting for the crawler to kill the process");
});

test("KernelProcess called other message", async () => {
const logger = container.get(ContainerName.Logger);
const processKernel = container.get(ContainerName.ProcessKernel);
assert(logger);

const mock = vi.spyOn(logger, "debug");
expect(() => {
processKernel["messageShutdownListen"]("other");
}).not.toThrow();
expect(mock).not.toHaveBeenCalled();
});
});
14 changes: 9 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

const coverage100 = 100;

const vite = defineConfig({
test: {
globals: true,
coverage: {
enabled: true,
provider: "v8",
branches: 100,
functions: 100,
lines: 100,
statements: 100,
provider: "istanbul",
watermarks: {
branches: [ coverage100, coverage100 ],
functions: [ coverage100, coverage100 ],
lines: [ coverage100, coverage100 ],
statements: [ coverage100, coverage100 ],
},
exclude: [
"src/index.ts",
"src/index.js",
Expand Down
Loading
Loading