mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 20:24:21 +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_HOST = '127.0.0.1';
|
||||||
const DEVTOOLS_ACTIVE_PORT_FILE = 'DevToolsActivePort';
|
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) {
|
switch (platform) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return path.join(
|
return path.join(
|
||||||
process.env.HOME || process.env.USERPROFILE || '',
|
env.HOME || env.USERPROFILE || '',
|
||||||
'Library',
|
'Library',
|
||||||
'Application Support',
|
'Application Support',
|
||||||
'Google',
|
'Google',
|
||||||
'Chrome'
|
'Chrome'
|
||||||
);
|
);
|
||||||
case 'linux':
|
case 'linux':
|
||||||
return path.join(
|
return path.join(env.HOME || env.USERPROFILE || '', '.config', 'google-chrome');
|
||||||
process.env.HOME || process.env.USERPROFILE || '',
|
|
||||||
'.config',
|
|
||||||
'google-chrome'
|
|
||||||
);
|
|
||||||
case 'win32': {
|
case 'win32': {
|
||||||
const localAppData = process.env.LOCALAPPDATA;
|
const localAppData = env.LOCALAPPDATA;
|
||||||
if (!localAppData) {
|
if (!localAppData) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'LOCALAPPDATA is required to resolve the default Chrome user-data-dir on Windows'
|
'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');
|
return path.join(localAppData, 'Google', 'Chrome', 'User Data');
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return path.join(
|
return path.join(env.HOME || env.USERPROFILE || '', '.config', 'google-chrome');
|
||||||
process.env.HOME || process.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_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 () => {
|
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', () => {
|
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(
|
expect(resolveDefaultChromeUserDataDir('darwin', env)).toBe(
|
||||||
path.join(os.homedir(), 'Library', 'Application Support', 'Google', 'Chrome')
|
path.join(isolatedHome, 'Library', 'Application Support', 'Google', 'Chrome')
|
||||||
);
|
);
|
||||||
expect(resolveDefaultChromeUserDataDir('linux')).toBe(
|
expect(resolveDefaultChromeUserDataDir('linux', env)).toBe(
|
||||||
path.join(os.homedir(), '.config', 'google-chrome')
|
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')
|
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 () => {
|
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(
|
await expect(resolveBrowserRuntimeEnv({ profileDir: missingProfileDir })).rejects.toThrow(
|
||||||
`Chrome profile directory is invalid: ${missingProfileDir}`
|
`Chrome profile directory is invalid: ${missingProfileDir}`
|
||||||
|
|||||||
Reference in New Issue
Block a user