Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): session utility #521

Merged
merged 44 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
289e6ce
feat: session utility
goosewobbler Apr 9, 2024
c291e26
test: add platform switching for appBinaryPath
goosewobbler Apr 9, 2024
6a9acf0
test: add version check, fix path
goosewobbler Apr 9, 2024
db9dff0
test: exit process
goosewobbler Apr 9, 2024
d1faa3a
test: update Mac path
goosewobbler Apr 9, 2024
c86ef82
test: extract binary path construction, use process from import
goosewobbler Apr 9, 2024
f2af201
refactor: rework CJS for session
goosewobbler Apr 9, 2024
ced35e6
test: standardise multiremote and standalone e2es across examples
goosewobbler Apr 9, 2024
80c5b4f
fix: more CJS issues
goosewobbler Apr 9, 2024
d65b736
test: fix package names
goosewobbler Apr 9, 2024
ac2270c
fix: add env var to standalone scripts
goosewobbler Apr 9, 2024
741e074
chore: update linting conf
goosewobbler Apr 9, 2024
1ffc656
test: fix EB binary path
goosewobbler Apr 9, 2024
5fffdfd
test: quit app after standalone e2es
goosewobbler Apr 10, 2024
cc4c3cd
test: restrict `app.quit` to mac
goosewobbler Apr 10, 2024
27664c6
refactor: remove unnecessary spread
goosewobbler Apr 10, 2024
4df340d
test: close app but exempt linux CI
goosewobbler Apr 30, 2024
d14a742
Merge remote-tracking branch 'origin/main' into sm/standalone-utility
goosewobbler Apr 30, 2024
4b9e769
Merge remote-tracking branch 'origin/main' into sm/standalone-utility
goosewobbler Apr 30, 2024
ed8e155
refactor: rename `startSession` => `startElectron`
goosewobbler May 1, 2024
af18718
chore: remove bundling for main in ESM examples
goosewobbler May 1, 2024
e2456f4
refactor: use tsx
goosewobbler May 1, 2024
3d68ab3
refactor: rearrange imports, remove log
goosewobbler May 1, 2024
961fca4
chore: update deps
goosewobbler May 1, 2024
f609025
chore: downgrade `eslint`
goosewobbler May 1, 2024
4538597
chore: update pnpm
goosewobbler May 1, 2024
ab461ee
chore: downgrade `electron-builder`
goosewobbler May 1, 2024
dba31ee
chore: update node
goosewobbler May 1, 2024
6ff4714
debug: test EB first
goosewobbler May 1, 2024
f549f3a
chore: delete symlink
goosewobbler May 1, 2024
aa85bd2
chore: replace symlink
goosewobbler May 1, 2024
69fe5aa
ci: update actions
goosewobbler May 1, 2024
960d937
chore: pin EB @ 24.13.0
goosewobbler May 1, 2024
bbfce62
chore: update e2e exec order
goosewobbler May 1, 2024
a00549b
chore: add comment
goosewobbler May 1, 2024
62accf5
Merge remote-tracking branch 'origin/main' into sm/standalone-utility
goosewobbler May 1, 2024
ddfba65
test: exempt CI completely from app.quit
goosewobbler May 1, 2024
409bb10
test: add units
goosewobbler May 1, 2024
1843726
docs: add standalone mode
goosewobbler May 2, 2024
5416d40
chore: downgrade electron
goosewobbler May 2, 2024
185f226
chore: update comments
goosewobbler May 2, 2024
5a2903a
docs: reference standalone mode in main readme
goosewobbler May 2, 2024
e3c7cff
debug: browser.deleteSession
goosewobbler May 2, 2024
b3447b3
refactor: use browser.deleteSession, remove CI guard
goosewobbler May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache pnpm modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
with:
version: 8.10.0
version: 9.0.6
run_install: false
- name: Run headless test
uses: coactions/[email protected]
with:
run: pnpm run ci
- name: Run Tests
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
xvfb-run pnpm run ci
else
pnpm run ci
fi
shell: bash
- name: 🐛 Debug Build
uses: stateful/vscode-server-action@v1
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/expense.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
authorize:
runs-on: ubuntu-latest
steps:
- uses: octokit/request-action@v2.1.9
- uses: octokit/request-action@v2.x
with:
route: GET /orgs/:organisation/teams/:team/memberships/${{ github.actor }}
team: technical-steering-committee
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: 'main'
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16.x
- uses: pnpm/action-setup@v2
node-version: 18.x
- uses: pnpm/action-setup@v3
with:
version: 8.10.0
version: 9.0.6
goosewobbler marked this conversation as resolved.
Show resolved Hide resolved
run_install: false
- name: NPM Setup
run: |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const config = {
**[Chromedriver Configuration](./docs/configuration/chromedriver-configuration.md)** \
**[Accessing Electron APIs](./docs/electron-apis/accessing-apis.md)** \
**[Mocking Electron APIs](./docs/electron-apis/mocking-apis.md)** \
**[Standalone Mode](./docs/standalone-mode.md)** \
**[Development](./docs/development.md)** \
**[Common Issues](./docs/common-issues.md)**

Expand Down
16 changes: 16 additions & 0 deletions docs/standalone-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Standalone Mode

You can also use the service without the WDIO testrunner, e.g. in a normal Node.js script.

The `startElectron` method accepts [`ElectronServiceOptions`](./configuration/service-configuration.md#service-options), creates a new WDIO session using your configuration and returns the WebdriverIO browser object:

```TS
import { startElectron } from 'wdio-electron-service';

const browser = await startElectron({
appBinaryPath: '/path/to/binary',
appArgs: ['foo', 'bar=baz'],
});

const appName = await browser.electron.execute((electron) => electron.app.getName());
```
22 changes: 22 additions & 0 deletions example-cjs/e2e-multiremote/api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { browser } from 'wdio-electron-service';
import { multiremotebrowser, expect } from '@wdio/globals';

const { name, version } = globalThis.packageJson;

describe('Electron APIs using Multiremote', () => {
it('should retrieve app metadata through the electron API', async () => {
const appName = await browser.electron.execute((electron) => electron.app.getName());
expect(appName).toStrictEqual([name, name]);
const appVersion = await browser.electron.execute((electron) => electron.app.getVersion());
expect(appVersion).toStrictEqual([version, version]);
});

it('should retrieve instance-specific values from a single instance', async () => {
const browserA = multiremotebrowser.getInstance('browserA');
expect(await browserA.electron.execute(() => process.argv.includes('--browser=A'))).toBe(true);
expect(await browserA.electron.execute(() => process.argv.includes('--browser=B'))).toBe(false);
const browserB = multiremotebrowser.getInstance('browserB');
expect(await browserB.electron.execute(() => process.argv.includes('--browser=A'))).toBe(false);
expect(await browserB.electron.execute(() => process.argv.includes('--browser=B'))).toBe(true);
});
});
50 changes: 50 additions & 0 deletions example-cjs/e2e-standalone/api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'node:path';
import fs from 'node:fs';
import process from 'node:process';

import { startElectron } from 'wdio-electron-service';
import type { PackageJson } from 'read-package-up';

process.env.TEST = 'true';

const PACKAGE_NAME = 'wdio-electron-service-example-cjs';
const packageJson = JSON.parse(
fs.readFileSync(path.join(__dirname, '..', 'package.json'), { encoding: 'utf-8' }),
) as PackageJson;

const getBinaryExtension = () => {
if (process.platform === 'darwin') {
return `.app/Contents/MacOS/${PACKAGE_NAME}`;
} else if (process.platform === 'win32') {
return '.exe';
}

return '';
};

const getBinaryPath = () =>
`./out/${PACKAGE_NAME}-${process.platform}-${process.arch}/${PACKAGE_NAME}${getBinaryExtension()}`;

async function init() {
const browser = await startElectron({
appBinaryPath: getBinaryPath(),
appArgs: ['foo', 'bar=baz'],
});

const appName = await browser.electron.execute((electron) => electron.app.getName());
if (appName !== packageJson.name) {
throw new Error(`appName test failed: ${appName} !== ${packageJson.name}`);
}

const appVersion = await browser.electron.execute((electron) => electron.app.getVersion());
if (appVersion !== packageJson.version) {
throw new Error(`appVersion test failed: ${appVersion} !== ${packageJson.version}`);
}

// Clean up - quit the app
await browser.deleteSession();

process.exit();
}

init();
7 changes: 5 additions & 2 deletions example-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"ci": "pnpm i && pnpm build && pnpm test",
"clean": "pnpm clean:dist && rm -rf ./node_modules pnpm-lock.yaml ./wdio-logs ./out",
"clean:dist": "pnpx rimraf ./dist && mkdir -p ./dist",
"test": "wdio run ./wdio.conf.ts"
"test": "wdio run ./wdio.conf.ts && pnpm test:multiremote && pnpm test:standalone",
"test:multiremote": "wdio run ./wdio.multiremote.conf.ts",
"test:standalone": "tsx ./e2e-standalone/api.spec.ts"
},
"dependencies": {
"wdio-electron-service": "file:../"
Expand All @@ -21,11 +23,12 @@
"@wdio/globals": "^8.27.2",
"@wdio/local-runner": "^8.27.2",
"@wdio/mocha-framework": "^8.27.2",
"electron": "^29.0.1",
"electron": "^29.3.1",
"global-jsdom": "^24.0.0",
"jsdom": "^24.0.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tsx": "^4.8.2",
"typescript": "^5.3.2",
"webdriverio": "^8.27.2"
},
Expand Down
Loading
Loading