Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(electron): fix electron types, move source to src/server/electron (#3583)

Dmitry Gozman77f803140a63
diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index 9ae5af9dd5..0000000000
--- a/.npmignore
+++ /dev/null
@@ -1,29 +0,0 @@
-# NOTE: .npmignore is copied over to every subpackage in //packages when NPM packages
-# are built.
-#
-# this ignores everything by default, except for package.json and LICENSE and README.md
-# see https://docs.npmjs.com/misc/developers
-**/*
-
-# include sources from lib except for injected, but not map files
-!lib/**/*.js
-# Include Windows dependency checker executable.
-!bin/PrintDeps.exe
-# Injected files are included via lib/generated, see src/injected/README.md
-lib/injected/
-#types
-!types/*
-!index.d.ts
-!electron-types.d.ts
-
-!index.js
-!index.mjs
-!install.js
-!README.md
-!LICENSE
-!NOTICE
-!api.md
-!protocol.yml
-
-# browser descriptor
-!browsers.json
diff --git a/index.js b/index.js
index f7247b83ed..8785e3336c 100644
--- a/index.js
+++ b/index.js
@@ -15,7 +15,7 @@
*/
const { Playwright } = require('./lib/server/playwright');
-const { Electron } = require('./lib/server/electron');
+const { Electron } = require('./lib/server/electron/electron');
const { setupInProcess } = require('./lib/rpc/inprocess');
const path = require('path');
diff --git a/packages/build_package.js b/packages/build_package.js
index da442f93f5..4c414f5675 100755
--- a/packages/build_package.js
+++ b/packages/build_package.js
@@ -28,7 +28,7 @@ const cpAsync = util.promisify(ncp);
const SCRIPT_NAME = path.basename(__filename);
const ROOT_PATH = path.join(__dirname, '..');
-const PLAYWRIGHT_CORE_FILES = ['bin', 'lib', 'types', 'NOTICE', 'LICENSE', '.npmignore'];
+const PLAYWRIGHT_CORE_FILES = ['bin', 'lib', 'types', 'NOTICE', 'LICENSE'];
const PACKAGES = {
'playwright': {
@@ -61,7 +61,7 @@ const PACKAGES = {
version: '0.4.0', // Manually manage playwright-electron version.
description: 'A high-level API to automate Electron',
browsers: [],
- files: PLAYWRIGHT_CORE_FILES,
+ files: [...PLAYWRIGHT_CORE_FILES, 'electron-types.d.ts'],
},
};
diff --git a/packages/common/.npmignore b/packages/common/.npmignore
new file mode 100644
index 0000000000..2b3d1f3193
--- /dev/null
+++ b/packages/common/.npmignore
@@ -0,0 +1,35 @@
+# NOTE: theoretically, we can remove this file, because we always create
+# a directory for each package and only copy necessary files there.
+# However, we keep it to double check the list of files.
+#
+# This ignores everything by default, except for package.json and LICENSE and README.md.
+# See https://docs.npmjs.com/misc/developers
+**/*
+
+# Include sources from lib, but not map files.
+!lib/**/*.js
+# Exclude injected files. A preprocessed version of these is included via lib/generated.
+# See src/injected/README.md.
+lib/injected/
+# Include Windows dependency checker executable.
+!bin/PrintDeps.exe
+# Include generated types and entrypoint.
+!types/*
+!index.d.ts
+# Include separate electron types.
+!electron-types.d.ts
+# Include main entrypoint.
+!index.js
+# Include main entrypoint for ES Modules.
+!index.mjs
+# Include installer.
+!install.js
+# Include essentials.
+!README.md
+!LICENSE
+!NOTICE
+# Include protocol and api docs, so that dependent packages can consume them.
+!api.md
+!protocol.yml
+# Include browser descriptors.
+!browsers.json
diff --git a/packages/installation-tests/installation-tests.sh b/packages/installation-tests/installation-tests.sh
index 46e3fe1a34..8ac512c667 100755
--- a/packages/installation-tests/installation-tests.sh
+++ b/packages/installation-tests/installation-tests.sh
@@ -49,6 +49,7 @@ function run_tests {
test_playwright_global_installation
test_playwright_global_installation_cross_package
test_playwright_electron_should_work
+ test_electron_types
}
function test_typescript_types {
@@ -241,6 +242,16 @@ function test_playwright_electron_should_work {
xvfb-run --auto-servernum -- bash -c "node sanity-electron.js"
}
+function test_electron_types {
+ initialize_test "${FUNCNAME[0]}"
+ npm install ${PLAYWRIGHT_ELECTRON_TGZ}
+ npm install [email protected]
+ npm install -D [email protected]
+ npm install -D @types/[email protected]
+ echo "import { Page, electron, ElectronApplication, ElectronLauncher } from 'playwright-electron';" > "test.ts"
+ npx tsc "test.ts"
+}
+
function initialize_test {
cd ${TEST_ROOT}
local TEST_NAME="./$1"
diff --git a/packages/playwright-electron/index.d.ts b/packages/playwright-electron/index.d.ts
index 00db14cfe8..96b8d85a39 100644
--- a/packages/playwright-electron/index.d.ts
+++ b/packages/playwright-electron/index.d.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { ElectronLauncher } from 'playwright-core/electron-types';
-export * from 'playwright-core/types/types';
-export * from 'playwright-core/electron-types';
+import { ElectronLauncher } from './electron-types';
+export * from './types/types';
+export * from './electron-types';
export const electron: ElectronLauncher;
diff --git a/packages/playwright-electron/index.js b/packages/playwright-electron/index.js
index ab8f673350..8d3ff68d5a 100644
--- a/packages/playwright-electron/index.js
+++ b/packages/playwright-electron/index.js
@@ -15,7 +15,7 @@
*/
const { Playwright } = require('./lib/server/playwright');
-const { Electron } = require('./lib/server/electron');
+const { Electron } = require('./lib/server/electron/electron');
const { setupInProcess } = require('./lib/rpc/inprocess');
const playwright = new Playwright(__dirname, require('./browsers.json')['browsers']);
diff --git a/src/rpc/server.ts b/src/rpc/server.ts
index 8ac606cc5d..05949e08f6 100644
--- a/src/rpc/server.ts
+++ b/src/rpc/server.ts
@@ -18,7 +18,7 @@ import { Transport } from '../protocol/transport';
import { DispatcherConnection } from './server/dispatcher';
import { Playwright } from '../server/playwright';
import { PlaywrightDispatcher } from './server/playwrightDispatcher';
-import { Electron } from '../server/electron';
+import { Electron } from '../server/electron/electron';
import { gracefullyCloseAll } from '../server/processLauncher';
const dispatcherConnection = new DispatcherConnection();
diff --git a/src/rpc/server/electronDispatcher.ts b/src/rpc/server/electronDispatcher.ts
index ce1e0f2ce6..27d30496c3 100644
--- a/src/rpc/server/electronDispatcher.ts
+++ b/src/rpc/server/electronDispatcher.ts
@@ -15,7 +15,7 @@
*/
import { Dispatcher, DispatcherScope, lookupDispatcher } from './dispatcher';
-import { Electron, ElectronApplication, ElectronPage } from '../../server/electron';
+import { Electron, ElectronApplication, ElectronPage } from '../../server/electron/electron';
import * as channels from '../../protocol/channels';
import { BrowserContextDispatcher } from './browserContextDispatcher';
import { PageDispatcher } from './pageDispatcher';
diff --git a/src/rpc/server/playwrightDispatcher.ts b/src/rpc/server/playwrightDispatcher.ts
index c28a211213..40c6e963e8 100644
--- a/src/rpc/server/playwrightDispatcher.ts
+++ b/src/rpc/server/playwrightDispatcher.ts
@@ -19,7 +19,7 @@ import * as channels from '../../protocol/channels';
import { BrowserTypeDispatcher } from './browserTypeDispatcher';
import { Dispatcher, DispatcherScope } from './dispatcher';
import { SelectorsDispatcher } from './selectorsDispatcher';
-import { Electron } from '../../server/electron';
+import { Electron } from '../../server/electron/electron';
import { ElectronDispatcher } from './electronDispatcher';
import { DeviceDescriptors } from '../../deviceDescriptors';
diff --git a/src/server/electron.ts b/src/server/electron/electron.ts
similarity index 90%
rename from src/server/electron.ts
rename to src/server/electron/electron.ts
index dab8e212ad..96a99aa9f4 100644
--- a/src/server/electron.ts
+++ b/src/server/electron/electron.ts
@@ -15,21 +15,21 @@
*/
import * as path from 'path';
-import { CRBrowser, CRBrowserContext } from './chromium/crBrowser';
-import { CRConnection, CRSession } from './chromium/crConnection';
-import { CRExecutionContext } from './chromium/crExecutionContext';
-import * as js from '../javascript';
-import { Page } from '../page';
-import { TimeoutSettings } from '../utils/timeoutSettings';
-import { WebSocketTransport } from '../transport';
-import * as types from '../types';
-import { launchProcess, waitForLine, envArrayToObject } from './processLauncher';
-import { BrowserContext } from '../browserContext';
+import { CRBrowser, CRBrowserContext } from '../chromium/crBrowser';
+import { CRConnection, CRSession } from '../chromium/crConnection';
+import { CRExecutionContext } from '../chromium/crExecutionContext';
+import * as js from '../../javascript';
+import { Page } from '../../page';
+import { TimeoutSettings } from '../../utils/timeoutSettings';
+import { WebSocketTransport } from '../../transport';
+import * as types from '../../types';
+import { launchProcess, waitForLine, envArrayToObject } from '../processLauncher';
+import { BrowserContext } from '../../browserContext';
import type {BrowserWindow} from 'electron';
-import { runAbortableTask, ProgressController } from '../progress';
+import { runAbortableTask, ProgressController } from '../../progress';
import { EventEmitter } from 'events';
-import { helper } from '../helper';
-import { BrowserProcess } from '../browser';
+import { helper } from '../../helper';
+import { BrowserProcess } from '../../browser';
export type ElectronLaunchOptionsBase = {
args?: string[],
diff --git a/src/server/electronLoader.ts b/src/server/electron/electronLoader.ts
similarity index 100%
rename from src/server/electronLoader.ts
rename to src/server/electron/electronLoader.ts