@akanjs/test 0.0.34 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/test",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,61 +10,14 @@
10
10
  "url": "https://github.com/akan-team/akanjs.git",
11
11
  "directory": "pkgs/@akanjs/base"
12
12
  },
13
- "dependencies": {
14
- "@apollo/server": "^4.11.2",
15
- "@inquirer/prompts": "^7.2.1",
16
- "@nestjs/apollo": "^12.2.2",
17
- "@nestjs/bull": "^10.2.3",
18
- "@nestjs/common": "^10.4.15",
19
- "@nestjs/core": "^10.4.15",
20
- "@nestjs/graphql": "^12.2.2",
21
- "@nestjs/mongoose": "^10.1.0",
22
- "@nestjs/passport": "^10.0.3",
23
- "@nestjs/platform-express": "^10.4.15",
24
- "@nestjs/platform-socket.io": "^10.4.15",
25
- "@nestjs/schedule": "^4.1.2",
26
- "@nestjs/websockets": "^10.4.15",
27
- "@socket.io/redis-adapter": "^8.3.0",
28
- "@urql/core": "^5.1.0",
29
- "apple-signin": "^1.0.9",
30
- "body-parser": "^1.20.3",
31
- "bull": "^4.16.5",
32
- "chance": "^1.1.12",
33
- "class-transformer": "^0.5.1",
34
- "class-validator": "^0.14.1",
35
- "cookie-parser": "^1.4.7",
36
- "dataloader": "^2.2.3",
37
- "dayjs": "^1.11.13",
38
- "dotenv": "^16.4.7",
39
- "express": "^4.21.2",
40
- "graphql": "^16.10.0",
41
- "graphql-type-json": "^0.3.2",
42
- "graphql-upload": "^12.0.0",
43
- "iap": "^1.1.1",
44
- "immer": "^10.1.1",
45
- "jsonwebtoken": "^9.0.2",
46
- "lodash": "^4.17.21",
47
- "meilisearch": "^0.47.0",
48
- "mongoose": "^8.9.3",
49
- "next": "^15.3.0",
50
- "passport": "^0.7.0",
51
- "passport-apple": "^2.0.2",
52
- "passport-facebook": "^3.0.0",
53
- "passport-github": "^1.1.0",
54
- "passport-google-oauth20": "^2.0.0",
55
- "passport-kakao": "^1.0.1",
56
- "passport-naver": "^1.0.6",
57
- "picocolors": "^1.1.1",
58
- "pluralize": "^8.0.0",
59
- "react": "^18.3.1",
60
- "react-dom": "^18.3.1",
61
- "redis": "^4.7.0",
62
- "reflect-metadata": "^0.2.2",
63
- "rxjs": "^7.8.1",
64
- "socket.io": "^4.8.1",
65
- "socket.io-client": "^4.8.1",
66
- "tunnel-ssh": "^5.2.0",
67
- "ua-parser-js": "^1.0.40"
13
+ "main": "./index.js",
14
+ "engines": {
15
+ "node": ">=22"
68
16
  },
69
- "main": "./index.js"
17
+ "dependencies": {
18
+ "chance": "^^1.1.12",
19
+ "dayjs": "^^1.11.13",
20
+ "pluralize": "^^8.0.0",
21
+ "reflect-metadata": "^^0.2.2"
22
+ }
70
23
  }
package/README.md DELETED
@@ -1,11 +0,0 @@
1
- # akan
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build akan` to build the library.
8
-
9
- ## Running unit tests
10
-
11
- Run `nx test akan` to execute the unit tests via [Jest](https://jestjs.io).
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src";
package/src/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { sampleOf } from "./sampleOf";
2
- export { sample } from "./sample";
package/src/index.js DELETED
@@ -1,30 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var src_exports = {};
19
- __export(src_exports, {
20
- sample: () => import_sample.sample,
21
- sampleOf: () => import_sampleOf.sampleOf
22
- });
23
- module.exports = __toCommonJS(src_exports);
24
- var import_sampleOf = require("./sampleOf");
25
- var import_sample = require("./sample");
26
- // Annotate the CommonJS export names for ESM import in node:
27
- 0 && (module.exports = {
28
- sample,
29
- sampleOf
30
- });
@@ -1,2 +0,0 @@
1
- import type { Config } from "@jest/types";
2
- export declare const withBase: (name: string) => Config.InitialOptions;
@@ -1,56 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var jest_config_base_exports = {};
19
- __export(jest_config_base_exports, {
20
- withBase: () => withBase
21
- });
22
- module.exports = __toCommonJS(jest_config_base_exports);
23
- var import_dotenv = require("dotenv");
24
- const withBase = (name) => {
25
- (0, import_dotenv.config)();
26
- process.env.NEXT_PUBLIC_ENV = "testing";
27
- process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
28
- process.env.NEXT_PUBLIC_APP_NAME = name;
29
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
30
- const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
31
- return {
32
- displayName: name,
33
- resolver: "@nx/jest/plugins/resolver",
34
- globalSetup: `${akanjsPrefix}@akanjs/test/src/jest.globalSetup.ts`,
35
- setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/test/src/jest.setupFilesAfterEnv.ts`],
36
- globalTeardown: `${akanjsPrefix}@akanjs/test/src/jest.globalTeardown.ts`,
37
- testMatch: ["**/?(*.)+(test).ts?(x)"],
38
- testPathIgnorePatterns: ["/node_modules/", "/app/"],
39
- maxWorkers: 1,
40
- transform: {
41
- "signal\\.(test)\\.ts$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
42
- "^.+\\.(ts|js|html)$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }]
43
- },
44
- moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
45
- coverageDirectory: `../../coverage/libs/${name}`,
46
- coverageReporters: ["html"],
47
- testEnvironment: "node",
48
- testEnvironmentOptions: {
49
- customExportConditions: ["node", "require", "default"]
50
- }
51
- };
52
- };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- withBase
56
- });
@@ -1,32 +0,0 @@
1
- import type { Config } from "@jest/types";
2
- import { config } from "dotenv";
3
-
4
- export const withBase = (name: string): Config.InitialOptions => {
5
- config();
6
- process.env.NEXT_PUBLIC_ENV = "testing";
7
- process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
8
- process.env.NEXT_PUBLIC_APP_NAME = name;
9
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
10
- const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
11
- return {
12
- displayName: name,
13
- resolver: "@nx/jest/plugins/resolver",
14
- globalSetup: `${akanjsPrefix}@akanjs/test/src/jest.globalSetup.ts`,
15
- setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/test/src/jest.setupFilesAfterEnv.ts`],
16
- globalTeardown: `${akanjsPrefix}@akanjs/test/src/jest.globalTeardown.ts`,
17
- testMatch: ["**/?(*.)+(test).ts?(x)"],
18
- testPathIgnorePatterns: ["/node_modules/", "/app/"],
19
- maxWorkers: 1,
20
- transform: {
21
- "signal\\.(test)\\.ts$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
22
- "^.+\\.(ts|js|html)$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
23
- },
24
- moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
25
- coverageDirectory: `../../coverage/libs/${name}`,
26
- coverageReporters: ["html"],
27
- testEnvironment: "node",
28
- testEnvironmentOptions: {
29
- customExportConditions: ["node", "require", "default"],
30
- },
31
- };
32
- };
@@ -1,4 +0,0 @@
1
- import "tsconfig-paths/register";
2
- import type { Config } from "@jest/types";
3
- declare const setup: (globalConfig: Config.InitialOptions, projectConfig: any) => Promise<void>;
4
- export default setup;
@@ -1,38 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var jest_globalSetup_exports = {};
19
- __export(jest_globalSetup_exports, {
20
- default: () => jest_globalSetup_default
21
- });
22
- module.exports = __toCommonJS(jest_globalSetup_exports);
23
- var import_register = require("tsconfig-paths/register");
24
- var import_jest = require("./jest.testServer");
25
- const setup = async (globalConfig, projectConfig) => {
26
- const { env } = require(`${globalConfig.rootDir}/env/env.server.testing`);
27
- const { fetch, registerModules } = require(`${globalConfig.rootDir}/server`);
28
- const maxWorkers = globalConfig.maxWorkers;
29
- if (!maxWorkers)
30
- throw new Error("maxWorkers is not defined");
31
- const testServers = new Array(maxWorkers).fill(0).map((_, idx) => new import_jest.TestServer(registerModules, env, idx + 1));
32
- await Promise.all(testServers.map((server) => server.init()));
33
- global.__TEST_SERVERS__ = testServers;
34
- global.fetch = fetch;
35
- global.env = env;
36
- global.registerModules = registerModules;
37
- };
38
- var jest_globalSetup_default = setup;
@@ -1,26 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-require-imports */
2
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
-
4
- import "tsconfig-paths/register";
5
-
6
- import type { BackendEnv } from "@akanjs/base";
7
- import type { Config } from "@jest/types";
8
-
9
- import { TestServer } from "./jest.testServer";
10
-
11
- const setup = async (globalConfig: Config.InitialOptions, projectConfig) => {
12
- const { env } = require(`${globalConfig.rootDir}/env/env.server.testing`);
13
- const { fetch, registerModules } = require(`${globalConfig.rootDir}/server`);
14
- const maxWorkers = globalConfig.maxWorkers;
15
- if (!maxWorkers) throw new Error("maxWorkers is not defined");
16
- const testServers = new Array(maxWorkers)
17
- .fill(0)
18
- .map((_, idx) => new TestServer(registerModules as (options: any) => any[], env as BackendEnv, idx + 1));
19
- await Promise.all(testServers.map((server) => server.init()));
20
- global.__TEST_SERVERS__ = testServers;
21
- global.fetch = fetch;
22
- global.env = env;
23
- global.registerModules = registerModules;
24
- };
25
-
26
- export default setup;
@@ -1,3 +0,0 @@
1
- import "tsconfig-paths/register";
2
- declare const teardown: (globalConfig: any, projectConfig: any) => Promise<void>;
3
- export default teardown;
@@ -1,30 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var jest_globalTeardown_exports = {};
19
- __export(jest_globalTeardown_exports, {
20
- default: () => jest_globalTeardown_default
21
- });
22
- module.exports = __toCommonJS(jest_globalTeardown_exports);
23
- var import_register = require("tsconfig-paths/register");
24
- const teardown = async (globalConfig, projectConfig) => {
25
- const testServers = global.__TEST_SERVERS__;
26
- if (!testServers)
27
- throw new Error("Test servers are not defined");
28
- await Promise.all(testServers.map((server) => server.terminate()));
29
- };
30
- var jest_globalTeardown_default = teardown;
@@ -1,12 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
- import "tsconfig-paths/register";
3
-
4
- import { TestServer } from "./jest.testServer";
5
-
6
- const teardown = async (globalConfig, projectConfig) => {
7
- const testServers: TestServer[] | undefined = global.__TEST_SERVERS__;
8
- if (!testServers) throw new Error("Test servers are not defined");
9
- await Promise.all(testServers.map((server) => server.terminate()));
10
- };
11
-
12
- export default teardown;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- var import_jest = require("./jest.testServer");
2
- const { env, fetch } = global;
3
- jest.setTimeout(3e4);
4
- global.beforeAll(async () => {
5
- import_jest.TestServer.initClient(env);
6
- await fetch.cleanup();
7
- });
8
- global.afterAll(async () => {
9
- await fetch.client.terminate();
10
- });
@@ -1,17 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
- /* eslint-disable @typescript-eslint/no-unsafe-call */
3
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
4
- import type { BackendEnv } from "@akanjs/base";
5
-
6
- import { TestServer } from "./jest.testServer";
7
-
8
- const { env, fetch } = global as any;
9
- jest.setTimeout(30000);
10
- global.beforeAll(async () => {
11
- TestServer.initClient(env as BackendEnv);
12
- await fetch.cleanup();
13
- });
14
-
15
- global.afterAll(async () => {
16
- await fetch.client.terminate();
17
- });
@@ -1,11 +0,0 @@
1
- import { type BackendEnv } from "@akanjs/base";
2
- export declare class TestServer {
3
- #private;
4
- workerId: number;
5
- static initClient(env: BackendEnv, workerId?: number): void;
6
- constructor(registerModules: (options: any) => any[], env: BackendEnv, workerId?: number);
7
- init(): Promise<void>;
8
- startMongo(): Promise<string>;
9
- cleanup(): Promise<void>;
10
- terminate(): Promise<void>;
11
- }
@@ -1,139 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var jest_testServer_exports = {};
29
- __export(jest_testServer_exports, {
30
- TestServer: () => TestServer
31
- });
32
- module.exports = __toCommonJS(jest_testServer_exports);
33
- var import_common = require("@akanjs/common");
34
- var import_server = require("@akanjs/server");
35
- var import_signal = require("@akanjs/signal");
36
- var import_mongodb_memory_server = require("mongodb-memory-server");
37
- var import_mongoose = __toESM(require("mongoose"));
38
- var import_redis_memory_server = require("redis-memory-server");
39
- const MAX_RETRY = 5;
40
- const TEST_LISTEN_PORT_BASE = 38080;
41
- const TEST_MONGODB_PORT_BASE = 38081;
42
- const TEST_REDIS_PORT_BASE = 38082;
43
- const MIN_ACTIVATION_TIME = 0;
44
- const MAX_ACTIVATION_TIME = 3e4;
45
- class TestServer {
46
- #logger = new import_common.Logger("TestServer");
47
- #mongod;
48
- #redis;
49
- #registerModules;
50
- #env;
51
- workerId;
52
- #startAt = Date.now();
53
- #app;
54
- #portOffset = 0;
55
- static initClient(env, workerId = parseInt(process.env.JEST_WORKER_ID ?? "0")) {
56
- if (workerId === 0)
57
- throw new Error("TestClient should not be used in main thread");
58
- const portOffset = workerId * 1e3 + env.appCode * 10;
59
- const port = TEST_LISTEN_PORT_BASE + portOffset;
60
- const endpoint = `http://localhost:${port}/backend/graphql`;
61
- import_signal.client.init({ uri: endpoint });
62
- }
63
- constructor(registerModules, env, workerId) {
64
- this.workerId = workerId ?? parseInt(process.env.JEST_WORKER_ID ?? "0");
65
- if (this.workerId === 0)
66
- throw new Error("TestServer should not be used in main thread");
67
- this.#portOffset = this.workerId * 1e3 + env.appCode * 10;
68
- this.#mongod = new import_mongodb_memory_server.MongoMemoryServer({ instance: { port: TEST_MONGODB_PORT_BASE + this.#portOffset } });
69
- this.#redis = new import_redis_memory_server.RedisMemoryServer({ instance: { port: TEST_REDIS_PORT_BASE + this.#portOffset } });
70
- this.#env = { ...env };
71
- this.#registerModules = registerModules;
72
- }
73
- async init() {
74
- for (let i = 0; i < MAX_RETRY; i++) {
75
- try {
76
- const watchdog = setTimeout(() => {
77
- throw new Error("TestServer Init Timeout");
78
- }, MAX_ACTIVATION_TIME);
79
- await this.#init();
80
- clearTimeout(watchdog);
81
- return;
82
- } catch (e) {
83
- this.#logger.error(e);
84
- await this.terminate();
85
- }
86
- }
87
- }
88
- async #init() {
89
- const now = Date.now();
90
- this.#logger.log(`Test System #${this.workerId} Initializing...`);
91
- const port = TEST_LISTEN_PORT_BASE + this.#portOffset;
92
- const [mongoUri, redisHost, redisPort] = await Promise.all([
93
- this.startMongo(),
94
- this.#redis.getHost(),
95
- this.#redis.getPort()
96
- ]);
97
- this.#env.port = port;
98
- this.#env.mongoUri = mongoUri;
99
- this.#env.redisUri = `redis://${redisHost}:${redisPort}`;
100
- this.#env.meiliUri = "http://localhost:7700/search";
101
- this.#env.onCleanup = async () => {
102
- await this.cleanup();
103
- };
104
- this.#app = await (0, import_server.createNestApp)({ registerModules: this.#registerModules, env: this.#env });
105
- this.#logger.log(`Test System #${this.workerId} Initialized, Mongo: ${mongoUri}, Redis: ${redisHost}:${redisPort}`);
106
- this.#startAt = Date.now();
107
- this.#logger.log(`Test System #${this.workerId} Activation Time: ${this.#startAt - now}ms`);
108
- }
109
- async startMongo() {
110
- await this.#mongod.start();
111
- return this.#mongod.getUri();
112
- }
113
- async cleanup() {
114
- const now = Date.now();
115
- this.#logger.log("Mongo Memory Database Cleaning up...");
116
- if (this.#mongod.state === "running") {
117
- await this.#mongod.stop();
118
- await this.#mongod.start(true);
119
- }
120
- this.#logger.log(`Mongo Memory Database Cleaned up in ${Date.now() - now}ms`);
121
- }
122
- async terminate() {
123
- const now = Date.now();
124
- const elapsed = now - this.#startAt;
125
- await (0, import_common.sleep)(50);
126
- import_signal.client.io?.socket.close();
127
- await this.#app.close();
128
- if (elapsed < MIN_ACTIVATION_TIME) {
129
- this.#logger.log(`waiting for ${MIN_ACTIVATION_TIME - elapsed}`);
130
- await (0, import_common.sleep)(MIN_ACTIVATION_TIME - elapsed);
131
- }
132
- await Promise.all([import_mongoose.default.disconnect(), this.#mongod.stop(), this.#redis.stop()]);
133
- this.#logger.log(`System Terminated in ${Date.now() - now}ms`);
134
- }
135
- }
136
- // Annotate the CommonJS export names for ESM import in node:
137
- 0 && (module.exports = {
138
- TestServer
139
- });
@@ -1,104 +0,0 @@
1
- import { type BackendEnv } from "@akanjs/base";
2
- import { Logger, sleep } from "@akanjs/common";
3
- import { type BackendApp, createNestApp } from "@akanjs/server";
4
- import { client } from "@akanjs/signal";
5
- import { MongoMemoryServer } from "mongodb-memory-server";
6
- import mongoose from "mongoose";
7
- import { RedisMemoryServer } from "redis-memory-server";
8
-
9
- const MAX_RETRY = 5;
10
- const TEST_LISTEN_PORT_BASE = 38080;
11
- const TEST_MONGODB_PORT_BASE = 38081;
12
- const TEST_REDIS_PORT_BASE = 38082;
13
- const MIN_ACTIVATION_TIME = 0;
14
- const MAX_ACTIVATION_TIME = 30000;
15
-
16
- export class TestServer {
17
- readonly #logger = new Logger("TestServer");
18
- readonly #mongod: MongoMemoryServer;
19
- readonly #redis: RedisMemoryServer;
20
- readonly #registerModules: (options: any) => any[];
21
- readonly #env: BackendEnv;
22
- workerId: number;
23
- #startAt = Date.now();
24
- #app: BackendApp;
25
- #portOffset = 0;
26
- static initClient(env: BackendEnv, workerId = parseInt(process.env.JEST_WORKER_ID ?? "0")) {
27
- if (workerId === 0) throw new Error("TestClient should not be used in main thread");
28
- const portOffset = workerId * 1000 + env.appCode * 10;
29
- const port = TEST_LISTEN_PORT_BASE + portOffset;
30
- const endpoint = `http://localhost:${port}/backend/graphql`;
31
- client.init({ uri: endpoint });
32
- }
33
- constructor(registerModules: (options: any) => any[], env: BackendEnv, workerId?: number) {
34
- this.workerId = workerId ?? parseInt(process.env.JEST_WORKER_ID ?? "0");
35
- if (this.workerId === 0) throw new Error("TestServer should not be used in main thread");
36
- this.#portOffset = this.workerId * 1000 + env.appCode * 10;
37
- this.#mongod = new MongoMemoryServer({ instance: { port: TEST_MONGODB_PORT_BASE + this.#portOffset } });
38
- this.#redis = new RedisMemoryServer({ instance: { port: TEST_REDIS_PORT_BASE + this.#portOffset } });
39
- this.#env = { ...env };
40
- this.#registerModules = registerModules;
41
- }
42
- async init() {
43
- for (let i = 0; i < MAX_RETRY; i++) {
44
- try {
45
- const watchdog = setTimeout(() => {
46
- throw new Error("TestServer Init Timeout");
47
- }, MAX_ACTIVATION_TIME);
48
- await this.#init();
49
- clearTimeout(watchdog);
50
- return;
51
- } catch (e) {
52
- this.#logger.error(e as string);
53
- await this.terminate();
54
- }
55
- }
56
- }
57
- async #init() {
58
- const now = Date.now();
59
- this.#logger.log(`Test System #${this.workerId} Initializing...`);
60
- const port = TEST_LISTEN_PORT_BASE + this.#portOffset;
61
- const [mongoUri, redisHost, redisPort] = await Promise.all([
62
- this.startMongo(),
63
- this.#redis.getHost(),
64
- this.#redis.getPort(),
65
- ]);
66
- this.#env.port = port;
67
- this.#env.mongoUri = mongoUri;
68
- this.#env.redisUri = `redis://${redisHost}:${redisPort}`;
69
- this.#env.meiliUri = "http://localhost:7700/search";
70
- this.#env.onCleanup = async () => {
71
- await this.cleanup();
72
- };
73
- this.#app = await createNestApp({ registerModules: this.#registerModules, env: this.#env });
74
- this.#logger.log(`Test System #${this.workerId} Initialized, Mongo: ${mongoUri}, Redis: ${redisHost}:${redisPort}`);
75
- this.#startAt = Date.now();
76
- this.#logger.log(`Test System #${this.workerId} Activation Time: ${this.#startAt - now}ms`);
77
- }
78
- async startMongo() {
79
- await this.#mongod.start();
80
- return this.#mongod.getUri();
81
- }
82
- async cleanup() {
83
- const now = Date.now();
84
- this.#logger.log("Mongo Memory Database Cleaning up...");
85
- if (this.#mongod.state === "running") {
86
- await this.#mongod.stop();
87
- await this.#mongod.start(true);
88
- }
89
- this.#logger.log(`Mongo Memory Database Cleaned up in ${Date.now() - now}ms`);
90
- }
91
- async terminate() {
92
- const now = Date.now();
93
- const elapsed = now - this.#startAt;
94
- await sleep(50); // cooldown
95
- client.io?.socket.close();
96
- await this.#app.close();
97
- if (elapsed < MIN_ACTIVATION_TIME) {
98
- this.#logger.log(`waiting for ${MIN_ACTIVATION_TIME - elapsed}`);
99
- await sleep(MIN_ACTIVATION_TIME - elapsed);
100
- }
101
- await Promise.all([mongoose.disconnect(), this.#mongod.stop(), this.#redis.stop()]);
102
- this.#logger.log(`System Terminated in ${Date.now() - now}ms`);
103
- }
104
- }
@@ -1,9 +0,0 @@
1
- import { type PlaywrightTestConfig } from "@playwright/test";
2
- /**
3
- * Read environment variables from file.
4
- * https://github.com/motdotla/dotenv
5
- */
6
- /**
7
- * See https://playwright.dev/docs/test-configuration.
8
- */
9
- export declare const withBase: (filename: string, config?: PlaywrightTestConfig) => PlaywrightTestConfig<{}, {}>;