wip
This commit is contained in:
@@ -39,8 +39,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
}
|
||||
throw reason;
|
||||
};
|
||||
const anyProcess = process as any;
|
||||
anyProcess.on('unhandledRejection', unhandledRejectionHandler);
|
||||
process.on('unhandledRejection', unhandledRejectionHandler);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -54,8 +53,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
afterAll(() => {
|
||||
if (unhandledRejectionHandler) {
|
||||
const anyProcess = process as any;
|
||||
anyProcess.removeListener('unhandledRejection', unhandledRejectionHandler);
|
||||
process.removeListener('unhandledRejection', unhandledRejectionHandler);
|
||||
unhandledRejectionHandler = null;
|
||||
}
|
||||
});
|
||||
@@ -177,12 +175,19 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
it('should log browser mode configuration with NODE_ENV source in production', async () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
const logSpy: Array<{ level: string; message: string; context?: any }> = [];
|
||||
const mockLogger = {
|
||||
debug: (msg: string, ctx?: any) => logSpy.push({ level: 'debug', message: msg, context: ctx }),
|
||||
info: (msg: string, ctx?: any) => logSpy.push({ level: 'info', message: msg, context: ctx }),
|
||||
warn: (msg: string, ctx?: any) => logSpy.push({ level: 'warn', message: msg, context: ctx }),
|
||||
error: (msg: string, ctx?: any) => logSpy.push({ level: 'error', message: msg, context: ctx }),
|
||||
const logSpy: Array<{ level: string; message: string; context?: Record<string, unknown> }> = [];
|
||||
type LoggerLike = {
|
||||
debug: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
info: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
warn: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
error: (msg: string, ctx?: Record<string, unknown>) => void;
|
||||
child: () => LoggerLike;
|
||||
};
|
||||
const mockLogger: LoggerLike = {
|
||||
debug: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'debug', message: msg, context: ctx }),
|
||||
info: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'info', message: msg, context: ctx }),
|
||||
warn: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'warn', message: msg, context: ctx }),
|
||||
error: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'error', message: msg, context: ctx }),
|
||||
child: () => mockLogger,
|
||||
};
|
||||
|
||||
@@ -192,7 +197,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter(
|
||||
{ mode: 'mock' },
|
||||
mockLogger as any
|
||||
mockLogger
|
||||
);
|
||||
|
||||
await adapter.connect();
|
||||
@@ -250,19 +255,23 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
loader.setDevelopmentMode('headed');
|
||||
|
||||
// Capture launch options
|
||||
const launches: Array<{ type: string; opts?: any; userDataDir?: string }> = [];
|
||||
type LaunchOptions = { headless?: boolean; [key: string]: unknown };
|
||||
const launches: Array<{ type: string; opts?: LaunchOptions; userDataDir?: string }> = [];
|
||||
|
||||
const mockLauncher = {
|
||||
launch: async (opts: any) => {
|
||||
launch: async (opts: LaunchOptions) => {
|
||||
launches.push({ type: 'launch', opts });
|
||||
return {
|
||||
newContext: async () => ({ newPage: async () => ({ setDefaultTimeout: () => {}, close: async () => {} }), close: async () => {} }),
|
||||
newContext: async () => ({
|
||||
newPage: async () => ({ setDefaultTimeout: () => {}, close: async () => {} }),
|
||||
close: async () => {},
|
||||
}),
|
||||
newPage: async () => ({ setDefaultTimeout: () => {}, close: async () => {} }),
|
||||
close: async () => {},
|
||||
newContextSync: () => {},
|
||||
};
|
||||
},
|
||||
launchPersistentContext: async (userDataDir: string, opts: any) => {
|
||||
launchPersistentContext: async (userDataDir: string, opts: LaunchOptions) => {
|
||||
launches.push({ type: 'launchPersistent', userDataDir, opts });
|
||||
return {
|
||||
pages: () => [{ setDefaultTimeout: () => {}, close: async () => {} }],
|
||||
@@ -273,9 +282,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
};
|
||||
|
||||
// Inject test launcher
|
||||
(PlaywrightAutomationAdapter as any).testLauncher = mockLauncher;
|
||||
const AdapterWithTestLauncher = PlaywrightAutomationAdapter as typeof PlaywrightAutomationAdapter & {
|
||||
testLauncher?: typeof mockLauncher;
|
||||
};
|
||||
AdapterWithTestLauncher.testLauncher = mockLauncher;
|
||||
|
||||
adapter = new PlaywrightAutomationAdapter({ mode: 'mock' }, undefined as any, loader as any);
|
||||
adapter = new PlaywrightAutomationAdapter({ mode: 'mock' }, undefined, loader);
|
||||
|
||||
// First connect => loader says headed => headless should be false
|
||||
const r1 = await adapter.connect();
|
||||
@@ -296,7 +308,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
|
||||
expect(secondLaunch!.opts.headless).toBe(true);
|
||||
|
||||
// Cleanup test hook
|
||||
(PlaywrightAutomationAdapter as any).testLauncher = undefined;
|
||||
AdapterWithTestLauncher.testLauncher = undefined;
|
||||
await adapter.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user