-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add sanity test for playwright-electron (#3387)
- Loading branch information
Showing
4 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters