mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	chore: prepare to reuse test server from ui mode (3) (#29989)
This commit is contained in:
		
							parent
							
								
									70e6cdac57
								
							
						
					
					
						commit
						c7b074d39e
					
				@ -86,8 +86,12 @@ export class HttpServer {
 | 
			
		||||
      transport.close = () => ws.close();
 | 
			
		||||
      ws.on('message', async (message: string) => {
 | 
			
		||||
        const { id, method, params } = JSON.parse(message);
 | 
			
		||||
        const result = await transport.dispatch(method, params);
 | 
			
		||||
        ws.send(JSON.stringify({ id, result }));
 | 
			
		||||
        try {
 | 
			
		||||
          const result = await transport.dispatch(method, params);
 | 
			
		||||
          ws.send(JSON.stringify({ id, result }));
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
          ws.send(JSON.stringify({ id, error: String(e) }));
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
      ws.on('close', () => transport.onclose());
 | 
			
		||||
      ws.on('error', () => transport.onclose());
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ import { TestRun, createTaskRunner, createTaskRunnerForList } from './tasks';
 | 
			
		||||
import type { FullConfigInternal } from '../common/config';
 | 
			
		||||
import { colors } from 'playwright-core/lib/utilsBundle';
 | 
			
		||||
import { runWatchModeLoop } from './watchMode';
 | 
			
		||||
import { runTestServer } from './uiMode';
 | 
			
		||||
import { runTestServer } from './testServer';
 | 
			
		||||
import { InternalReporter } from '../reporters/internalReporter';
 | 
			
		||||
import { Multiplexer } from '../reporters/multiplexer';
 | 
			
		||||
import type { Suite } from '../common/test';
 | 
			
		||||
 | 
			
		||||
@ -21,8 +21,7 @@ import type { FullResult, Location, TestError } from '../../types/testReporter';
 | 
			
		||||
import { collectAffectedTestFiles, dependenciesForTestFile } from '../transform/compilationCache';
 | 
			
		||||
import type { FullConfigInternal } from '../common/config';
 | 
			
		||||
import { InternalReporter } from '../reporters/internalReporter';
 | 
			
		||||
import { TeleReporterEmitter } from '../reporters/teleEmitter';
 | 
			
		||||
import { createReporters } from './reporters';
 | 
			
		||||
import { createReporterForTestServer, createReporters } from './reporters';
 | 
			
		||||
import { TestRun, createTaskRunnerForList, createTaskRunnerForWatch, createTaskRunnerForWatchSetup } from './tasks';
 | 
			
		||||
import { open } from 'playwright-core/lib/utilsBundle';
 | 
			
		||||
import ListReporter from '../reporters/list';
 | 
			
		||||
@ -157,12 +156,13 @@ class TestServerDispatcher implements TestServerInterface {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async listTests(params: { reporter?: string; fileNames: string[]; }) {
 | 
			
		||||
    this._queue = this._queue.then(() => this._innerListTests(params));
 | 
			
		||||
    this._queue = this._queue.then(() => this._innerListTests(params)).catch(printInternalError);
 | 
			
		||||
    await this._queue;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private async _innerListTests(params: { reporter?: string; fileNames?: string[]; }) {
 | 
			
		||||
    const reporter = new InternalReporter(new TeleReporterEmitter(e => this._dispatchEvent('listReport', e), { omitBuffers: true }));
 | 
			
		||||
    const wireReporter = await createReporterForTestServer(this._config, params.reporter || require.resolve('./uiModeReporter'), 'list', e => this._dispatchEvent('listReport', e));
 | 
			
		||||
    const reporter = new InternalReporter(wireReporter);
 | 
			
		||||
    this._config.cliArgs = params.fileNames || [];
 | 
			
		||||
    this._config.cliListOnly = true;
 | 
			
		||||
    this._config.testIdMatcher = undefined;
 | 
			
		||||
@ -183,7 +183,7 @@ class TestServerDispatcher implements TestServerInterface {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async runTests(params: { reporter?: string; locations?: string[] | undefined; grep?: string | undefined; testIds?: string[] | undefined; headed?: boolean | undefined; oneWorker?: boolean | undefined; trace?: 'off' | 'on' | undefined; projects?: string[] | undefined; reuseContext?: boolean | undefined; connectWsEndpoint?: string | undefined; }) {
 | 
			
		||||
    this._queue = this._queue.then(() => this._innerRunTests(params));
 | 
			
		||||
    this._queue = this._queue.then(() => this._innerRunTests(params)).catch(printInternalError);
 | 
			
		||||
    await this._queue;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -199,7 +199,7 @@ class TestServerDispatcher implements TestServerInterface {
 | 
			
		||||
    this._config.testIdMatcher = id => !testIdSet || testIdSet.has(id);
 | 
			
		||||
 | 
			
		||||
    const reporters = await createReporters(this._config, 'ui');
 | 
			
		||||
    reporters.push(new TeleReporterEmitter(e => this._dispatchEvent('testReport', e), { omitBuffers: true }));
 | 
			
		||||
    reporters.push(await createReporterForTestServer(this._config, params.reporter || require.resolve('./uiModeReporter'), 'list', e => this._dispatchEvent('testReport', e)));
 | 
			
		||||
    const reporter = new InternalReporter(new Multiplexer(reporters));
 | 
			
		||||
    const taskRunner = createTaskRunnerForWatch(this._config, reporter);
 | 
			
		||||
    const testRun = new TestRun(this._config, reporter);
 | 
			
		||||
@ -291,3 +291,8 @@ async function installBrowsers() {
 | 
			
		||||
  const executables = registry.defaultExecutables();
 | 
			
		||||
  await registry.install(executables, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function printInternalError(e: Error) {
 | 
			
		||||
  // eslint-disable-next-line no-console
 | 
			
		||||
  console.error('Internal error:', e);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								packages/playwright/src/runner/uiModeReporter.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								packages/playwright/src/runner/uiModeReporter.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright (c) Microsoft Corporation.
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 *
 | 
			
		||||
 * http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { TeleReporterEmitter } from '../reporters/teleEmitter';
 | 
			
		||||
 | 
			
		||||
class UIModeReporter extends TeleReporterEmitter {
 | 
			
		||||
  constructor(options: any) {
 | 
			
		||||
    super(options._send, { omitBuffers: true });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default UIModeReporter;
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user