mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 12:15:57 +00:00
fix(test): isolate chrome reuse home env expectations
This commit is contained in:
@@ -19,24 +19,23 @@ export interface BrowserRuntimeEnv {
|
||||
const DEVTOOLS_HOST = '127.0.0.1';
|
||||
const DEVTOOLS_ACTIVE_PORT_FILE = 'DevToolsActivePort';
|
||||
|
||||
export function resolveDefaultChromeUserDataDir(platform = process.platform): string {
|
||||
export function resolveDefaultChromeUserDataDir(
|
||||
platform = process.platform,
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): string {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return path.join(
|
||||
process.env.HOME || process.env.USERPROFILE || '',
|
||||
env.HOME || env.USERPROFILE || '',
|
||||
'Library',
|
||||
'Application Support',
|
||||
'Google',
|
||||
'Chrome'
|
||||
);
|
||||
case 'linux':
|
||||
return path.join(
|
||||
process.env.HOME || process.env.USERPROFILE || '',
|
||||
'.config',
|
||||
'google-chrome'
|
||||
);
|
||||
return path.join(env.HOME || env.USERPROFILE || '', '.config', 'google-chrome');
|
||||
case 'win32': {
|
||||
const localAppData = process.env.LOCALAPPDATA;
|
||||
const localAppData = env.LOCALAPPDATA;
|
||||
if (!localAppData) {
|
||||
throw new Error(
|
||||
'LOCALAPPDATA is required to resolve the default Chrome user-data-dir on Windows'
|
||||
@@ -45,11 +44,7 @@ export function resolveDefaultChromeUserDataDir(platform = process.platform): st
|
||||
return path.join(localAppData, 'Google', 'Chrome', 'User Data');
|
||||
}
|
||||
default:
|
||||
return path.join(
|
||||
process.env.HOME || process.env.USERPROFILE || '',
|
||||
'.config',
|
||||
'google-chrome'
|
||||
);
|
||||
return path.join(env.HOME || env.USERPROFILE || '', '.config', 'google-chrome');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,9 @@ describe('chrome reuse resolver', () => {
|
||||
});
|
||||
|
||||
expect(runtimeEnv.CCS_BROWSER_DEVTOOLS_PORT).toBe(String(server.port));
|
||||
expect(runtimeEnv.CCS_BROWSER_DEVTOOLS_WS_URL).toBe('ws://127.0.0.1/devtools/browser/explicit-port');
|
||||
expect(runtimeEnv.CCS_BROWSER_DEVTOOLS_WS_URL).toBe(
|
||||
'ws://127.0.0.1/devtools/browser/explicit-port'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws a clear error when DevToolsActivePort metadata is missing', async () => {
|
||||
@@ -196,15 +198,20 @@ describe('chrome reuse resolver', () => {
|
||||
});
|
||||
|
||||
it('resolves platform default Chrome user-data-dir paths', () => {
|
||||
process.env.LOCALAPPDATA = 'C:/Users/test/AppData/Local';
|
||||
const isolatedHome = createTempDir('ccs-chrome-home-');
|
||||
const env = {
|
||||
HOME: isolatedHome,
|
||||
USERPROFILE: isolatedHome,
|
||||
LOCALAPPDATA: 'C:/Users/test/AppData/Local',
|
||||
};
|
||||
|
||||
expect(resolveDefaultChromeUserDataDir('darwin')).toBe(
|
||||
path.join(os.homedir(), 'Library', 'Application Support', 'Google', 'Chrome')
|
||||
expect(resolveDefaultChromeUserDataDir('darwin', env)).toBe(
|
||||
path.join(isolatedHome, 'Library', 'Application Support', 'Google', 'Chrome')
|
||||
);
|
||||
expect(resolveDefaultChromeUserDataDir('linux')).toBe(
|
||||
path.join(os.homedir(), '.config', 'google-chrome')
|
||||
expect(resolveDefaultChromeUserDataDir('linux', env)).toBe(
|
||||
path.join(isolatedHome, '.config', 'google-chrome')
|
||||
);
|
||||
expect(resolveDefaultChromeUserDataDir('win32')).toBe(
|
||||
expect(resolveDefaultChromeUserDataDir('win32', env)).toBe(
|
||||
path.normalize('C:/Users/test/AppData/Local/Google/Chrome/User Data')
|
||||
);
|
||||
});
|
||||
@@ -218,7 +225,10 @@ describe('chrome reuse resolver', () => {
|
||||
});
|
||||
|
||||
it('throws a clear error when the resolved profile directory does not exist', async () => {
|
||||
const missingProfileDir = path.join(createTempDir('ccs-chrome-missing-dir-'), 'missing-profile');
|
||||
const missingProfileDir = path.join(
|
||||
createTempDir('ccs-chrome-missing-dir-'),
|
||||
'missing-profile'
|
||||
);
|
||||
|
||||
await expect(resolveBrowserRuntimeEnv({ profileDir: missingProfileDir })).rejects.toThrow(
|
||||
`Chrome profile directory is invalid: ${missingProfileDir}`
|
||||
|
||||
Reference in New Issue
Block a user