feat(rpc): in-process rpc on by default (#3104)
This commit is contained in:
		
							parent
							
								
									1b8128eb84
								
							
						
					
					
						commit
						3179e71912
					
				
							
								
								
									
										3
									
								
								index.js
								
								
								
								
							
							
						
						
									
										3
									
								
								index.js
								
								
								
								
							|  | @ -16,8 +16,9 @@ | |||
| 
 | ||||
| const { Playwright } = require('./lib/server/playwright'); | ||||
| const { Electron } = require('./lib/server/electron'); | ||||
| const { setupInProcess } = require('./lib/rpc/inprocess'); | ||||
| const path = require('path'); | ||||
| 
 | ||||
| const playwright = new Playwright(__dirname, require(path.join(__dirname, 'browsers.json'))['browsers']); | ||||
| playwright.electron = new Electron(); | ||||
| module.exports = playwright; | ||||
| module.exports = setupInProcess(playwright); | ||||
|  |  | |||
|  | @ -21,9 +21,9 @@ | |||
|     "tsc": "tsc -p .", | ||||
|     "tsc-installer": "tsc -p ./src/install/tsconfig.json", | ||||
|     "doc": "node utils/doclint/cli.js", | ||||
|     "doc-channel": "node utils/doclint/cli.js --channel", | ||||
|     "doc-no-channel": "node utils/doclint/cli.js --no-channel", | ||||
|     "test-infra": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js", | ||||
|     "lint": "npm run eslint && npm run tsc && npm run doc && npm run doc-channel && npm run check-deps && npm run generate-channels && npm run test-types && npm run test-infra", | ||||
|     "lint": "npm run eslint && npm run tsc && npm run doc && npm run doc-no-channel && npm run check-deps && npm run generate-channels && npm run test-types && npm run test-infra", | ||||
|     "debug-test": "node --inspect-brk test/test.js", | ||||
|     "clean": "rimraf lib && rimraf types", | ||||
|     "prepare": "node install-from-github.js", | ||||
|  |  | |||
|  | @ -15,5 +15,6 @@ | |||
|  */ | ||||
| 
 | ||||
| const { Playwright } = require('./lib/server/playwright'); | ||||
| const { setupInProcess } = require('./lib/rpc/inprocess'); | ||||
| 
 | ||||
| module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']); | ||||
| module.exports = setupInProcess(new Playwright(__dirname, require('./browsers.json')['browsers'])); | ||||
|  |  | |||
|  | @ -16,7 +16,8 @@ | |||
| 
 | ||||
| const { Playwright } = require('playwright-core/lib/server/playwright'); | ||||
| const { Electron } = require('playwright-core/lib/server/electron'); | ||||
| const { setupInProcess } = require('./lib/rpc/inprocess'); | ||||
| 
 | ||||
| const playwright = new Playwright(__dirname, require('./browsers.json')['browsers']); | ||||
| playwright.electron = new Electron(); | ||||
| module.exports = playwright; | ||||
| module.exports = setupInProcess(playwright); | ||||
|  |  | |||
|  | @ -9,10 +9,8 @@ | |||
| 
 | ||||
|   const path = require('path'); | ||||
|   const { setUnderTest } = require(path.join(playwrightPath, 'lib', 'helper')); | ||||
|   const { setupInProcess } = require(path.join(playwrightPath, 'lib', 'rpc', 'inprocess')); | ||||
|   setUnderTest(); | ||||
|   const playwrightImpl = require(path.join(playwrightPath, 'index')); | ||||
|   const playwright = process.env.PWCHANNEL ? setupInProcess(playwrightImpl) : playwrightImpl; | ||||
|   const playwright = require(path.join(playwrightPath, 'index')); | ||||
| 
 | ||||
|   const browserServer = await playwright[browserTypeName].launchServer(launchOptions); | ||||
|   browserServer.on('close', (exitCode, signal) => { | ||||
|  |  | |||
|  | @ -16,17 +16,15 @@ | |||
| 
 | ||||
| const path = require('path'); | ||||
| const childProcess = require('child_process'); | ||||
| const playwrightImpl = require('../../index'); | ||||
| 
 | ||||
| const { TestServer } = require('../../utils/testserver'); | ||||
| const { Connection } = require('../../lib/rpc/client/connection'); | ||||
| const { Transport } = require('../../lib/rpc/transport'); | ||||
| const { setupInProcess } = require('../../lib/rpc/inprocess'); | ||||
| const { setUnderTest } = require('../../lib/helper'); | ||||
| const { valueFromEnv } = require('./utils'); | ||||
| const { registerFixture, registerWorkerFixture } = require('./fixturePool'); | ||||
| 
 | ||||
| setUnderTest(); | ||||
| setUnderTest();  // Note: we must call setUnderTest before requiring Playwright.
 | ||||
| 
 | ||||
| const browserName = process.env.BROWSER || 'chromium'; | ||||
| 
 | ||||
|  | @ -102,13 +100,8 @@ module.exports = function registerFixtures(global) { | |||
|       spawnedProcess.stdin.destroy(); | ||||
|       spawnedProcess.stdout.destroy(); | ||||
|       spawnedProcess.stderr.destroy(); | ||||
|     } else if (process.env.PWCHANNEL) { | ||||
|       const playwright = setupInProcess(playwrightImpl); | ||||
|       await test(playwright); | ||||
|     } else { | ||||
|       const playwright = playwrightImpl; | ||||
|       playwright._toImpl = x => x; | ||||
|       await test(playwright); | ||||
|       await test(require('../../index')); | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ testOptions.CHROMIUM = browserName === 'chromium'; | |||
| testOptions.FFOX = browserName === 'firefox'; | ||||
| testOptions.WEBKIT = browserName === 'webkit'; | ||||
| testOptions.USES_HOOKS = process.env.PWCHANNEL === 'wire'; | ||||
| testOptions.CHANNEL = !!process.env.PWCHANNEL; | ||||
| testOptions.CHANNEL = true; | ||||
| testOptions.HEADLESS = !!valueFromEnv('HEADLESS', true); | ||||
| testOptions.ASSETS_DIR = path.join(__dirname, '..', 'assets'); | ||||
| testOptions.GOLDEN_DIR = path.join(__dirname, '..', 'golden-' + browserName); | ||||
|  |  | |||
|  | @ -81,9 +81,7 @@ function apiForBrowser(browserName) { | |||
|   const events = browserConfig.events; | ||||
|   // TODO: we should rethink our api.ts approach to ensure coverage and async stacks.
 | ||||
|   const api = { | ||||
|     ...require('../../lib/api'), | ||||
|     Browser: require('../../lib/browser').BrowserBase, | ||||
|     BrowserContext: require('../../lib/browserContext').BrowserContextBase, | ||||
|     ...require('../../lib/rpc/client/api'), | ||||
|   }; | ||||
| 
 | ||||
|   const filteredKeys = Object.keys(api).filter(apiName => { | ||||
|  |  | |||
|  | @ -26,10 +26,10 @@ const {installCoverageHooks} = require('./coverage'); | |||
| const reportOnly = !!process.env.REPORT_ONLY_PLATFORM; | ||||
| const { ModuleMocker } = require('jest-mock'); | ||||
| 
 | ||||
| Error.stackTraceLimit = 15; | ||||
| global.testOptions = require('../harness/testOptions'); | ||||
| global.registerFixture = registerFixture; | ||||
| global.registerWorkerFixture = registerWorkerFixture; | ||||
| 
 | ||||
| registerFixtures(global); | ||||
| 
 | ||||
| const browserName = process.env.BROWSER || 'chromium'; | ||||
|  | @ -42,7 +42,7 @@ let currentFixturePool = null; | |||
| process.on('SIGINT', async () => { | ||||
|   if (currentFixturePool) { | ||||
|     await currentFixturePool.teardownScope('test'); | ||||
|     await currentFixturePool.teardownScope('worker');   | ||||
|     await currentFixturePool.teardownScope('worker'); | ||||
|   } | ||||
|   process.exit(130); | ||||
| }); | ||||
|  |  | |||
|  | @ -36,9 +36,9 @@ run(); | |||
| async function run() { | ||||
|   const startTime = Date.now(); | ||||
|   const onlyBrowserVersions = process.argv.includes('--only-browser-versions'); | ||||
|   const channel = process.argv.includes('--channel'); | ||||
|   if (channel) | ||||
|     console.warn(`${YELLOW_COLOR}NOTE: checking documentation against //src/rpc/client${RESET_COLOR}`); | ||||
|   const noChannel = process.argv.includes('--no-channel'); | ||||
|   if (noChannel) | ||||
|     console.warn(`${YELLOW_COLOR}NOTE: checking documentation against //src${RESET_COLOR}`); | ||||
| 
 | ||||
|   /** @type {!Array<!Message>} */ | ||||
|   const messages = []; | ||||
|  | @ -70,11 +70,11 @@ async function run() { | |||
|       const page = await browser.newPage(); | ||||
|       const checkPublicAPI = require('./check_public_api'); | ||||
|       let jsSources; | ||||
|       if (channel) { | ||||
|         jsSources = await Source.readdir(path.join(PROJECT_DIR, 'src', 'rpc', 'client'), '', []); | ||||
|       } else { | ||||
|       if (noChannel) { | ||||
|         const rpcDir = path.join(PROJECT_DIR, 'src', 'rpc'); | ||||
|         jsSources = await Source.readdir(path.join(PROJECT_DIR, 'src'), '', [rpcDir]); | ||||
|       } else { | ||||
|         jsSources = await Source.readdir(path.join(PROJECT_DIR, 'src', 'rpc', 'client'), '', []); | ||||
|       } | ||||
|       messages.push(...await checkPublicAPI(page, [api], jsSources)); | ||||
|       await browser.close(); | ||||
|  |  | |||
|  | @ -37,8 +37,7 @@ let documentation; | |||
|   const api = await Source.readFile(path.join(PROJECT_DIR, 'docs', 'api.md')); | ||||
|   const {documentation: mdDocumentation} = await require('../doclint/check_public_api/MDBuilder')(page, [api]); | ||||
|   await browser.close(); | ||||
|   const rpcDir = path.join(PROJECT_DIR, 'src', 'rpc'); | ||||
|   const sources = await Source.readdir(path.join(PROJECT_DIR, 'src'), '', [rpcDir]); | ||||
|   const sources = await Source.readdir(path.join(PROJECT_DIR, 'src', 'rpc', 'client'), '', []); | ||||
|   const {documentation: jsDocumentation} = await require('../doclint/check_public_api/JSBuilder').checkSources(sources); | ||||
|   documentation = mergeDocumentation(mdDocumentation, jsDocumentation); | ||||
|   const handledClasses = new Set(); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue