Skip to content

Commit

Permalink
test: add sanity test for playwright-electron (#3387)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Aug 12, 2020
1 parent adfeaa4 commit 3a6b5ca
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/installation-tests/electron-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { app } = require('electron');

app.on('window-all-closed', e => e.preventDefault());
13 changes: 13 additions & 0 deletions packages/installation-tests/installation-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 [email protected]
copy_test_scripts
xvfb-run --auto-servernum -- bash -c "node sanity-electron.js"
}

function initialize_test {
cd ${TEST_ROOT}
local TEST_NAME="./$1"
Expand Down
34 changes: 34 additions & 0 deletions packages/installation-tests/sanity-electron.js
Original file line number Diff line number Diff line change
@@ -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);
});
4 changes: 2 additions & 2 deletions packages/playwright-electron/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit 3a6b5ca

Please sign in to comment.