@cotestdev/ai-runner-fake 0.0.3 → 0.0.5
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/dist/runner.d.ts +3 -3
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +46 -10
- package/dist/runner.js.map +1 -1
- package/package.json +1 -1
- package/src/runner.ts +17 -14
package/dist/runner.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BrowserContext, Page } from '@playwright/test';
|
|
2
1
|
export declare class Runner {
|
|
3
2
|
private abortController;
|
|
4
3
|
private variables;
|
|
@@ -8,7 +7,7 @@ export declare class Runner {
|
|
|
8
7
|
private constructor();
|
|
9
8
|
static NewInstance(projectId: string, testCaseId: string, canHeal?: boolean): Runner;
|
|
10
9
|
stop(): void;
|
|
11
|
-
init(page:
|
|
10
|
+
init(page: any, context: any, data?: Record<string, any>): Promise<void>;
|
|
12
11
|
runStep(description: string, fn: () => Promise<void>): Promise<void>;
|
|
13
12
|
set(key: string, value: any): void;
|
|
14
13
|
get(key: string): any;
|
|
@@ -18,6 +17,7 @@ export declare class Runner {
|
|
|
18
17
|
keys(): string[];
|
|
19
18
|
getAll(): Record<string, unknown>;
|
|
20
19
|
private loadTestScript;
|
|
21
|
-
|
|
20
|
+
runScript(testId: string, script: string): Promise<Map<string, unknown>>;
|
|
21
|
+
reuseTest(useTestCaseId: string, description?: string): Promise<Map<string, unknown>>;
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAWA,qBAAa,MAAM;IACjB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS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|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.Runner = void 0;
|
|
4
37
|
const path_1 = require("path");
|
|
5
38
|
const os_1 = require("os");
|
|
6
39
|
const fs_1 = require("fs");
|
|
7
|
-
const test_1 = require("@playwright/test");
|
|
8
40
|
class Runner {
|
|
9
41
|
constructor(projectId, testCaseId) {
|
|
10
42
|
this.variables = new Map();
|
|
@@ -59,21 +91,18 @@ class Runner {
|
|
|
59
91
|
const scriptPath = (0, path_1.join)((0, os_1.homedir)(), '.test_agent', 'projects', this.projectId, 'script', `${testCaseId}.ts`);
|
|
60
92
|
return (0, fs_1.readFileSync)(scriptPath, 'utf-8');
|
|
61
93
|
}
|
|
62
|
-
async
|
|
63
|
-
const
|
|
64
|
-
if (!scriptContent) {
|
|
65
|
-
throw new Error(`Reusable test script not found: ${useTestCaseId}`);
|
|
66
|
-
}
|
|
67
|
-
const reuseRunner = Runner.NewInstance(this.projectId, useTestCaseId);
|
|
94
|
+
async runScript(testId, script) {
|
|
95
|
+
const reuseRunner = Runner.NewInstance(this.projectId, testId);
|
|
68
96
|
await reuseRunner.init(this.state.page, this.state.context);
|
|
69
|
-
console.log(`Starting to execute reusable test case: ${
|
|
97
|
+
console.log(`Starting to execute reusable test case: ${testId}`);
|
|
70
98
|
try {
|
|
71
99
|
const executeScript = new Function('runner', 'page', 'context', 'expect', `
|
|
72
100
|
return (async () => {
|
|
73
|
-
${
|
|
101
|
+
${script}
|
|
74
102
|
})();
|
|
75
103
|
`);
|
|
76
|
-
|
|
104
|
+
const { expect } = await Promise.resolve().then(() => __importStar(require('@playwright/test')));
|
|
105
|
+
await executeScript(reuseRunner, this.state.page, this.state.context, expect);
|
|
77
106
|
console.log(`Reusable test case executed successfully`);
|
|
78
107
|
return reuseRunner.state?.variables || new Map();
|
|
79
108
|
}
|
|
@@ -81,6 +110,13 @@ class Runner {
|
|
|
81
110
|
throw new Error(`reuseTest execution failed, error: ${error instanceof Error ? error.message : String(error)}`);
|
|
82
111
|
}
|
|
83
112
|
}
|
|
113
|
+
async reuseTest(useTestCaseId, description) {
|
|
114
|
+
const scriptContent = this.loadTestScript(useTestCaseId);
|
|
115
|
+
if (!scriptContent) {
|
|
116
|
+
throw new Error(`Reusable test script not found: ${useTestCaseId}`);
|
|
117
|
+
}
|
|
118
|
+
return this.runScript(useTestCaseId, scriptContent);
|
|
119
|
+
}
|
|
84
120
|
}
|
|
85
121
|
exports.Runner = Runner;
|
|
86
122
|
//# sourceMappingURL=runner.js.map
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA4B;AAC5B,2BAA6B;AAC7B,2BAAkC;AASlC,MAAa,MAAM;IAOjB,YAAoB,SAAiB,EAAE,UAAkB;QALjD,cAAS,GAAqB,IAAI,GAAG,EAAe,CAAC;QAM3D,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,SAAiB,EAAE,UAAkB,EAAE,UAAmB,IAAI;QAC/E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAS,EAAE,OAAY,EAAE,IAA0B;QAC5D,IAAI,CAAC,KAAK,GAAG;YACX,IAAI,EAAE,IAAI;YACV,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAA;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,EAAuB;QACxD,IAAI,CAAC;YACH,MAAM,EAAE,EAAE,CAAC;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IAC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,CAAC,2CAA2C,MAAM,EAAE,CAAC,CAAC;QAEjE,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE;;YAEpE,MAAM;;OAEX,CAAC,CAAC;YAEH,MAAM,EAAE,MAAM,EAAE,GAAG,wDAAa,kBAAkB,GAAC,CAAC;YACpD,MAAM,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,KAAM,CAAC,IAAI,EAAE,IAAI,CAAC,KAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAEhF,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;YAExD,OAAO,WAAW,CAAC,KAAK,EAAE,SAAS,IAAI,IAAI,GAAG,EAAmB,CAAC;QACpE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,aAAqB,EAAE,WAAoB;QACzD,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,aAAa,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACtD,CAAC;CACF;AAvGD,wBAuGC"}
|
package/package.json
CHANGED
package/src/runner.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { homedir } from 'os';
|
|
3
3
|
import { readFileSync } from 'fs';
|
|
4
|
-
import { BrowserContext, Page } from '@playwright/test';
|
|
5
|
-
import { expect } from '@playwright/test';
|
|
6
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
5
|
|
|
8
6
|
interface State {
|
|
9
|
-
context:
|
|
10
|
-
page:
|
|
7
|
+
context: any;
|
|
8
|
+
page: any;
|
|
11
9
|
variables: Map<string, any>;
|
|
12
10
|
}
|
|
13
11
|
|
|
@@ -33,7 +31,7 @@ export class Runner {
|
|
|
33
31
|
this.abortController.abort();
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
async init(page:
|
|
34
|
+
async init(page: any, context: any, data?: Record<string, any>): Promise<void> {
|
|
37
35
|
this.state = {
|
|
38
36
|
page: page,
|
|
39
37
|
context: context,
|
|
@@ -82,24 +80,20 @@ export class Runner {
|
|
|
82
80
|
return readFileSync(scriptPath, 'utf-8');
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
async
|
|
86
|
-
const
|
|
87
|
-
if (!scriptContent) {
|
|
88
|
-
throw new Error(`Reusable test script not found: ${useTestCaseId}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const reuseRunner = Runner.NewInstance(this.projectId, useTestCaseId);
|
|
83
|
+
async runScript(testId: string, script: string): Promise<Map<string, unknown>> {
|
|
84
|
+
const reuseRunner = Runner.NewInstance(this.projectId, testId);
|
|
92
85
|
await reuseRunner.init(this.state!.page, this.state!.context);
|
|
93
86
|
|
|
94
|
-
console.log(`Starting to execute reusable test case: ${
|
|
87
|
+
console.log(`Starting to execute reusable test case: ${testId}`);
|
|
95
88
|
|
|
96
89
|
try {
|
|
97
90
|
const executeScript = new Function('runner', 'page', 'context', 'expect', `
|
|
98
91
|
return (async () => {
|
|
99
|
-
${
|
|
92
|
+
${script}
|
|
100
93
|
})();
|
|
101
94
|
`);
|
|
102
95
|
|
|
96
|
+
const { expect } = await import('@playwright/test');
|
|
103
97
|
await executeScript(reuseRunner, this.state!.page, this.state!.context, expect);
|
|
104
98
|
|
|
105
99
|
console.log(`Reusable test case executed successfully`);
|
|
@@ -109,4 +103,13 @@ export class Runner {
|
|
|
109
103
|
throw new Error(`reuseTest execution failed, error: ${error instanceof Error ? error.message : String(error)}`);
|
|
110
104
|
}
|
|
111
105
|
}
|
|
106
|
+
|
|
107
|
+
async reuseTest(useTestCaseId: string, description?: string): Promise<Map<string, unknown>> {
|
|
108
|
+
const scriptContent = this.loadTestScript(useTestCaseId);
|
|
109
|
+
if (!scriptContent) {
|
|
110
|
+
throw new Error(`Reusable test script not found: ${useTestCaseId}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return this.runScript(useTestCaseId, scriptContent);
|
|
114
|
+
}
|
|
112
115
|
}
|