webdriverio/packages/wdio-cli/tests/constants.test.ts
mato533 3f1e7ef93a
feat: integrate the create-wdio package (#14618)
* chore: create sub-package of `create-wdio`

* docs: copy and adjustment for changing repository

* chore: copy a code of create-wdio

* chore: update compiler plugin

* chore: adjust npm script

* chore(wdio-cli): delete the code copied to `create-wdio`

* chore: remove compiler plugin for @wdio/cli

* docs: update root readme

* chore: update package.json

* style: apply format rule

* fix: remove unnecessary export `installPackages`

* test: remove unnecessary mocking in wdio-cli

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
2025-07-08 16:13:28 -07:00

86 lines
3.8 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { TESTRUNNER_DEFAULTS } from '../src/constants.js'
class CustomReporter {}
describe('constants', () => {
describe('TESTRUNNER_DEFAULTS', () => {
it('should expect specs to be an array', () => {
TESTRUNNER_DEFAULTS.specs!.validate!([])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.specs!.validate!('foobar')).toThrow()
})
it('should expect exclude to be an array', () => {
TESTRUNNER_DEFAULTS.exclude!.validate!([])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.exclude!.validate!('foobar')).toThrow()
})
it('should validate reporters correctly', () => {
TESTRUNNER_DEFAULTS.reporters!.validate!(['string'])
// @ts-expect-error wrong parameter
TESTRUNNER_DEFAULTS.reporters!.validate!([[CustomReporter, {}]])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.reporters!.validate!('foobar')).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.reporters!.validate!([false, 'string'])).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.reporters!.validate!([{}])).toThrow()
})
it('should validate capabilities correctly', () => {
TESTRUNNER_DEFAULTS.capabilities!.validate!([{}])
TESTRUNNER_DEFAULTS.capabilities!.validate!({})
expect(() => TESTRUNNER_DEFAULTS.capabilities!.validate!('foobar')).toThrow()
expect(() => TESTRUNNER_DEFAULTS.capabilities!.validate!(false)).toThrow()
expect(() => TESTRUNNER_DEFAULTS.capabilities!.validate!([{}, 'foobar'])).toThrow()
})
it('should validate services correctly', () => {
TESTRUNNER_DEFAULTS.services!.validate!(['foobar'])
// @ts-expect-error wrong parameter
TESTRUNNER_DEFAULTS.services!.validate!([[]])
TESTRUNNER_DEFAULTS.services!.validate!([['service', {}], 'foobar'])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.services!.validate!('foobar')).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.services!.validate!(false)).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.services!.validate!(['foobar', true])).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.services!.validate!([[], {}])).toThrow()
})
it('should expect execArgv to be an array', () => {
TESTRUNNER_DEFAULTS.execArgv!.validate!([])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.execArgv!.validate!('foobar')).toThrow()
})
it('should expect filesToWatch to be an array', () => {
TESTRUNNER_DEFAULTS.filesToWatch!.validate!([])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.filesToWatch!.validate!('foobar')).toThrow()
})
})
describe('HOOK_DEFINITION', () => {
it('should only accept arrays of functions', () => {
TESTRUNNER_DEFAULTS.before!.validate!([])
TESTRUNNER_DEFAULTS.before!.validate!([() => {}])
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.before!.validate!()).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.before!.validate!(['foobar'])).toThrow()
// @ts-expect-error wrong parameter
expect(() => TESTRUNNER_DEFAULTS.before!.validate!([() => {}, 'foobar'])).toThrow()
})
})
})