Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove baseUrl from root-level types for supported fields #20589

Merged
merged 14 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2963,7 +2963,7 @@ declare namespace Cypress {
xhrUrl: string
}

interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'baseUrl' | 'blockHosts' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'numTestsKeptInMemory' | 'pageLoadTimeout' | 'redirectionLimit' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'screenshotOnRunFailure' | 'slowTestThreshold' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>> {
interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'blockHosts' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'numTestsKeptInMemory' | 'pageLoadTimeout' | 'redirectionLimit' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'screenshotOnRunFailure' | 'slowTestThreshold' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>> {
browser?: IsBrowserMatcher | IsBrowserMatcher[]
keystrokeDelay?: number
}
Expand All @@ -2974,16 +2974,21 @@ declare namespace Cypress {
type CoreConfigOptions = Partial<Omit<ResolvedConfigOptions, TestingType>>

type DevServerFn<ComponentDevServerOpts = any> = (cypressDevServerConfig: DevServerConfig, devServerConfig: ComponentDevServerOpts) => ResolvedDevServerConfig | Promise<ResolvedDevServerConfig>
interface ComponentConfigOptions<ComponentDevServerOpts = any> extends CoreConfigOptions {
interface ComponentConfigOptions<ComponentDevServerOpts = any> extends Omit<CoreConfigOptions, 'baseUrl'> {
devServer: DevServerFn<ComponentDevServerOpts>
devServerConfig?: ComponentDevServerOpts
}

/**
* Config options that can be assigned on cypress.config.{ts|js} file
*/
type UserConfigOptions<ComponentDevServerOpts = any> = Omit<ResolvedConfigOptions<ComponentDevServerOpts>, 'baseUrl' | 'excludeSpecPattern' | 'supportFile' | 'specPattern'>

/**
* Takes ComponentDevServerOpts to track the signature of the devServerConfig for the provided `devServer`,
* so we have proper completion for `devServerConfig`
*/
type ConfigOptions<ComponentDevServerOpts = any> = Partial<ResolvedConfigOptions<ComponentDevServerOpts>>
type ConfigOptions<ComponentDevServerOpts = any> = Partial<UserConfigOptions<ComponentDevServerOpts>>

interface PluginConfigOptions extends ResolvedConfigOptions, RuntimeConfigOptions {
/**
Expand Down
4 changes: 3 additions & 1 deletion cli/types/tests/cypress-npm-api-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ cypress.run({

// provide only some config options
const runConfig: Cypress.ConfigOptions = {
baseUrl: 'http://localhost:8080',
e2e: {
baseUrl: 'http://localhost:8080',
},
env: {
login: false
},
Expand Down
10 changes: 4 additions & 6 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ namespace CypressConfigTests {
Cypress.config().baseUrl // $ExpectType string | null

// setters
Cypress.config('baseUrl', '.') // $ExpectType void
Cypress.config('baseUrl', null) // $ExpectType void
Cypress.config({ baseUrl: '.', }) // $ExpectType void
Cypress.config({ e2e: { baseUrl: '.' }}) // $ExpectType void
Cypress.config({ e2e: { baseUrl: null }}) // $ExpectType void
Cypress.config({ e2e: { baseUrl: '.', }}) // $ExpectType void
Copy link
Contributor

@lmiller1990 lmiller1990 Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need one of these tests asserting component.baseUrl is not allowed? (I am not sure if these inline, string-based assertions support that)

Cypress.config({ component: { baseUrl: '.', devServer: () => ({} as any) } }) // $ExpectError

Cypress.config('taskTimeout') // $ExpectType number
Cypress.config('includeShadowDom') // $ExpectType boolean
Expand Down Expand Up @@ -686,7 +687,6 @@ namespace CypressTestConfigOverridesTests {
// set config on a per-test basis
it('test', {
animationDistanceThreshold: 10,
baseUrl: 'www.foobar.com',
defaultCommandTimeout: 6000,
env: {},
execTimeout: 6000,
Expand Down Expand Up @@ -747,15 +747,13 @@ namespace CypressTestConfigOverridesTests {
// set config on a per-suite basis
describe('suite', {
browser: {family: 'firefox'},
baseUrl: 'www.example.com',
keystrokeDelay: 0
}, () => {})

context('suite', {}, () => {})

describe('suite', {
browser: {family: 'firefox'},
baseUrl: 'www.example.com',
keystrokeDelay: false // $ExpectError
foo: 'foo' // $ExpectError
}, () => {})
Expand Down
9 changes: 6 additions & 3 deletions cli/types/tests/plugins-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const pluginConfig: Cypress.PluginConfig = (on, config) => {}
// allows synchronous returns
const pluginConfig2: Cypress.PluginConfig = (on, config) => {
config // $ExpectType PluginConfigOptions
config.baseUrl // $ExpectType string | null
config.configFile // $ExpectType string | false
config.fixturesFolder // $ExpectType string | false
config.screenshotsFolder // $ExpectType string | false
Expand Down Expand Up @@ -66,7 +65,9 @@ const pluginConfig2: Cypress.PluginConfig = (on, config) => {
})

return {
baseUrl: 'http://localhost:3000'
e2e: {
baseUrl: 'http://localhost:3000'
}
}
}

Expand Down Expand Up @@ -105,7 +106,9 @@ const pluginConfig4: Cypress.PluginConfig = (on, config) => {
})

return Promise.resolve({
baseUrl: 'http://localhost:3000'
e2e: {
baseUrl: 'http://localhost:3000'
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion npm/cypress-schematic/src/builders/cypress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function initCypress (userOptions: CypressBuilderOptions): Observable<BuilderOut
}

if (userOptions.baseUrl) {
options.config = { ...options.config, baseUrl: userOptions.baseUrl }
options.config = { ...options.config, e2e: { ...options.config?.e2e, baseUrl: userOptions.baseUrl } }
}

const { watch, headless } = userOptions
Expand Down