test-proxy-recorder 0.1.0 → 0.1.2
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/README.md +79 -172
- package/dist/index.cjs +597 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -5
- package/dist/index.mjs +582 -0
- package/dist/playwright/index.cjs +72 -0
- package/dist/playwright/index.d.cts +50 -0
- package/dist/playwright/index.d.ts +12 -10
- package/dist/playwright/index.mjs +65 -0
- package/dist/proxy.js +555 -4
- package/package.json +12 -5
- package/dist/ProxyServer.d.ts +0 -39
- package/dist/ProxyServer.d.ts.map +0 -1
- package/dist/ProxyServer.js +0 -464
- package/dist/cli.d.ts +0 -8
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -32
- package/dist/constants.d.ts +0 -7
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/playwright/index.d.ts.map +0 -1
- package/dist/playwright/index.js +0 -92
- package/dist/proxy.d.ts +0 -2
- package/dist/proxy.d.ts.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/utils/fileUtils.d.ts +0 -5
- package/dist/utils/fileUtils.d.ts.map +0 -1
- package/dist/utils/fileUtils.js +0 -16
- package/dist/utils/httpHelpers.d.ts +0 -4
- package/dist/utils/httpHelpers.d.ts.map +0 -1
- package/dist/utils/httpHelpers.js +0 -13
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -4
- package/dist/utils/requestKeyGenerator.d.ts +0 -3
- package/dist/utils/requestKeyGenerator.d.ts.map +0 -1
- package/dist/utils/requestKeyGenerator.js +0 -24
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/playwright/index.ts
|
|
4
|
+
var INTERNAL_API_URL = process.env.INTERNAL_API_URL || "http://localhost:8100";
|
|
5
|
+
async function setProxyMode(mode, sessionId, timeout) {
|
|
6
|
+
try {
|
|
7
|
+
const body = {
|
|
8
|
+
mode,
|
|
9
|
+
id: sessionId,
|
|
10
|
+
...timeout && { timeout }
|
|
11
|
+
};
|
|
12
|
+
const response = await fetch(`${INTERNAL_API_URL}/__control`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: { "Content-Type": "application/json" },
|
|
15
|
+
body: JSON.stringify(body)
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
const text = await response.text();
|
|
19
|
+
console.error(`Failed to set proxy mode to ${mode}:`, text);
|
|
20
|
+
throw new Error(`Failed to set proxy mode: ${text}`);
|
|
21
|
+
}
|
|
22
|
+
await response.json();
|
|
23
|
+
console.log(`Proxy mode set to: ${mode} (session: ${sessionId})`);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(`Error setting proxy mode:`, error);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function generateSessionId(testInfo) {
|
|
30
|
+
return testInfo.title.toLowerCase().replaceAll(/\s+/g, "-");
|
|
31
|
+
}
|
|
32
|
+
async function startRecording(testInfo) {
|
|
33
|
+
const sessionId = generateSessionId(testInfo);
|
|
34
|
+
await setProxyMode("recording", sessionId);
|
|
35
|
+
}
|
|
36
|
+
async function startReplay(testInfo) {
|
|
37
|
+
const sessionId = generateSessionId(testInfo);
|
|
38
|
+
await setProxyMode("replay", sessionId);
|
|
39
|
+
}
|
|
40
|
+
async function stopProxy(testInfo) {
|
|
41
|
+
const sessionId = generateSessionId(testInfo);
|
|
42
|
+
await setProxyMode("transparent", sessionId);
|
|
43
|
+
}
|
|
44
|
+
var playwrightProxy = {
|
|
45
|
+
/**
|
|
46
|
+
* Setup before test - sets the proxy mode
|
|
47
|
+
* @param testInfo - Playwright test info object
|
|
48
|
+
* @param mode - The proxy mode to use for this test
|
|
49
|
+
*/
|
|
50
|
+
async before(testInfo, mode) {
|
|
51
|
+
const sessionId = generateSessionId(testInfo);
|
|
52
|
+
console.log("Proxy setup:", { mode, sessionId });
|
|
53
|
+
await setProxyMode(mode, sessionId);
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Cleanup after test - returns to transparent mode
|
|
57
|
+
* @param testInfo - Playwright test info object
|
|
58
|
+
*/
|
|
59
|
+
async after(testInfo) {
|
|
60
|
+
const sessionId = generateSessionId(testInfo);
|
|
61
|
+
await setProxyMode("transparent", sessionId);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.generateSessionId = generateSessionId;
|
|
66
|
+
exports.playwrightProxy = playwrightProxy;
|
|
67
|
+
exports.setProxyMode = setProxyMode;
|
|
68
|
+
exports.startRecording = startRecording;
|
|
69
|
+
exports.startReplay = startReplay;
|
|
70
|
+
exports.stopProxy = stopProxy;
|
|
71
|
+
//# sourceMappingURL=index.cjs.map
|
|
72
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TestInfo } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
type ProxyMode = 'recording' | 'replay' | 'transparent';
|
|
4
|
+
type PlaywrightTestInfo = Pick<TestInfo, 'title'>;
|
|
5
|
+
/**
|
|
6
|
+
* Set the proxy mode for a given session
|
|
7
|
+
* @param mode - The proxy mode to set (recording, replay, transparent)
|
|
8
|
+
* @param sessionId - Unique identifier for the session
|
|
9
|
+
* @param timeout - Optional timeout in milliseconds
|
|
10
|
+
*/
|
|
11
|
+
declare function setProxyMode(mode: ProxyMode, sessionId: string, timeout?: number): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Generate a session ID from test info
|
|
14
|
+
* @param testInfo - Playwright test info object
|
|
15
|
+
*/
|
|
16
|
+
declare function generateSessionId(testInfo: PlaywrightTestInfo): string;
|
|
17
|
+
/**
|
|
18
|
+
* Start recording for a test
|
|
19
|
+
* @param testInfo - Playwright test info object
|
|
20
|
+
*/
|
|
21
|
+
declare function startRecording(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Start replay for a test
|
|
24
|
+
* @param testInfo - Playwright test info object
|
|
25
|
+
*/
|
|
26
|
+
declare function startReplay(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Stop recording/replay and return to transparent mode
|
|
29
|
+
* @param testInfo - Playwright test info object
|
|
30
|
+
*/
|
|
31
|
+
declare function stopProxy(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Playwright test fixture helper for managing proxy mode
|
|
34
|
+
* Use this in beforeEach/afterEach hooks
|
|
35
|
+
*/
|
|
36
|
+
declare const playwrightProxy: {
|
|
37
|
+
/**
|
|
38
|
+
* Setup before test - sets the proxy mode
|
|
39
|
+
* @param testInfo - Playwright test info object
|
|
40
|
+
* @param mode - The proxy mode to use for this test
|
|
41
|
+
*/
|
|
42
|
+
before(testInfo: PlaywrightTestInfo, mode: ProxyMode): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Cleanup after test - returns to transparent mode
|
|
45
|
+
* @param testInfo - Playwright test info object
|
|
46
|
+
*/
|
|
47
|
+
after(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { type PlaywrightTestInfo, type ProxyMode, generateSessionId, playwrightProxy, setProxyMode, startRecording, startReplay, stopProxy };
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { TestInfo } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
type ProxyMode = 'recording' | 'replay' | 'transparent';
|
|
4
|
+
type PlaywrightTestInfo = Pick<TestInfo, 'title'>;
|
|
4
5
|
/**
|
|
5
6
|
* Set the proxy mode for a given session
|
|
6
7
|
* @param mode - The proxy mode to set (recording, replay, transparent)
|
|
7
8
|
* @param sessionId - Unique identifier for the session
|
|
8
9
|
* @param timeout - Optional timeout in milliseconds
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
declare function setProxyMode(mode: ProxyMode, sessionId: string, timeout?: number): Promise<void>;
|
|
11
12
|
/**
|
|
12
13
|
* Generate a session ID from test info
|
|
13
14
|
* @param testInfo - Playwright test info object
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
declare function generateSessionId(testInfo: PlaywrightTestInfo): string;
|
|
16
17
|
/**
|
|
17
18
|
* Start recording for a test
|
|
18
19
|
* @param testInfo - Playwright test info object
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function startRecording(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
21
22
|
/**
|
|
22
23
|
* Start replay for a test
|
|
23
24
|
* @param testInfo - Playwright test info object
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
|
+
declare function startReplay(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
26
27
|
/**
|
|
27
28
|
* Stop recording/replay and return to transparent mode
|
|
28
29
|
* @param testInfo - Playwright test info object
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
declare function stopProxy(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
31
32
|
/**
|
|
32
33
|
* Playwright test fixture helper for managing proxy mode
|
|
33
34
|
* Use this in beforeEach/afterEach hooks
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
+
declare const playwrightProxy: {
|
|
36
37
|
/**
|
|
37
38
|
* Setup before test - sets the proxy mode
|
|
38
39
|
* @param testInfo - Playwright test info object
|
|
@@ -45,4 +46,5 @@ export declare const playwrightProxy: {
|
|
|
45
46
|
*/
|
|
46
47
|
after(testInfo: PlaywrightTestInfo): Promise<void>;
|
|
47
48
|
};
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
export { type PlaywrightTestInfo, type ProxyMode, generateSessionId, playwrightProxy, setProxyMode, startRecording, startReplay, stopProxy };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/playwright/index.ts
|
|
2
|
+
var INTERNAL_API_URL = process.env.INTERNAL_API_URL || "http://localhost:8100";
|
|
3
|
+
async function setProxyMode(mode, sessionId, timeout) {
|
|
4
|
+
try {
|
|
5
|
+
const body = {
|
|
6
|
+
mode,
|
|
7
|
+
id: sessionId,
|
|
8
|
+
...timeout && { timeout }
|
|
9
|
+
};
|
|
10
|
+
const response = await fetch(`${INTERNAL_API_URL}/__control`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: { "Content-Type": "application/json" },
|
|
13
|
+
body: JSON.stringify(body)
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
const text = await response.text();
|
|
17
|
+
console.error(`Failed to set proxy mode to ${mode}:`, text);
|
|
18
|
+
throw new Error(`Failed to set proxy mode: ${text}`);
|
|
19
|
+
}
|
|
20
|
+
await response.json();
|
|
21
|
+
console.log(`Proxy mode set to: ${mode} (session: ${sessionId})`);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(`Error setting proxy mode:`, error);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function generateSessionId(testInfo) {
|
|
28
|
+
return testInfo.title.toLowerCase().replaceAll(/\s+/g, "-");
|
|
29
|
+
}
|
|
30
|
+
async function startRecording(testInfo) {
|
|
31
|
+
const sessionId = generateSessionId(testInfo);
|
|
32
|
+
await setProxyMode("recording", sessionId);
|
|
33
|
+
}
|
|
34
|
+
async function startReplay(testInfo) {
|
|
35
|
+
const sessionId = generateSessionId(testInfo);
|
|
36
|
+
await setProxyMode("replay", sessionId);
|
|
37
|
+
}
|
|
38
|
+
async function stopProxy(testInfo) {
|
|
39
|
+
const sessionId = generateSessionId(testInfo);
|
|
40
|
+
await setProxyMode("transparent", sessionId);
|
|
41
|
+
}
|
|
42
|
+
var playwrightProxy = {
|
|
43
|
+
/**
|
|
44
|
+
* Setup before test - sets the proxy mode
|
|
45
|
+
* @param testInfo - Playwright test info object
|
|
46
|
+
* @param mode - The proxy mode to use for this test
|
|
47
|
+
*/
|
|
48
|
+
async before(testInfo, mode) {
|
|
49
|
+
const sessionId = generateSessionId(testInfo);
|
|
50
|
+
console.log("Proxy setup:", { mode, sessionId });
|
|
51
|
+
await setProxyMode(mode, sessionId);
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* Cleanup after test - returns to transparent mode
|
|
55
|
+
* @param testInfo - Playwright test info object
|
|
56
|
+
*/
|
|
57
|
+
async after(testInfo) {
|
|
58
|
+
const sessionId = generateSessionId(testInfo);
|
|
59
|
+
await setProxyMode("transparent", sessionId);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { generateSessionId, playwrightProxy, setProxyMode, startRecording, startReplay, stopProxy };
|
|
64
|
+
//# sourceMappingURL=index.mjs.map
|
|
65
|
+
//# sourceMappingURL=index.mjs.map
|