rewrite @wdiotestingbot-service to ESM
This commit is contained in:
parent
80337515a4
commit
ccdb85a45b
9 changed files with 71 additions and 42 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { vi } from 'vitest'
|
||||
|
||||
export default (opts: any, cb: any) => {
|
||||
cb(null, {
|
||||
close: jest.fn()
|
||||
close: vi.fn()
|
||||
})
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
"author": "Jochen Delabie <info@testingbot.com>",
|
||||
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-testingbot-service",
|
||||
"license": "MIT",
|
||||
"main": "./build",
|
||||
"engines": {
|
||||
"node": "^16.13 || >=18"
|
||||
},
|
||||
|
|
@ -22,6 +21,20 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/webdriverio/webdriverio/issues"
|
||||
},
|
||||
"main": "./build/index.cjs.js",
|
||||
"type": "module",
|
||||
"module": "./build/index.js",
|
||||
"exports": {
|
||||
".": [
|
||||
{
|
||||
"import": "./build/index.js",
|
||||
"require": "./build/index.cjs.js"
|
||||
},
|
||||
"./build/index.cjs.js"
|
||||
]
|
||||
},
|
||||
"types": "./build/index.d.ts",
|
||||
"typeScriptVersion": "3.8.3",
|
||||
"dependencies": {
|
||||
"@types/node": "^18.0.0",
|
||||
"@wdio/logger": "7.19.0",
|
||||
|
|
@ -35,6 +48,5 @@
|
|||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"types": "./build/index.d.ts"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* istanbul ignore file */
|
||||
|
||||
import TestingBotLauncher from './launcher'
|
||||
import TestingBotService from './service'
|
||||
import { TestingbotOptions } from './types'
|
||||
import TestingBotLauncher from './launcher.js'
|
||||
import TestingBotService from './service.js'
|
||||
import type { TestingbotOptions } from './types'
|
||||
|
||||
export default TestingBotService
|
||||
export const launcher = TestingBotLauncher
|
||||
export * from './types'
|
||||
export * from './types.js'
|
||||
|
||||
declare global {
|
||||
namespace WebdriverIO {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { performance, PerformanceObserver } from 'perf_hooks'
|
||||
import { promisify } from 'util'
|
||||
import { performance, PerformanceObserver } from 'node:perf_hooks'
|
||||
import { promisify } from 'node:util'
|
||||
|
||||
import testingbotTunnel from 'testingbot-tunnel-launcher'
|
||||
import logger from '@wdio/logger'
|
||||
import { Capabilities, Options, Services } from '@wdio/types'
|
||||
|
||||
import { TestingbotOptions, TestingbotTunnel, TunnelLauncherOptions } from './types'
|
||||
import type { TestingbotOptions, TestingbotTunnel, TunnelLauncherOptions } from './types'
|
||||
|
||||
const log = logger('@wdio/testingbot-service')
|
||||
|
||||
|
|
@ -22,7 +22,10 @@ export default class TestingBotLauncher implements Services.ServiceInstance {
|
|||
return
|
||||
}
|
||||
|
||||
const tbTunnelIdentifier = this.options.tbTunnelOpts?.tunnelIdentifier || `TB-tunnel-${Math.random().toString().slice(2)}`
|
||||
const tbTunnelIdentifier = (
|
||||
this.options.tbTunnelOpts?.tunnelIdentifier ||
|
||||
`TB-tunnel-${Math.random().toString().slice(2)}`
|
||||
)
|
||||
|
||||
this.tbTunnelOpts = Object.assign({
|
||||
apiKey: config.user,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import logger from '@wdio/logger'
|
|||
import { Capabilities, Options, Services, Frameworks } from '@wdio/types'
|
||||
import type { Browser, MultiRemoteBrowser } from 'webdriverio'
|
||||
|
||||
import { TestingbotOptions } from './types'
|
||||
import type { TestingbotOptions } from './types'
|
||||
|
||||
const log = logger('@wdio/testingbot-service')
|
||||
const jobDataProperties = ['name', 'tags', 'public', 'build', 'extra']
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
import path from 'node:path'
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||
import logger from '@wdio/logger'
|
||||
import type { Capabilities } from '@wdio/types'
|
||||
|
||||
import TestingBotLauncher from '../src/launcher'
|
||||
import type { TestingbotOptions } from '../src/types'
|
||||
|
||||
vi.mock('testingbot-tunnel-launcher')
|
||||
vi.mock('@wdio/logger', () => import(path.join(process.cwd(), '__mocks__', '@wdio/logger')))
|
||||
const log = logger('')
|
||||
|
||||
describe('wdio-testingbot-service', () => {
|
||||
const execute = jest.fn()
|
||||
const execute = vi.fn()
|
||||
|
||||
afterEach(() => {
|
||||
execute.mockReset()
|
||||
|
|
@ -43,9 +47,14 @@ describe('wdio-testingbot-service', () => {
|
|||
const tbLauncher = new TestingBotLauncher(options)
|
||||
|
||||
await tbLauncher.onPrepare(config, caps)
|
||||
expect(tbLauncher.tbTunnelOpts).toMatchObject({ apiKey: 'user', apiSecret: 'key', tunnelIdentifier: 'some options' })
|
||||
expect(tbLauncher.tbTunnelOpts).toMatchObject({
|
||||
apiKey: 'user',
|
||||
apiSecret: 'key',
|
||||
tunnelIdentifier: 'some options'
|
||||
})
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
expect((log.info as jest.Mock).mock.calls[0][0]).toContain('TestingBot tunnel successfully started after')
|
||||
expect(vi.mocked(log.info).mock.calls[0][0])
|
||||
.toContain('TestingBot tunnel successfully started after')
|
||||
})
|
||||
|
||||
it('should merge tunnelIdentifier in tb:options', async () => {
|
||||
|
|
@ -180,8 +189,10 @@ describe('wdio-testingbot-service', () => {
|
|||
const tbLauncher = new TestingBotLauncher(options)
|
||||
|
||||
await tbLauncher.onPrepare(config, caps as any)
|
||||
expect(Object.keys((caps.browserA.capabilities as Capabilities.DesiredCapabilities)['tb:options'] as any)).toContain('tunnel-identifier')
|
||||
expect(Object.keys((caps.browserB.capabilities as Capabilities.DesiredCapabilities)['tb:options'] as any)).toContain('build')
|
||||
expect(Object.keys((caps.browserA.capabilities as Capabilities.DesiredCapabilities)['tb:options'] as any))
|
||||
.toContain('tunnel-identifier')
|
||||
expect(Object.keys((caps.browserB.capabilities as Capabilities.DesiredCapabilities)['tb:options'] as any))
|
||||
.toContain('build')
|
||||
})
|
||||
|
||||
it('onComplete', () => {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,24 @@
|
|||
import TestingBotService from '../src/service'
|
||||
import path from 'node:path'
|
||||
import got from 'got'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import type { Capabilities, Frameworks } from '@wdio/types'
|
||||
import type { Browser, MultiRemoteBrowser } from 'webdriverio'
|
||||
|
||||
import TestingBotService from '../src/service'
|
||||
|
||||
const uri = '/some/uri'
|
||||
const featureObject = {
|
||||
name: 'Create a feature'
|
||||
} as any
|
||||
|
||||
(got.put as jest.Mock).mockReturnValue(Promise.resolve({ body: '{}' }))
|
||||
vi.mock('got')
|
||||
vi.mocked(got.put).mockResolvedValue({ body: '{}' })
|
||||
vi.mock('@wdio/logger', () => import(path.join(process.cwd(), '__mocks__', '@wdio/logger')))
|
||||
|
||||
describe('wdio-testingbot-service', () => {
|
||||
const execute = jest.fn()
|
||||
const execute = vi.fn()
|
||||
|
||||
let browser: Browser | MultiRemoteBrowser
|
||||
let browser: Browser<'async'> | MultiRemoteBrowser<'async'>
|
||||
beforeEach(() => {
|
||||
browser = {
|
||||
execute,
|
||||
|
|
@ -33,8 +38,8 @@ describe('wdio-testingbot-service', () => {
|
|||
})
|
||||
|
||||
afterEach(() => {
|
||||
execute.mockReset();
|
||||
(got.put as jest.Mock).mockClear()
|
||||
execute.mockReset()
|
||||
vi.mocked(got.put).mockClear()
|
||||
})
|
||||
|
||||
it('before', () => {
|
||||
|
|
@ -233,7 +238,7 @@ describe('wdio-testingbot-service', () => {
|
|||
key: undefined
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
await tbService.after()
|
||||
|
||||
expect(updateJobSpy).not.toBeCalled()
|
||||
|
|
@ -246,7 +251,7 @@ describe('wdio-testingbot-service', () => {
|
|||
mochaOpts: { bail: true }
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
|
||||
tbService['_failures'] = 2
|
||||
|
|
@ -262,7 +267,7 @@ describe('wdio-testingbot-service', () => {
|
|||
mochaOpts: { bail: true }
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
await tbService.after(10)
|
||||
|
||||
|
|
@ -276,7 +281,7 @@ describe('wdio-testingbot-service', () => {
|
|||
mochaOpts: { bail: true }
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
|
||||
tbService['_failures'] = 0
|
||||
|
|
@ -296,7 +301,7 @@ describe('wdio-testingbot-service', () => {
|
|||
key: 'secret'
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
|
||||
tbService['_browser'].isMultiremote = true
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
|
|
@ -316,7 +321,7 @@ describe('wdio-testingbot-service', () => {
|
|||
tbService['_browser'] = browser
|
||||
const tbService2 = new TestingBotService({}, {}, {})
|
||||
tbService2['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService2, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService2, 'updateJob')
|
||||
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
await tbService.onReload('oldSessionId', 'newSessionId')
|
||||
|
|
@ -330,7 +335,7 @@ describe('wdio-testingbot-service', () => {
|
|||
key: 'secret'
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
tbService['_failures'] = 2
|
||||
|
|
@ -346,7 +351,7 @@ describe('wdio-testingbot-service', () => {
|
|||
key: 'secret'
|
||||
})
|
||||
tbService['_browser'] = browser
|
||||
const updateJobSpy = jest.spyOn(tbService, 'updateJob')
|
||||
const updateJobSpy = vi.spyOn(tbService, 'updateJob')
|
||||
|
||||
tbService['_browser'].isMultiremote = true
|
||||
tbService['_browser'].sessionId = 'sessionId'
|
||||
|
|
@ -427,14 +432,14 @@ describe('wdio-testingbot-service', () => {
|
|||
|
||||
expect(service['_failures']).toBe(0)
|
||||
expect(got.put).toHaveBeenCalled()
|
||||
expect((got.put as jest.Mock).mock.calls[0][1].username).toBe('foobar')
|
||||
expect((got.put as jest.Mock).mock.calls[0][1].password).toBe('123')
|
||||
expect((vi.mocked(got.put).mock.calls[0][1 as any] as any).username).toBe('foobar')
|
||||
expect((vi.mocked(got.put).mock.calls[0][1 as any] as any).password).toBe('123')
|
||||
})
|
||||
|
||||
it('updateJob failure', async () => {
|
||||
const response: any = new Error('Failure')
|
||||
response.statusCode = 500;
|
||||
(got.put as jest.Mock).mockReturnValue(Promise.reject(response))
|
||||
response.statusCode = 500
|
||||
vi.mocked(got.put).mockRejectedValue(response)
|
||||
|
||||
const service = new TestingBotService({}, {}, { user: 'foobar', key: '123' })
|
||||
service['_browser'] = browser
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ export default defineConfig({
|
|||
'packages/wdio-shared-store-service/**/*.test.ts',
|
||||
'packages/wdio-spec-reporter/**/*.test.ts',
|
||||
'packages/wdio-static-server-service/**/*.test.ts',
|
||||
'packages/wdio-sumologic-reporter/**/*.test.ts'
|
||||
'packages/wdio-sumologic-reporter/**/*.test.ts',
|
||||
'packages/wdio-testingbot-service/**/*.test.ts'
|
||||
],
|
||||
coverage: {
|
||||
enabled: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue