@akanjs/test 0.0.30 → 0.0.32
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 +49 -2
- package/src/jest.config.base.d.ts +2 -0
- package/src/jest.config.base.js +56 -0
- package/src/jest.config.base.ts +32 -0
- package/src/jest.globalSetup.d.ts +4 -0
- package/src/jest.globalSetup.js +38 -0
- package/src/jest.globalSetup.ts +26 -0
- package/src/jest.globalTeardown.d.ts +3 -0
- package/src/jest.globalTeardown.js +30 -0
- package/src/jest.globalTeardown.ts +12 -0
- package/src/jest.setupFilesAfterEnv.d.ts +1 -0
- package/src/jest.setupFilesAfterEnv.js +10 -0
- package/src/jest.setupFilesAfterEnv.ts +17 -0
- package/src/jest.testServer.d.ts +11 -0
- package/src/jest.testServer.js +139 -0
- package/src/jest.testServer.ts +104 -0
- package/src/playwright.config.base.d.ts +9 -0
- package/src/playwright.config.base.js +80 -0
- package/src/playwright.config.base.ts +71 -0
- package/src/playwright.pageAgent.d.ts +13 -0
- package/src/playwright.pageAgent.js +67 -0
- package/src/playwright.pageAgent.ts +42 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -11,13 +11,60 @@
|
|
|
11
11
|
"directory": "pkgs/@akanjs/base"
|
|
12
12
|
},
|
|
13
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",
|
|
14
28
|
"@urql/core": "^5.1.0",
|
|
29
|
+
"apple-signin": "^1.0.9",
|
|
30
|
+
"body-parser": "^1.20.3",
|
|
31
|
+
"bull": "^4.16.5",
|
|
15
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",
|
|
16
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",
|
|
17
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",
|
|
18
58
|
"pluralize": "^8.0.0",
|
|
59
|
+
"react": "^18.3.1",
|
|
60
|
+
"react-dom": "^18.3.1",
|
|
61
|
+
"redis": "^4.7.0",
|
|
19
62
|
"reflect-metadata": "^0.2.2",
|
|
20
|
-
"
|
|
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"
|
|
21
68
|
},
|
|
22
69
|
"main": "./index.js"
|
|
23
70
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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<{}, {}>;
|
|
@@ -0,0 +1,80 @@
|
|
|
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 playwright_config_base_exports = {};
|
|
19
|
+
__export(playwright_config_base_exports, {
|
|
20
|
+
withBase: () => withBase
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(playwright_config_base_exports);
|
|
23
|
+
var import_devkit = require("@nx/devkit");
|
|
24
|
+
var import_preset = require("@nx/playwright/preset");
|
|
25
|
+
var import_test = require("@playwright/test");
|
|
26
|
+
const baseURL = process.env.BASE_URL ?? "http://127.0.0.1:4200";
|
|
27
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT ?? "unknown";
|
|
28
|
+
const withBase = (filename, config = {}) => (0, import_test.defineConfig)({
|
|
29
|
+
...(0, import_preset.nxE2EPreset)(filename, { testDir: "./app" }),
|
|
30
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
31
|
+
use: {
|
|
32
|
+
baseURL,
|
|
33
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
34
|
+
trace: "on-first-retry"
|
|
35
|
+
},
|
|
36
|
+
/* Run your local dev server before starting the tests */
|
|
37
|
+
webServer: {
|
|
38
|
+
command: `nx serve ${projectName}`,
|
|
39
|
+
url: "http://127.0.0.1:4200",
|
|
40
|
+
reuseExistingServer: !process.env.CI,
|
|
41
|
+
cwd: import_devkit.workspaceRoot
|
|
42
|
+
},
|
|
43
|
+
projects: [
|
|
44
|
+
{
|
|
45
|
+
name: "chromium",
|
|
46
|
+
use: { ...import_test.devices["Desktop Chrome"] }
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "firefox",
|
|
50
|
+
use: { ...import_test.devices["Desktop Firefox"] }
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "webkit",
|
|
54
|
+
use: { ...import_test.devices["Desktop Safari"] }
|
|
55
|
+
}
|
|
56
|
+
// Uncomment for mobile browsers support
|
|
57
|
+
/* {
|
|
58
|
+
name: 'Mobile Chrome',
|
|
59
|
+
use: { ...devices['Pixel 5'] },
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'Mobile Safari',
|
|
63
|
+
use: { ...devices['iPhone 12'] },
|
|
64
|
+
}, */
|
|
65
|
+
// Uncomment for branded browsers
|
|
66
|
+
/* {
|
|
67
|
+
name: 'Microsoft Edge',
|
|
68
|
+
use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'Google Chrome',
|
|
72
|
+
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
73
|
+
} */
|
|
74
|
+
],
|
|
75
|
+
...config
|
|
76
|
+
});
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
withBase
|
|
80
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { workspaceRoot } from "@nx/devkit";
|
|
2
|
+
import { nxE2EPreset } from "@nx/playwright/preset";
|
|
3
|
+
import { defineConfig, devices, type PlaywrightTestConfig } from "@playwright/test";
|
|
4
|
+
|
|
5
|
+
// For CI, you may want to set BASE_URL to the deployed application.
|
|
6
|
+
const baseURL = process.env.BASE_URL ?? "http://127.0.0.1:4200";
|
|
7
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT ?? "unknown";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Read environment variables from file.
|
|
11
|
+
* https://github.com/motdotla/dotenv
|
|
12
|
+
*/
|
|
13
|
+
// require('dotenv').config();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* See https://playwright.dev/docs/test-configuration.
|
|
17
|
+
*/
|
|
18
|
+
export const withBase = (filename: string, config: PlaywrightTestConfig = {}) =>
|
|
19
|
+
defineConfig({
|
|
20
|
+
...nxE2EPreset(filename, { testDir: "./app" }),
|
|
21
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
22
|
+
use: {
|
|
23
|
+
baseURL,
|
|
24
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
25
|
+
trace: "on-first-retry",
|
|
26
|
+
},
|
|
27
|
+
/* Run your local dev server before starting the tests */
|
|
28
|
+
webServer: {
|
|
29
|
+
command: `nx serve ${projectName}`,
|
|
30
|
+
url: "http://127.0.0.1:4200",
|
|
31
|
+
reuseExistingServer: !process.env.CI,
|
|
32
|
+
cwd: workspaceRoot,
|
|
33
|
+
},
|
|
34
|
+
projects: [
|
|
35
|
+
{
|
|
36
|
+
name: "chromium",
|
|
37
|
+
use: { ...devices["Desktop Chrome"] },
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
name: "firefox",
|
|
42
|
+
use: { ...devices["Desktop Firefox"] },
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
{
|
|
46
|
+
name: "webkit",
|
|
47
|
+
use: { ...devices["Desktop Safari"] },
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// Uncomment for mobile browsers support
|
|
51
|
+
/* {
|
|
52
|
+
name: 'Mobile Chrome',
|
|
53
|
+
use: { ...devices['Pixel 5'] },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'Mobile Safari',
|
|
57
|
+
use: { ...devices['iPhone 12'] },
|
|
58
|
+
}, */
|
|
59
|
+
|
|
60
|
+
// Uncomment for branded browsers
|
|
61
|
+
/* {
|
|
62
|
+
name: 'Microsoft Edge',
|
|
63
|
+
use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'Google Chrome',
|
|
67
|
+
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
68
|
+
} */
|
|
69
|
+
],
|
|
70
|
+
...config,
|
|
71
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Page } from "@playwright/test";
|
|
2
|
+
import { test } from "@playwright/test";
|
|
3
|
+
export { expect } from "@playwright/test";
|
|
4
|
+
export { test };
|
|
5
|
+
export declare class PageAgent {
|
|
6
|
+
#private;
|
|
7
|
+
readonly page: Page;
|
|
8
|
+
constructor(page: Page);
|
|
9
|
+
goto(path: string): Promise<void>;
|
|
10
|
+
waitForPathChange(path?: string): Promise<unknown>;
|
|
11
|
+
wait(ms?: number): Promise<void>;
|
|
12
|
+
url(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 playwright_pageAgent_exports = {};
|
|
19
|
+
__export(playwright_pageAgent_exports, {
|
|
20
|
+
PageAgent: () => PageAgent,
|
|
21
|
+
expect: () => import_test3.expect,
|
|
22
|
+
test: () => import_test2.test
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(playwright_pageAgent_exports);
|
|
25
|
+
var import_test2 = require("@playwright/test");
|
|
26
|
+
var import_test3 = require("@playwright/test");
|
|
27
|
+
class PageAgent {
|
|
28
|
+
page;
|
|
29
|
+
#defaultWaitMs = 500;
|
|
30
|
+
#isInitialized = false;
|
|
31
|
+
constructor(page) {
|
|
32
|
+
this.page = page;
|
|
33
|
+
}
|
|
34
|
+
async goto(path) {
|
|
35
|
+
await Promise.all([this.page.goto(path), this.waitForPathChange(path)]);
|
|
36
|
+
if (!this.#isInitialized) {
|
|
37
|
+
this.#isInitialized = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async waitForPathChange(path) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const timeout = setTimeout(() => {
|
|
43
|
+
reject(new Error("Timeout waiting for pathChange message"));
|
|
44
|
+
}, 3e4);
|
|
45
|
+
this.page.on("console", (msg) => {
|
|
46
|
+
if (msg.type() === "log" && msg.text().startsWith(`%cpathChange-finished:${path ?? ""}`)) {
|
|
47
|
+
clearInterval(timeout);
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
resolve(true);
|
|
50
|
+
}, this.#defaultWaitMs);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async wait(ms = this.#defaultWaitMs) {
|
|
56
|
+
await this.page.waitForTimeout(ms);
|
|
57
|
+
}
|
|
58
|
+
url() {
|
|
59
|
+
return "/" + this.page.url().split("/").slice(4).join("/");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
PageAgent,
|
|
65
|
+
expect,
|
|
66
|
+
test
|
|
67
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Page } from "@playwright/test";
|
|
2
|
+
import { test } from "@playwright/test";
|
|
3
|
+
|
|
4
|
+
export { expect } from "@playwright/test";
|
|
5
|
+
export { test };
|
|
6
|
+
|
|
7
|
+
export class PageAgent {
|
|
8
|
+
readonly page: Page;
|
|
9
|
+
readonly #defaultWaitMs = 500;
|
|
10
|
+
#isInitialized = false;
|
|
11
|
+
constructor(page: Page) {
|
|
12
|
+
this.page = page;
|
|
13
|
+
}
|
|
14
|
+
async goto(path: string) {
|
|
15
|
+
await Promise.all([this.page.goto(path), this.waitForPathChange(path)]);
|
|
16
|
+
if (!this.#isInitialized) {
|
|
17
|
+
// await this.page.waitForEvent("websocket");
|
|
18
|
+
this.#isInitialized = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async waitForPathChange(path?: string) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const timeout = setTimeout(() => {
|
|
24
|
+
reject(new Error("Timeout waiting for pathChange message"));
|
|
25
|
+
}, 30000);
|
|
26
|
+
this.page.on("console", (msg) => {
|
|
27
|
+
if (msg.type() === "log" && msg.text().startsWith(`%cpathChange-finished:${path ?? ""}`)) {
|
|
28
|
+
clearInterval(timeout);
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
resolve(true);
|
|
31
|
+
}, this.#defaultWaitMs);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async wait(ms = this.#defaultWaitMs) {
|
|
37
|
+
await this.page.waitForTimeout(ms);
|
|
38
|
+
}
|
|
39
|
+
url() {
|
|
40
|
+
return "/" + this.page.url().split("/").slice(4).join("/");
|
|
41
|
+
}
|
|
42
|
+
}
|