import { describe, expect, it, vi, beforeEach } from 'vitest'
import WDIORunner from '../src/index.js'
import type BaseReporter from '../src/reporter.js'
import type { Options } from '@wdio/types'
vi.mock('../src/utils', () => ({
__esModule: true,
initializeInstance() {
return {
'$'() { },
'$$'() { },
sessionId: 'id',
isBar: false,
events: {},
on (eventName: string, callback: Function) {
this.events[eventName] = callback
}
}
}
}))
const config: Options.WebdriverIO = { capabilities: {} }
const capability: WebdriverIO.Capabilities = { browserName: 'foo' }
describe('wdio-runner', () => {
describe('_initSession', () => {
let runner: WDIORunner
beforeEach(() => {
runner = new WDIORunner()
runner['_reporter'] = {
emit: vi.fn()
} as unknown as BaseReporter
})
it('command event', async () => {
const browser = await runner['_initSession'](config, capability)
const command = { foo: 'bar' }
browser.events.command(command)
expect(command).toEqual({ foo: 'bar', sessionId: 'id' })
})
it('result event', async () => {
const browser = await runner['_initSession'](config, capability)
const result = { bar: 'foo' }
browser.events.result(result)
expect(result).toEqual({ bar: 'foo', sessionId: 'id' })
})
})
})