test: add sanity test for playwright-electron (#3387)

This commit is contained in:
Dmitry Gozman 2020-08-12 14:45:22 -07:00 committed by GitHub
parent adfeaa49ed
commit 3a6b5cab42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,3 @@
const { app } = require('electron');
app.on('window-all-closed', e => e.preventDefault());

View File

@ -21,6 +21,7 @@ PLAYWRIGHT_TGZ="$(node ${PACKAGE_BUILDER} playwright ./playwright.tgz)"
PLAYWRIGHT_CHROMIUM_TGZ="$(node ${PACKAGE_BUILDER} playwright-chromium ./playwright-chromium.tgz)"
PLAYWRIGHT_WEBKIT_TGZ="$(node ${PACKAGE_BUILDER} playwright-webkit ./playwright-webkit.tgz)"
PLAYWRIGHT_FIREFOX_TGZ="$(node ${PACKAGE_BUILDER} playwright-firefox ./playwright-firefox.tgz)"
PLAYWRIGHT_ELECTRON_TGZ="$(node ${PACKAGE_BUILDER} playwright-electron ./playwright-electron.tgz)"
SCRIPTS_PATH="$(pwd -P)/.."
TEST_ROOT="$(pwd -P)"
@ -33,6 +34,8 @@ function copy_test_scripts {
cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-firefox.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-webkit.mjs" .
cp "${SCRIPTS_PATH}/sanity-electron.js" .
cp "${SCRIPTS_PATH}/electron-app.js" .
}
function run_tests {
@ -45,6 +48,7 @@ function run_tests {
test_playwright_firefox_should_work
test_playwright_global_installation
test_playwright_global_installation_cross_package
test_playwright_electron_should_work
}
function test_typescript_types {
@ -228,6 +232,15 @@ function test_playwright_firefox_should_work {
fi
}
function test_playwright_electron_should_work {
initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_ELECTRON_TGZ}
npm install electron@9.0
copy_test_scripts
xvfb-run --auto-servernum -- bash -c "node sanity-electron.js"
}
function initialize_test {
cd ${TEST_ROOT}
local TEST_NAME="./$1"

View File

@ -0,0 +1,34 @@
/**
* 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.
*/
const playwright = require('playwright-electron');
const path = require('path');
(async () => {
const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron';
const electronPath = path.join(__dirname, 'node_modules', '.bin', electronName);
const application = await playwright.electron.launch(electronPath, {
args: [path.join(__dirname, 'electron-app.js')],
});
const appPath = await application.evaluate(async ({ app }) => app.getAppPath());
await application.close();
if (appPath !== __dirname)
throw new Error(`Malformed app path: got "${appPath}", expected "${__dirname}"`);
console.log(`playwright-electron SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
const { Playwright } = require('playwright-core/lib/server/playwright');
const { Electron } = require('playwright-core/lib/server/electron');
const { Playwright } = require('./lib/server/playwright');
const { Electron } = require('./lib/server/electron');
const { setupInProcess } = require('./lib/rpc/inprocess');
const playwright = new Playwright(__dirname, require('./browsers.json')['browsers']);