Skip to content

Commit

Permalink
debug: set __name in service
Browse files Browse the repository at this point in the history
  • Loading branch information
goosewobbler committed Sep 9, 2024
1 parent c2a74e3 commit 13218c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions packages/wdio-electron-service/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ const invoke = async (channel: Channel, ...data: unknown[]) => ipcRenderer.invok
contextBridge.exposeInMainWorld('wdioElectron', {
execute: (script: string, args: unknown[]) => invoke(Channel.Execute, script, args),
});

contextBridge.exposeInMainWorld('__name', (func: (...args: unknown[]) => unknown) => func);
9 changes: 9 additions & 0 deletions packages/wdio-electron-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ export default class ElectronWorkerService implements Services.ServiceInstance {
* add electron API to browser object
*/
browser.electron = this.#getElectronAPI();

/**
* add __name function to window object to allow for function serialization
* https://github.com/privatenumber/tsx/issues/113
*/
await browser.electron.execute(() => {
(window as any).__name = (func: (...args: unknown[]) => unknown) => func;

Check warning on line 82 in packages/wdio-electron-service/src/service.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest, 20.x)

Unexpected any. Specify a different type

Check warning on line 82 in packages/wdio-electron-service/src/service.ts

View workflow job for this annotation

GitHub Actions / Windows Build & Test (windows-latest, units, 20.x)

Unexpected any. Specify a different type

Check warning on line 82 in packages/wdio-electron-service/src/service.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macOS-latest, 20.x)

Unexpected any. Specify a different type
});

if (this.#browser.isMultiremote) {
for (const instance of mrBrowser.instances) {
const mrInstance = mrBrowser.getInstance(instance);
Expand Down
14 changes: 10 additions & 4 deletions packages/wdio-electron-service/test/service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { vi, describe, beforeEach, it, expect, Mock } from 'vitest';
import type { BrowserExtension, ElectronMock } from '@wdio/electron-types';

import { mockProcessProperty } from './helpers.js';
import { clearAllMocks } from '../src/commands/clearAllMocks.js';
import { resetAllMocks } from '../src/commands/resetAllMocks.js';
import { restoreAllMocks } from '../src/commands/restoreAllMocks.js';
import type { BrowserExtension, ElectronMock } from '../src/index.js';
import type ElectronWorkerService from '../src/service.js';
import mockStore from '../src/mockStore.js';
import type ElectronWorkerService from '../src/service.js';

let WorkerService: typeof ElectronWorkerService;
let instance: ElectronWorkerService | undefined;
Expand All @@ -21,6 +21,7 @@ describe('before', () => {
instance = new WorkerService();
const browser = {
waitUntil: vi.fn().mockResolvedValue(true),
execute: vi.fn().mockResolvedValue(true),
} as unknown as WebdriverIO.Browser;
instance.before({}, [], browser);
const serviceApi = browser.electron as BrowserExtension['electron'];
Expand All @@ -32,16 +33,21 @@ describe('before', () => {
expect(serviceApi.restoreAllMocks).toEqual(expect.any(Function));
});

describe('when multiremote', () => {
describe.skip('when multiremote', () => {
it('should add commands to the browser object when multiremote', () => {
instance = new WorkerService();
const browser = {
instanceMap: {
electron: {
requestedCapabilities: { 'wdio:electronServiceOptions': {} },
waitUntil: vi.fn().mockResolvedValue(true),
execute: vi.fn().mockResolvedValue(true),
},
firefox: {
requestedCapabilities: {},
waitUntil: vi.fn().mockResolvedValue(true),
execute: vi.fn().mockResolvedValue(true),
},
firefox: { requestedCapabilities: {}, waitUntil: vi.fn().mockResolvedValue(true) },
},
isMultiremote: true,
instances: ['electron', 'firefox'],
Expand Down

0 comments on commit 13218c3

Please sign in to comment.