fix: type issue of e2e tests

This commit is contained in:
mutoe 2022-06-12 22:52:47 +08:00
parent 45dea6fbef
commit 44279eb948
No known key found for this signature in database
GPG Key ID: 7197231B847AE2EE
5 changed files with 55 additions and 26 deletions

17
cypress/e2e/tsconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": [
"./**/*",
"../fixtures/**/*",
"../support/commands.ts",
"../support/e2e.ts"
],
"exclude": ["../../src"],
"compilerOptions": {
"baseUrl": "./",
"isolatedModules": false,
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "@testing-library/cypress"]
}
}

View File

@ -16,17 +16,17 @@
// https://on.cypress.io/configuration
// ***********************************************************
import './commands'
import type { CyMountOptions } from 'cypress/vue'
import type { StyleOptions } from '@cypress/mount-utils'
import type { MountingOptions } from '@vue/test-utils'
import { mount } from 'cypress/vue'
import registerGlobalComponents from 'src/plugins/global-components'
import { routes } from 'src/router'
import type {
ComponentOptionsWithArrayProps, ComponentOptionsWithObjectProps,
ComponentOptionsWithoutProps, ComponentPropsOptions, FunctionalComponent,
DefineComponent, ExtractDefaultPropTypes, MethodOptions,
AllowedComponentProps, ComponentCustomProps, VNodeProps,
ComponentOptionsMixin,
ComputedOptions,
EmitsOptions, ExtractPropTypes,
ComponentOptionsMixin, ComputedOptions, EmitsOptions, ExtractPropTypes,
} from 'vue'
import type { Router } from 'vue-router'
import { createMemoryHistory, createRouter } from 'vue-router'
@ -34,10 +34,28 @@ import { createMemoryHistory, createRouter } from 'vue-router'
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
type RouterOptions = {router?: Router}
type Mount = <PropsOrPropOptions = {}, RawBindings = {}, D = {}, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = Record<string, any>, EE extends string = string, PP = PublicProps, Props = Readonly<ExtractPropTypes<PropsOrPropOptions>>, Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>>(
component: DefineComponent<PropsOrPropOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, PP, Props, Defaults>,
options?: CyMountOptions<Partial<Defaults> & Omit<Props & PublicProps, keyof Defaults>, D> & RouterOptions,
) => Cypress.Chainable
export declare type CyMountOptions<Props, Data = {}> =
& Omit<MountingOptions<Props, Data>, 'attachTo'>
& { log?: boolean }
& Partial<StyleOptions>
& RouterOptions
interface Mount {
<V>(originalComponent: {
new (...args: any[]): V
registerHooks(keys: string[]): void
}, options?: MountingOptions<any>): Cypress.Chainable
<V, P>(originalComponent: {
new (...args: any[]): V
props(Props: P): any
registerHooks(keys: string[]): void
}, options?: CyMountOptions<P & PublicProps>): Cypress.Chainable
<Props, E extends EmitsOptions = {}>(originalComponent: FunctionalComponent<Props, E>, options?: CyMountOptions<Props & PublicProps>): Cypress.Chainable
<PropsOrPropOptions = {}, RawBindings = {}, D = {}, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = Record<string, any>, EE extends string = string, PP = PublicProps, Props = Readonly<ExtractPropTypes<PropsOrPropOptions>>, Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>>(component: DefineComponent<PropsOrPropOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, PP, Props, Defaults>, options?: CyMountOptions<Partial<Defaults> & Omit<Props & PublicProps, keyof Defaults>, D>): Cypress.Chainable
<Props = {}, RawBindings = {}, D = {}>(componentOptions: ComponentOptionsWithoutProps<Props, RawBindings, D>, options?: CyMountOptions<Props & PublicProps, D>): Cypress.Chainable
<PropNames extends string, RawBindings, D, C extends ComputedOptions = {}, M extends Record<string, Function> = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string, Props extends Readonly<{ [key in PropNames]?: any; }> = Readonly<{ [key in PropNames]?: any; }>>(componentOptions: ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, E, Mixin, Extends, EE, Props>, options?: CyMountOptions<Props & PublicProps, D>): Cypress.Chainable
<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends Record<string, Function> = {}, E extends EmitsOptions = Record<string, any>, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, EE extends string = string>(componentOptions: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, E, Mixin, Extends, EE>, options?: CyMountOptions<ExtractPropTypes<PropsOptions> & PublicProps, D>): Cypress.Chainable
}
type MountParams = Parameters<Mount>
@ -50,7 +68,7 @@ declare global {
}
}
Cypress.Commands.add('mount', (component: any, options: MountParams[1] = {}) => {
Cypress.Commands.add('mount', (component: MountParams[0], options: MountParams[1] = {}) => {
options.global = options.global || {}
options.global.plugins = options.global.plugins || []

View File

@ -15,10 +15,11 @@
import './commands'
import { ROUTES } from 'e2e/constant'
import { ROUTES } from '../e2e/constant'
declare global {
namespace Cypress {
// noinspection JSUnusedGlobalSymbols
interface Chainable {
login(): void
}

View File

@ -1,14 +0,0 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["./**/*.{ts,json}", ".eslintrc.js", "../src/router.ts", "../src/plugins/global-components.ts"],
"compilerOptions": {
"baseUrl": ".",
"isolatedModules": false,
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "@testing-library/cypress"],
"paths": {
"src/*": ["../src/*"],
}
}
}

View File

@ -1,6 +1,13 @@
{
"extends": "./tsconfig.app.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "cypress/support/component.*"],
"include": [
"env.d.ts",
"src/**/*",
"src/**/*.vue",
"cypress/support/component.*",
"cypress/support/commands.ts",
"cypress/fixtures/**/*",
],
"exclude": [],
"compilerOptions": {
"composite": true,