Skip to content

Commit

Permalink
feat: support both options and capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
goosewobbler committed Dec 11, 2024
1 parent e9fa007 commit d38e1f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/wdio-electron-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export default class ElectronWorkerService implements Services.ServiceInstance {
}

async before(
_capabilities: WebdriverIO.Capabilities,
capabilities: WebdriverIO.Capabilities,
_specs: string[],
instance: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
): Promise<void> {
const browser = instance as WebdriverIO.Browser;
const { clearMocks, resetMocks, restoreMocks } = this.#globalOptions;
const { clearMocks, resetMocks, restoreMocks } = this.#globalOptions || capabilities[CUSTOM_CAPABILITY_NAME];

this.#clearMocks = clearMocks ?? false;
this.#resetMocks = resetMocks ?? false;
Expand Down
38 changes: 38 additions & 0 deletions packages/wdio-electron-service/test/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,44 @@ describe('beforeTest', () => {

expect(restoreAllMocks).toHaveBeenCalled();
});

describe('when setting options in capabilities', () => {
it('should clear all mocks when `clearMocks` is set in capabilities', async () => {
instance = new WorkerService();
const browser = {
waitUntil: vi.fn().mockResolvedValue(true),
execute: vi.fn().mockResolvedValue(true),
} as unknown as WebdriverIO.Browser;
await instance.before({ 'wdio:electronServiceOptions': { clearMocks: true } }, [], browser);
await instance.beforeTest();

expect(clearAllMocks).toHaveBeenCalled();
});

it('should reset all mocks when `resetMocks` is set in capabilities', async () => {
instance = new WorkerService();
const browser = {
waitUntil: vi.fn().mockResolvedValue(true),
execute: vi.fn().mockResolvedValue(true),
} as unknown as WebdriverIO.Browser;
await instance.before({ 'wdio:electronServiceOptions': { resetMocks: true } }, [], browser);
await instance.beforeTest();

expect(resetAllMocks).toHaveBeenCalled();
});

it('should restore all mocks when `restoreMocks` is set in capabilities', async () => {
instance = new WorkerService();
const browser = {
waitUntil: vi.fn().mockResolvedValue(true),
execute: vi.fn().mockResolvedValue(true),
} as unknown as WebdriverIO.Browser;
await instance.before({ 'wdio:electronServiceOptions': { restoreMocks: true } }, [], browser);
await instance.beforeTest();

expect(restoreAllMocks).toHaveBeenCalled();
});
});
});

describe('afterCommand', () => {
Expand Down

0 comments on commit d38e1f1

Please sign in to comment.