@cotestdev/ai-runner-fake 0.0.9 → 0.0.11
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 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +15 -38
- package/dist/runner.js.map +1 -1
- package/package.json +1 -1
- package/src/runner.ts +17 -5
package/dist/runner.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export declare class Runner {
|
|
|
3
3
|
private projectId;
|
|
4
4
|
private testCaseId;
|
|
5
5
|
private state?;
|
|
6
|
+
private exteralContext;
|
|
6
7
|
private constructor();
|
|
7
8
|
static NewInstance(projectId: string, testCaseId: string, canHeal?: boolean): Runner;
|
|
8
9
|
stop(): void;
|
|
10
|
+
setExternalContext(context: Record<string, any>): void;
|
|
9
11
|
init(page: any, context: any, data?: Record<string, any>): Promise<void>;
|
|
10
12
|
runStep(description: string, fn: () => Promise<void>): Promise<void>;
|
|
11
13
|
set(key: string, value: any): void;
|
|
@@ -18,5 +20,6 @@ export declare class Runner {
|
|
|
18
20
|
private loadTestScript;
|
|
19
21
|
runScript(testId: string, script: string): Promise<Record<string, unknown>>;
|
|
20
22
|
reuseTest(useTestCaseId: string, description?: string): Promise<Record<string, unknown>>;
|
|
23
|
+
private log;
|
|
21
24
|
}
|
|
22
25
|
//# 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":"AAYA,qBAAa,MAAM;IACjB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAC,CAAQ;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAYA,qBAAa,MAAM;I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EAAE,OAAO,CAAC,CAAC;IAS9F,OAAO,CAAC,GAAG;CAGZ"}
|
package/dist/runner.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
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
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.Runner = void 0;
|
|
37
4
|
const path_1 = require("path");
|
|
@@ -39,6 +6,7 @@ const os_1 = require("os");
|
|
|
39
6
|
const fs_1 = require("fs");
|
|
40
7
|
class Runner {
|
|
41
8
|
constructor(projectId, testCaseId) {
|
|
9
|
+
this.exteralContext = {};
|
|
42
10
|
this.abortController = new AbortController();
|
|
43
11
|
this.projectId = projectId;
|
|
44
12
|
this.testCaseId = testCaseId;
|
|
@@ -50,6 +18,9 @@ class Runner {
|
|
|
50
18
|
stop() {
|
|
51
19
|
this.abortController.abort();
|
|
52
20
|
}
|
|
21
|
+
setExternalContext(context) {
|
|
22
|
+
this.exteralContext = context;
|
|
23
|
+
}
|
|
53
24
|
async init(page, context, data) {
|
|
54
25
|
this.state = {
|
|
55
26
|
page: page,
|
|
@@ -60,9 +31,12 @@ class Runner {
|
|
|
60
31
|
}
|
|
61
32
|
async runStep(description, fn) {
|
|
62
33
|
try {
|
|
34
|
+
this.log(`Starting step: ${description}`);
|
|
63
35
|
await fn();
|
|
36
|
+
this.log(`Step successful: ${description}`);
|
|
64
37
|
}
|
|
65
38
|
catch (error) {
|
|
39
|
+
this.log(`Step failed: ${description}, error: ${error}`);
|
|
66
40
|
throw error;
|
|
67
41
|
}
|
|
68
42
|
}
|
|
@@ -102,19 +76,19 @@ class Runner {
|
|
|
102
76
|
async runScript(testId, script) {
|
|
103
77
|
const reuseRunner = Runner.NewInstance(this.projectId, testId);
|
|
104
78
|
await reuseRunner.init(this.state.page, this.state.context, { ...this.getAll() });
|
|
105
|
-
|
|
79
|
+
this.log(`Starting to execute reusable test case: ${testId}`);
|
|
106
80
|
try {
|
|
107
|
-
const executeScript = new Function('runner', 'page', 'context', 'expect', `
|
|
81
|
+
const executeScript = new Function('runner', 'page', 'context', 'expect', ...Object.keys(this.exteralContext), `
|
|
108
82
|
return (async () => {
|
|
109
83
|
${script}
|
|
110
84
|
})();
|
|
111
85
|
`);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
console.log(`Reusable test case executed successfully`);
|
|
86
|
+
await executeScript(reuseRunner, this.state.page, this.state.context, ...Object.values(this.exteralContext));
|
|
87
|
+
this.log(`Reusable test case executed successfully`);
|
|
115
88
|
return { ...reuseRunner.state?.variables || {} };
|
|
116
89
|
}
|
|
117
90
|
catch (error) {
|
|
91
|
+
this.log(`reuseTest execution failed, error: ${error}`);
|
|
118
92
|
throw new Error(`reuseTest execution failed, error: ${error instanceof Error ? error.message : String(error)}`);
|
|
119
93
|
}
|
|
120
94
|
}
|
|
@@ -125,6 +99,9 @@ class Runner {
|
|
|
125
99
|
}
|
|
126
100
|
return this.runScript(useTestCaseId, scriptContent);
|
|
127
101
|
}
|
|
102
|
+
log(msg, ...other) {
|
|
103
|
+
console.log(`[Runner] ${msg}`, ...other);
|
|
104
|
+
}
|
|
128
105
|
}
|
|
129
106
|
exports.Runner = Runner;
|
|
130
107
|
//# 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;AAUlC,MAAa,MAAM;IAOjB,YAAoB,SAAiB,EAAE,UAAkB;QAFjD,mBAAc,GAAwB,EAAE,CAAC;QAG/C,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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G,KAAU;QACpC,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AA5HD,wBA4HC"}
|
package/package.json
CHANGED
package/src/runner.ts
CHANGED
|
@@ -15,6 +15,7 @@ export class Runner {
|
|
|
15
15
|
private projectId: string;
|
|
16
16
|
private testCaseId: string;
|
|
17
17
|
private state?: State;
|
|
18
|
+
private exteralContext: Record<string, any> = {};
|
|
18
19
|
|
|
19
20
|
private constructor(projectId: string, testCaseId: string) {
|
|
20
21
|
this.abortController = new AbortController();
|
|
@@ -31,6 +32,10 @@ export class Runner {
|
|
|
31
32
|
this.abortController.abort();
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
setExternalContext(context: Record<string, any>) {
|
|
36
|
+
this.exteralContext = context;
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
async init(page: any, context: any, data?: Record<string, any>): Promise<void> {
|
|
35
40
|
this.state = {
|
|
36
41
|
page: page,
|
|
@@ -42,8 +47,11 @@ export class Runner {
|
|
|
42
47
|
|
|
43
48
|
async runStep(description: string, fn: () => Promise<void>) {
|
|
44
49
|
try {
|
|
50
|
+
this.log(`Starting step: ${description}`);
|
|
45
51
|
await fn();
|
|
52
|
+
this.log(`Step successful: ${description}`);
|
|
46
53
|
} catch (error) {
|
|
54
|
+
this.log(`Step failed: ${description}, error: ${error}`);
|
|
47
55
|
throw error;
|
|
48
56
|
}
|
|
49
57
|
}
|
|
@@ -94,22 +102,22 @@ export class Runner {
|
|
|
94
102
|
const reuseRunner = Runner.NewInstance(this.projectId, testId);
|
|
95
103
|
await reuseRunner.init(this.state!.page, this.state!.context, { ...this.getAll() });
|
|
96
104
|
|
|
97
|
-
|
|
105
|
+
this.log(`Starting to execute reusable test case: ${testId}`);
|
|
98
106
|
|
|
99
107
|
try {
|
|
100
|
-
const executeScript = new Function('runner', 'page', 'context', 'expect', `
|
|
108
|
+
const executeScript = new Function('runner', 'page', 'context', 'expect', ...Object.keys(this.exteralContext), `
|
|
101
109
|
return (async () => {
|
|
102
110
|
${script}
|
|
103
111
|
})();
|
|
104
112
|
`);
|
|
105
113
|
|
|
106
|
-
|
|
107
|
-
await executeScript(reuseRunner, this.state!.page, this.state!.context, expect);
|
|
114
|
+
await executeScript(reuseRunner, this.state!.page, this.state!.context, ...Object.values(this.exteralContext));
|
|
108
115
|
|
|
109
|
-
|
|
116
|
+
this.log(`Reusable test case executed successfully`);
|
|
110
117
|
|
|
111
118
|
return { ...reuseRunner.state?.variables || {} };
|
|
112
119
|
} catch (error) {
|
|
120
|
+
this.log(`reuseTest execution failed, error: ${error}`);
|
|
113
121
|
throw new Error(`reuseTest execution failed, error: ${error instanceof Error ? error.message : String(error)}`);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -122,4 +130,8 @@ export class Runner {
|
|
|
122
130
|
|
|
123
131
|
return this.runScript(useTestCaseId, scriptContent);
|
|
124
132
|
}
|
|
133
|
+
|
|
134
|
+
private log(msg: string, ...other: any) {
|
|
135
|
+
console.log(`[Runner] ${msg}`, ...other);
|
|
136
|
+
}
|
|
125
137
|
}
|