-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest-profiles.cjs
More file actions
165 lines (142 loc) · 5.83 KB
/
test-profiles.cjs
File metadata and controls
165 lines (142 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env node
/**
* Test Chrome profile functionality
*
* Tests:
* 1. Default profile is 'superpowers-chrome'
* 2. Can set a custom profile
* 3. Profile directories are created correctly
* 4. Cannot change profile while Chrome is running
* 5. Different profiles have isolated data
*/
const chromeLib = require('./skills/browsing/chrome-ws-lib.js');
const fs = require('fs');
const path = require('path');
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function runTests() {
console.log('Testing Chrome profile functionality...\n');
try {
// Test 1: Check default profile
console.log('Test 1: Check default profile name');
const defaultProfile = chromeLib.getProfileName();
console.log(` Default profile: ${defaultProfile}`);
if (defaultProfile === 'superpowers-chrome') {
console.log(' ✓ Pass: Default profile is "superpowers-chrome"\n');
} else {
console.log(` ✗ FAIL: Expected "superpowers-chrome", got "${defaultProfile}"\n`);
process.exit(1);
}
// Test 2: Check default profile directory path
console.log('Test 2: Check default profile directory');
const defaultProfileDir = chromeLib.getChromeProfileDir('superpowers-chrome');
console.log(` Profile dir: ${defaultProfileDir}`);
if (defaultProfileDir.includes('browser-profiles') && defaultProfileDir.includes('superpowers-chrome')) {
console.log(' ✓ Pass: Profile directory path is correct\n');
} else {
console.log(' ✗ FAIL: Profile directory path is incorrect\n');
process.exit(1);
}
// Test 3: Start Chrome with default profile
console.log('Test 3: Start Chrome with default profile');
await chromeLib.startChrome();
await sleep(2000);
const mode = await chromeLib.getBrowserMode();
console.log(` Mode: ${JSON.stringify(mode)}`);
if (mode.profile === 'superpowers-chrome' && fs.existsSync(mode.profileDir)) {
console.log(' ✓ Pass: Chrome started with default profile\n');
} else {
console.log(' ✗ FAIL: Profile not set correctly\n');
process.exit(1);
}
// Test 4: Try to change profile while Chrome is running (should fail)
console.log('Test 4: Try to change profile while Chrome is running');
try {
chromeLib.setProfileName('test-profile');
console.log(' ✗ FAIL: Should have thrown error\n');
process.exit(1);
} catch (error) {
if (error.message.includes('Cannot change profile while Chrome is running')) {
console.log(` ✓ Pass: Correctly prevented profile change: ${error.message}\n`);
} else {
console.log(` ✗ FAIL: Wrong error: ${error.message}\n`);
process.exit(1);
}
}
// Test 5: Kill Chrome and change profile
console.log('Test 5: Kill Chrome and change profile');
await chromeLib.killChrome();
await sleep(1000);
const result = chromeLib.setProfileName('test-profile');
console.log(` Result: ${result}`);
const newProfile = chromeLib.getProfileName();
console.log(` New profile: ${newProfile}`);
if (newProfile === 'test-profile') {
console.log(' ✓ Pass: Profile changed successfully\n');
} else {
console.log(' ✗ FAIL: Profile not changed\n');
process.exit(1);
}
// Test 6: Start Chrome with new profile
console.log('Test 6: Start Chrome with new profile');
await chromeLib.startChrome();
await sleep(2000);
const newMode = await chromeLib.getBrowserMode();
console.log(` Mode: ${JSON.stringify(newMode)}`);
if (newMode.profile === 'test-profile' && fs.existsSync(newMode.profileDir)) {
console.log(' ✓ Pass: Chrome started with new profile\n');
} else {
console.log(' ✗ FAIL: Profile not applied\n');
process.exit(1);
}
// Test 7: Verify profile directories are separate
console.log('Test 7: Verify profile directories are separate');
const defaultDir = chromeLib.getChromeProfileDir('superpowers-chrome');
const testDir = chromeLib.getChromeProfileDir('test-profile');
console.log(` Default: ${defaultDir}`);
console.log(` Test: ${testDir}`);
if (defaultDir !== testDir && fs.existsSync(testDir)) {
console.log(' ✓ Pass: Profile directories are separate and exist\n');
} else {
console.log(' ✗ FAIL: Profile directories not properly isolated\n');
process.exit(1);
}
// Test 8: Explicitly pass profile name to startChrome
console.log('Test 8: Explicitly pass profile name to startChrome');
await chromeLib.killChrome();
await sleep(1000);
await chromeLib.startChrome(true, 'explicit-profile');
await sleep(2000);
const explicitMode = await chromeLib.getBrowserMode();
console.log(` Mode: ${JSON.stringify(explicitMode)}`);
if (explicitMode.profile === 'explicit-profile' && fs.existsSync(explicitMode.profileDir)) {
console.log(' ✓ Pass: Explicit profile parameter works\n');
} else {
console.log(' ✗ FAIL: Explicit profile not applied\n');
process.exit(1);
}
// Cleanup
console.log('Cleanup: Killing Chrome');
await chromeLib.killChrome();
await sleep(500);
console.log('\n✅ All tests passed!');
console.log('\nKey findings:');
console.log('- Default profile is "superpowers-chrome"');
console.log('- Profiles are stored in ~/.cache/superpowers/browser-profiles/{name}/');
console.log('- Profile directories persist across sessions');
console.log('- Cannot change profile while Chrome is running');
console.log('- Different profiles have completely isolated data\n');
} catch (error) {
console.error(`\n✗ Test failed with error: ${error.message}`);
console.error(error.stack);
// Try to cleanup
try {
await chromeLib.killChrome();
} catch (e) {
// Ignore cleanup errors
}
process.exit(1);
}
}
runTests();