Skip to content

Commit bd0d38f

Browse files
chore(server): convert modes/run to typescript (cypress-io#23536)
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
1 parent 2fcecbf commit bd0d38f

File tree

15 files changed

+1717
-2727
lines changed

15 files changed

+1717
-2727
lines changed

packages/data-context/src/actions/ProjectActions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CodeGenType, MutationSetProjectPreferencesInGlobalCacheArgs, NexusGenObjects, NexusGenUnions } from '@packages/graphql/src/gen/nxs.gen'
2-
import type { InitializeProjectOptions, FoundBrowser, FoundSpec, LaunchOpts, OpenProjectLaunchOptions, Preferences, TestingType, ReceivedCypressOptions, AddProject, FullConfig, AllowedState } from '@packages/types'
2+
import type { InitializeProjectOptions, FoundBrowser, FoundSpec, LaunchOpts, OpenProjectLaunchOptions, Preferences, TestingType, ReceivedCypressOptions, AddProject, FullConfig, AllowedState, SpecWithRelativeRoot } from '@packages/types'
33
import type { EventEmitter } from 'events'
44
import execa from 'execa'
55
import path from 'path'
@@ -40,7 +40,7 @@ export interface ProjectApiShape {
4040
setProjectPreferences(stated: AllowedState): void
4141
makeProjectSavedState(projectRoot: string): void
4242
getDevServer (): {
43-
updateSpecs(specs: FoundSpec[]): void
43+
updateSpecs(specs: SpecWithRelativeRoot[]): void
4444
start(options: {specs: Cypress.Spec[], config: FullConfig}): Promise<{port: number}>
4545
close(): void
4646
emitter: EventEmitter
@@ -313,7 +313,7 @@ export class ProjectActions {
313313
this.api.setPromptShown(slug)
314314
}
315315

316-
setSpecs (specs: FoundSpec[]) {
316+
setSpecs (specs: SpecWithRelativeRoot[]) {
317317
this.ctx.project.setSpecs(specs)
318318
this.refreshSpecs(specs)
319319

@@ -324,7 +324,7 @@ export class ProjectActions {
324324
this.ctx.emitter.specsChange()
325325
}
326326

327-
refreshSpecs (specs: FoundSpec[]) {
327+
refreshSpecs (specs: SpecWithRelativeRoot[]) {
328328
this.ctx.lifecycleManager.git?.setSpecs(specs.map((s) => s.absolute))
329329
}
330330

packages/data-context/src/sources/ProjectDataSource.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os from 'os'
22
import chokidar from 'chokidar'
3-
import type { ResolvedFromConfig, RESOLVED_FROM, FoundSpec, TestingType } from '@packages/types'
3+
import type { ResolvedFromConfig, RESOLVED_FROM, TestingType, SpecWithRelativeRoot } from '@packages/types'
44
import minimatch from 'minimatch'
55
import _ from 'lodash'
66
import path from 'path'
@@ -23,8 +23,6 @@ import type { ProjectShape } from '../data'
2323
import type { FindSpecs } from '../actions'
2424
import { getDefaultSpecFileName } from './migration/utils'
2525

26-
export type SpecWithRelativeRoot = FoundSpec & { relativeToCommonRoot: string }
27-
2826
interface MatchedSpecs {
2927
projectRoot: string
3028
testingType: Cypress.TestingType
@@ -199,7 +197,7 @@ export function getPathFromSpecPattern ({
199197

200198
export class ProjectDataSource {
201199
private _specWatcher: FSWatcher | null = null
202-
private _specs: FoundSpec[] = []
200+
private _specs: SpecWithRelativeRoot[] = []
203201

204202
constructor (private ctx: DataContext) {}
205203

@@ -227,7 +225,7 @@ export class ProjectDataSource {
227225
return this._specs
228226
}
229227

230-
setSpecs (specs: FoundSpec[]) {
228+
setSpecs (specs: SpecWithRelativeRoot[]) {
231229
this._specs = specs
232230
}
233231

@@ -256,7 +254,7 @@ export class ProjectDataSource {
256254
configSpecPattern,
257255
excludeSpecPattern,
258256
additionalIgnorePattern,
259-
}: FindSpecs<string[]>): Promise<FoundSpec[]> {
257+
}: FindSpecs<string[]>): Promise<SpecWithRelativeRoot[]> {
260258
let specAbsolutePaths = await this.ctx.file.getFilesByGlob(
261259
projectRoot,
262260
specPattern, {

packages/server/lib/automation/automation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class Automation {
184184
}
185185
}
186186

187-
get = (fn: keyof AutomationMiddleware) => {
187+
get = <K extends keyof AutomationMiddleware>(fn: K): AutomationMiddleware[K] => {
188188
return this.middleware[fn]
189189
}
190190
}

packages/server/lib/makeDataContext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function makeDataContext (options: MakeDataContextOptions): DataContext {
118118
return openProject.closeActiveProject()
119119
},
120120
getCurrentBrowser () {
121-
return (openProject?.projectBase?.browser) ?? undefined
121+
return (openProject?.getProject()?.browser) ?? undefined
122122
},
123123
getConfig () {
124124
return openProject.getConfig()

packages/server/lib/modes/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export = (mode, options) => {
3232
// a testingType, we default to e2e
3333
options.testingType = options.testingType || 'e2e'
3434

35-
return require('./run').run(options, loadingPromise)
35+
return (require('./run') as typeof import('./run')).run(options, loadingPromise)
3636
}
3737

3838
if (mode === 'interactive') {
3939
// Either launchpad or straight to e2e tests
40-
return require('./interactive').run(options, loadingPromise)
40+
return (require('./interactive') as typeof import('./interactive')).run(options, loadingPromise)
4141
}
4242
}

0 commit comments

Comments
 (0)