diff --git a/index.js b/index.js index 6409628365..31266294c2 100644 --- a/index.js +++ b/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); diff --git a/package.json b/package.json index 1dfdca3205..836ad93ba5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/common/index.js b/packages/common/index.js index bcc6ecaa3d..5509391c8f 100644 --- a/packages/common/index.js +++ b/packages/common/index.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'])); diff --git a/packages/playwright-electron/index.js b/packages/playwright-electron/index.js index fe9fa4bdd3..cc3f52771d 100644 --- a/packages/playwright-electron/index.js +++ b/packages/playwright-electron/index.js @@ -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); diff --git a/test/fixtures/closeme.js b/test/fixtures/closeme.js index 3a0e6f90a9..a916c04995 100644 --- a/test/fixtures/closeme.js +++ b/test/fixtures/closeme.js @@ -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) => { diff --git a/test/harness/fixtures.js b/test/harness/fixtures.js index 4a821e1617..a5e2c5867a 100644 --- a/test/harness/fixtures.js +++ b/test/harness/fixtures.js @@ -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')); } }); diff --git a/test/harness/testOptions.js b/test/harness/testOptions.js index 2f00f81031..15cb3028c2 100644 --- a/test/harness/testOptions.js +++ b/test/harness/testOptions.js @@ -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); diff --git a/test/jest/coverage.js b/test/jest/coverage.js index 5a5811fceb..14a176a7be 100644 --- a/test/jest/coverage.js +++ b/test/jest/coverage.js @@ -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 => { diff --git a/test/jest/playwrightEnvironment.js b/test/jest/playwrightEnvironment.js index 9930d3fe6f..e76a4c8098 100644 --- a/test/jest/playwrightEnvironment.js +++ b/test/jest/playwrightEnvironment.js @@ -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); }); diff --git a/utils/doclint/cli.js b/utils/doclint/cli.js index a604677aaf..d20de1a4d4 100755 --- a/utils/doclint/cli.js +++ b/utils/doclint/cli.js @@ -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} */ 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(); diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js index ee42112b6d..943e41f098 100644 --- a/utils/generate_types/index.js +++ b/utils/generate_types/index.js @@ -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();