Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-playwright-helpers

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-playwright-helpers - npm Package Compare versions

Comparing version 1.4.1 to 1.5.1

33

dist/find_parse_builds.d.ts
/**
* Parses the `out` directory to find the latest build of your Electron project.
* Use `npm run package` (or similar) to build your app prior to testing.
*
* Assumptions: We assume that your build will be in the `out` directory, and that
* the build directory will be named with a hyphen-delimited platform name, e.g.
* `out/my-app-win-x64`. If your build directory is not `out`, you can
* pass the name of the directory as the `buildDirectory` parameter. If your
* build directory is not named with a hyphen-delimited platform name, this
* function will not work. However, you can pass the build path into
* `parseElectronApp()` directly.
*
* @see parseElectronApp
*
* @param buildDirectory {string} - optional - the directory to search for the latest build

@@ -10,2 +21,20 @@ * (path/name relative to package root or full path starting with /). Defaults to `out`.

type Architecture = 'x64' | 'x32' | 'arm64' | undefined;
export interface PackageJson {
[key: string]: unknown;
name: string;
productName?: string;
main: string;
version: string;
description?: string;
author?: string | {
name: string;
email: string;
};
license?: string;
repository?: string;
homepage?: string;
bugs?: string | {
url: string;
};
}
/**

@@ -21,2 +50,3 @@ * Format of the data returned from `parseElectronApp()`

* @prop {string} arch - 'x64', 'x32', or 'arm64'
* @prop {PackageJson} packageJson - the `JSON.parse()`'d contents of the package.json file.
*/

@@ -38,2 +68,4 @@ export interface ElectronAppInfo {

arch: Architecture;
/** The JSON.parse()'d contents of the package.json file. */
packageJson: PackageJson;
}

@@ -54,2 +86,3 @@ /**

* - arch: architecture
* - packageJson: the JSON.parse()'d contents of the package.json file.
*

@@ -56,0 +89,0 @@ * @param buildDir {string} - absolute path to the build directory or the app itself

93

dist/find_parse_builds.js

@@ -36,2 +36,13 @@ "use strict";

* Use `npm run package` (or similar) to build your app prior to testing.
*
* Assumptions: We assume that your build will be in the `out` directory, and that
* the build directory will be named with a hyphen-delimited platform name, e.g.
* `out/my-app-win-x64`. If your build directory is not `out`, you can
* pass the name of the directory as the `buildDirectory` parameter. If your
* build directory is not named with a hyphen-delimited platform name, this
* function will not work. However, you can pass the build path into
* `parseElectronApp()` directly.
*
* @see parseElectronApp
*
* @param buildDirectory {string} - optional - the directory to search for the latest build

@@ -60,2 +71,3 @@ * (path/name relative to package root or full path starting with /). Defaults to `out`.

'ubuntu',
'debian',
];

@@ -94,13 +106,2 @@ const latestBuild = builds

/**
* Given baseName, extract linux executable name.
* Can't depend on .app, or .exe being in the name.
* Assume baseName format is <appName>-<platform>-<arch>
* @private
*/
function getLinuxExecutableName(baseName) {
const tokens = baseName.split('-');
const result = tokens.slice(0, tokens.length - 2).join('-');
return result;
}
/**
* Given a directory containing an Electron app build,

@@ -119,2 +120,3 @@ * or the path to the app itself (directory on Mac, executable on Windows),

* - arch: architecture
* - packageJson: the JSON.parse()'d contents of the package.json file.
*

@@ -125,4 +127,4 @@ * @param buildDir {string} - absolute path to the build directory or the app itself

function parseElectronApp(buildDir) {
console.log(`Parsing Electron app in ${buildDir}`);
let platform = '';
// The platform of the app
let platform;
// in case the buildDir is the path to the app itself

@@ -133,6 +135,9 @@ if (buildDir.endsWith('.app')) {

}
if (buildDir.endsWith('.exe')) {
else if (buildDir.endsWith('.exe')) {
buildDir = path_1.default.dirname(buildDir);
platform = 'win32';
}
else {
// equivalent for Linux?
}
// The name of the build directory CONVERTED TO LOWERCASE

@@ -174,2 +179,3 @@ const baseNameLc = path_1.default.basename(buildDir).toLowerCase();

let resourcesDir;
let packageJson;
if (platform === 'darwin') {

@@ -204,3 +210,2 @@ // MacOS Structure

asar = resourcesList.includes('app.asar');
let packageJson;
if (asar) {

@@ -227,2 +232,3 @@ const asarPath = path_1.default.join(resourcesDir, 'app.asar');

const list = fs_1.default.readdirSync(buildDir);
// !! assume the executable is the only .exe file in the directory
const exe = list.find((fileName) => {

@@ -238,3 +244,2 @@ return fileName.endsWith('.exe');

asar = resourcesList.includes('app.asar');
let packageJson;
if (asar) {

@@ -260,7 +265,57 @@ const asarPath = path_1.default.join(resourcesDir, 'app.asar');

// (your app structure)
executable = path_1.default.join(buildDir, getLinuxExecutableName(path_1.default.basename(buildDir)));
const list = fs_1.default.readdirSync(buildDir);
const exeCandidates = list.filter((fileName) => {
// Assume the executable is the only file in the directory that...
// ...does not have one of these suffixes
const ignoreSuffixes = [
'.so',
'.so.1',
'.so.2',
'.bin',
'.pak',
'.dat',
'.json',
];
// ...does not have one of these names
const ignoreNames = ['resources', 'locales', 'version', 'LICENSE'];
// ...does not start with one of these names
const ignoreStartsWith = ['chrome-', 'chrome_', 'lib', 'LICENSE'];
if (ignoreSuffixes.some((suffix) => fileName.endsWith(suffix))) {
return false;
}
if (ignoreNames.some((name) => fileName === name)) {
return false;
}
if (ignoreStartsWith.some((name) => fileName.startsWith(name))) {
return false;
}
const filePath = path_1.default.join(buildDir, fileName);
const stats = fs_1.default.statSync(filePath);
// ...is not a directory
if (stats.isDirectory()) {
return false;
}
// ...is not a symlink
if (stats.isSymbolicLink()) {
return false;
}
// ...is executable
try {
fs_1.default.accessSync(filePath, fs_1.default.constants.X_OK);
return true;
}
catch (err) {
return false;
}
});
if (exeCandidates.length > 1) {
console.warn(`Found ${exeCandidates.length} executable files in ${buildDir}. Will use the first: ${exeCandidates[0]}. If this is not the correct executable, please file an issue at https://github.com/spaceagetv/electron-playwright-helpers/issues`);
}
if (exeCandidates.length < 1) {
throw new Error(`Could not find executable file in ${buildDir}. Please check your build directory. If file exists, please make sure it is executable. If file is executable, please file an issue at https://github.com/spaceagetv/electron-playwright-helpers/issues`);
}
executable = path_1.default.join(buildDir, exeCandidates[0]);
resourcesDir = path_1.default.join(buildDir, 'resources');
const resourcesList = fs_1.default.readdirSync(resourcesDir);
asar = resourcesList.includes('app.asar');
let packageJson;
if (asar) {

@@ -280,2 +335,3 @@ const asarPath = path_1.default.join(resourcesDir, 'app.asar');

}
// get the name field from package.json
name = packageJson.name;

@@ -294,2 +350,3 @@ }

arch,
packageJson,
};

@@ -296,0 +353,0 @@ }

5

package.json
{
"name": "electron-playwright-helpers",
"version": "1.4.1",
"version": "1.5.1",
"description": "Helper functions for Electron end-to-end testing using Playwright",

@@ -38,2 +38,5 @@ "main": "./dist/index.js",

"@babel/preset-typescript": "^7.18.6",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@tsconfig/node12": "^1.0.11",

@@ -40,0 +43,0 @@ "@typescript-eslint/eslint-plugin": "^5.48.1",

@@ -87,3 +87,10 @@ # Electron Playwright Helpers

<dd><p>Parses the <code>out</code> directory to find the latest build of your Electron project.
Use <code>npm run package</code> (or similar) to build your app prior to testing.</p></dd>
Use <code>npm run package</code> (or similar) to build your app prior to testing.</p>
<p>Assumptions: We assume that your build will be in the <code>out</code> directory, and that
the build directory will be named with a hyphen-delimited platform name, e.g.
<code>out/my-app-win-x64</code>. If your build directory is not <code>out</code>, you can
pass the name of the directory as the <code>buildDirectory</code> parameter. If your
build directory is not named with a hyphen-delimited platform name, this
function will not work. However, you can pass the build path into
<code>parseElectronApp()</code> directly.</p></dd>
<dt><a href="#parseElectronApp">parseElectronApp(buildDir)</a> ⇒ <code>ElectronAppInfo</code></dt>

@@ -103,2 +110,3 @@ <dd><p>Given a directory containing an Electron app build,

<li>arch: architecture</li>
<li>packageJson: the JSON.parse()'d contents of the package.json file.</li>
</ul></dd>

@@ -200,2 +208,9 @@ <dt><a href="#electronWaitForFunction">electronWaitForFunction(electronApp, fn, arg)</a> ⇒ <code>Promise.&lt;void&gt;</code></dt>

Use <code>npm run package</code> (or similar) to build your app prior to testing.</p>
<p>Assumptions: We assume that your build will be in the <code>out</code> directory, and that
the build directory will be named with a hyphen-delimited platform name, e.g.
<code>out/my-app-win-x64</code>. If your build directory is not <code>out</code>, you can
pass the name of the directory as the <code>buildDirectory</code> parameter. If your
build directory is not named with a hyphen-delimited platform name, this
function will not work. However, you can pass the build path into
<code>parseElectronApp()</code> directly.</p>

@@ -206,2 +221,3 @@ **Kind**: global function

</ul>
**See**: parseElectronApp

@@ -228,2 +244,3 @@ | Param | Type | Default | Description |

<li>arch: architecture</li>
<li>packageJson: the JSON.parse()'d contents of the package.json file.</li>
</ul>

@@ -230,0 +247,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc