feat: Add typings for new devServer config (#18797)

This commit is contained in:
Tim Griesser
2021-11-08 11:02:01 -05:00
committed by GitHub
parent c8a7de8bb2
commit e018a14c21
18 changed files with 30 additions and 65 deletions
+1 -1
View File
@@ -395,7 +395,7 @@ declare module 'cypress' {
* @param {Cypress.ConfigOptions} config
* @returns {Cypress.ConfigOptions} the configuration passed in parameter
*/
defineConfig(config: Cypress.ConfigOptions): Cypress.ConfigOptions
defineConfig<ComponentDevServerOpts = any>(config: Cypress.ConfigOptions<ComponentDevServerOpts>): Cypress.ConfigOptions
}
// export Cypress NPM module interface
+15 -1
View File
@@ -2895,7 +2895,21 @@ declare namespace Cypress {
* All configuration items are optional.
*/
type CoreConfigOptions = Partial<Omit<ResolvedConfigOptions, TestingType>>
type ConfigOptions = CoreConfigOptions & { e2e?: CoreConfigOptions, component?: CoreConfigOptions }
interface ComponentConfigOptions<ComponentDevServerOpts = any> extends CoreConfigOptions {
// TODO(tim): Keeping optional until we land the implementation
devServer?: (cypressConfig: DevServerConfig, devServerConfig: ComponentDevServerOpts) => ResolvedDevServerConfig | Promise<ResolvedDevServerConfig>
devServerConfig?: ComponentDevServerOpts
}
/**
* Takes ComponentDevServerOpts to track the signature of the devServerConfig for the provided `devServer`,
* so we have proper completion for `devServerConfig`
*/
type ConfigOptions<ComponentDevServerOpts = any> = CoreConfigOptions & {
e2e?: CoreConfigOptions,
component?: ComponentConfigOptions<ComponentDevServerOpts>
}
interface PluginConfigOptions extends ResolvedConfigOptions {
/**
-5
View File
@@ -16,11 +16,6 @@ declare namespace legacyDevServer {
indexHtml?: string
}
/**
* Type helper to make writing `CypressBabelDevServerConfig` easier
*/
function defineDevServerConfig(devServerConfig: CypressBabelDevServerConfig): CypressBabelDevServerConfig
/**
* Sets up a webpack dev server with the proper configuration for babel transpilation
* @param cypressDevServerConfig comes from the `devServer()` function first argument
-4
View File
@@ -19,7 +19,3 @@ module.exports = getLegacyDevServer(devServer, (config) => {
// New signature
module.exports.devServer = devServer
module.exports.defineDevServerConfig = function (devServerConfig) {
return devServerConfig
}
-5
View File
@@ -12,11 +12,6 @@ declare namespace legacyDevServer {
indexHtml?: string
}
/**
* Type helper to make writing `CypressCracoDevServerConfig` easier
*/
function defineDevServerConfig(devServerConfig: CypressCracoDevServerConfig): CypressCracoDevServerConfig
/**
* Sets up a dev server for using Cypress compoennt testing with CRACO (https://github.com/gsoft-inc/craco)
* @param cypressDevServerConfig comes from the `devServer()` function first argument
-4
View File
@@ -24,7 +24,3 @@ module.exports = getLegacyDevServer(devServer, (config) => {
module.exports.devServer = (cypressDevServerConfig, { cracoConfig, indexHtml }) => {
return devServer(cypressDevServerConfig, cracoConfig, indexHtml)
}
module.exports.defineDevServerConfig = function (devServerConfig) {
return devServerConfig
}
-5
View File
@@ -12,11 +12,6 @@ declare namespace legacyDevServer {
indexHtml?: string
}
/**
* Type helper to make writing `CypressWebpackDevServerConfig` easier
*/
function defineDevServerConfig(devServerConfig: CypressWebpackDevServerConfig): CypressWebpackDevServerConfig
/**
* Sets up a webpack dev server with the proper configuration for babel transpilation
* @param cypressDevServerConfig comes from the `devServer()` function first argument
-4
View File
@@ -38,7 +38,3 @@ module.exports = getLegacyDevServer(devServer, (config) => {
// New signature
module.exports.devServer = devServer
module.exports.defineDevServerConfig = function (devServerConfig) {
return devServerConfig
}
-5
View File
@@ -14,11 +14,6 @@ declare namespace legacyDevServer {
indexHtml?: string
}
/**
* Type helper to make writing `CypressNextDevServerConfig` easier
*/
function defineDevServerConfig(devServerConfig: CypressNextDevServerConfig): CypressNextDevServerConfig
/**
* Sets up a Cypress component testing environment for your NextJs application
* @param cypressDevServerConfig comes from the `devServer()` function first argument
-5
View File
@@ -12,11 +12,6 @@ declare namespace legacyDevServer {
indexHtml?: string
}
/**
* Type helper to make writing `CypressCRADevServerConfig` easier
*/
function defineDevServerConfig(devServerConfig: CypressCRADevServerConfig): CypressCRADevServerConfig
/**
* Sets up a Cypress component testing environment for your Create React App environment
* @param cypressDevServerConfig comes from the `devServer()` function first argument
-4
View File
@@ -24,7 +24,3 @@ module.exports = getLegacyDevServer(devServer, (config) => {
// New signature
module.exports.devServer = devServer
module.exports.defineDevServerConfig = function (devServerConfig) {
return devServerConfig
}
@@ -5,15 +5,15 @@
*/
const path = require('path')
const { devServer, defineDevServerConfig } = require('../../dist')
const { devServer } = require('../../dist')
module.exports = (on, config) => {
on('dev-server:start', async (options) => {
return devServer(
options,
defineDevServerConfig({
{
configFile: path.resolve(__dirname, '..', '..', 'vite.config.ts'),
}),
},
)
})
-4
View File
@@ -21,7 +21,3 @@ export type CypressViteDevServerConfig = Omit<InlineConfig, 'base' | 'root'>
export function devServer (cypressDevServerConfig: Cypress.DevServerConfig, devServerConfig?: CypressViteDevServerConfig) {
return startDevServer({ options: cypressDevServerConfig, viteConfig: devServerConfig })
}
export function defineDevServerConfig (devServerConfig: CypressViteDevServerConfig) {
return devServerConfig
}
-4
View File
@@ -71,7 +71,3 @@ export function devServer (cypressDevServerConfig: Cypress.DevServerConfig, devS
template: devServerConfig?.template,
})
}
export function defineDevServerConfig (devServerConfig: CypressWebpackDevServerConfig) {
return devServerConfig
}
+2 -2
View File
@@ -6,7 +6,7 @@ import http from 'http'
import fs from 'fs'
import { webpackDevServerFacts } from '../src/webpackDevServerFacts'
import { defineDevServerConfig, devServer, startDevServer } from '../'
import { devServer, startDevServer } from '../'
const requestSpecFile = (port: number) => {
return new Promise((res) => {
@@ -164,7 +164,7 @@ describe('#startDevServer', () => {
specs,
devServerEvents,
},
defineDevServerConfig({ webpackConfig }),
{ webpackConfig },
)
const response = await requestSpecFile(port as number)
@@ -3,16 +3,16 @@ import type { SampleConfigFile } from '@packages/types'
// FIXME: temporary content
const content = `import { defineConfig } from 'cypress'
import { devServer, defineDevServerConfig } from '@cypress/vite-dev-server'
import { devServer } from '@cypress/vite-dev-server'
// sample code !!!
export default defineConfig({
component: {
devServer,
devServerConfig: defineDevServerConfig({
devServerConfig: {
entryHtmlFile: 'cypress/component/support/entry.html'
}),
},
},
})`
@@ -2,14 +2,14 @@ import ShikiHighlight, { initHighlighter } from './ShikiHighlight.vue'
import code from '../../windi.config?raw'
const devServerCode = `const { defineConfig } = require('cypress')
const { devServer, defineDevServerConfig } = require('@cypress/vite-dev-server')
const { devServer } = require('@cypress/vite-dev-server')
module.exports = defineConfig({
component: {
devServer,
devServerConfig: defineDevServerConfig({
devServerConfig: {
entryHtmlFile: 'cypress/component/support/entry.html'
}),
},
},
})`
@@ -4,14 +4,14 @@ import faker from 'faker'
import { defaultMessages } from '@cy/i18n'
const content = `import { defineConfig } from 'cypress'
import { devServer, defineDevServerConfig } from '@cypress/vite-dev-server'
import { devServer } from '@cypress/vite-dev-server'
export default defineConfig({
component: {
devServer,
devServerConfig: defineDevServerConfig({
devServerConfig: {
entryHtmlFile: 'cypress/component/support/entry.html'
}),
},
},
})`