Skip to content
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
4 changes: 2 additions & 2 deletions packages/data-context/src/data/ProjectConfigIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TagStream } from '@packages/stderr-filtering'
// NOTE: need the file:// prefix to avoid https://nodejs.org/api/errors.html#err_unsupported_esm_url_scheme on windows
const tsx = os.platform() === 'win32' ? `file://${toPosix(require.resolve('tsx'))}` : toPosix(require.resolve('tsx'))

export type IpcHandler = (ipc: ProjectConfigIpc) => void
export type PluginIpcHandler = (ipc: ProjectConfigIpc) => void

/**
* If running as root on Linux, no-sandbox must be passed or Chrome will not start
Expand Down Expand Up @@ -194,7 +194,7 @@ export class ProjectConfigIpc extends EventEmitter {
})
}

async callSetupNodeEventsWithConfig (testingType: TestingType, config: FullConfig, handlers: IpcHandler[]): Promise<SetupNodeEventsReply> {
async callSetupNodeEventsWithConfig (testingType: TestingType, config: FullConfig, handlers: PluginIpcHandler[]): Promise<SetupNodeEventsReply> {
for (const handler of handlers) {
handler(this)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/data-context/src/data/ProjectConfigManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CypressError, getError } from '@packages/errors'
import { DebugData, IpcHandler, LoadConfigReply, ProjectConfigIpc, SetupNodeEventsReply } from './ProjectConfigIpc'
import { DebugData, PluginIpcHandler, LoadConfigReply, ProjectConfigIpc, SetupNodeEventsReply } from './ProjectConfigIpc'
import assert from 'assert'
import type { AllModeOptions, FullConfig, TestingType } from '@packages/types'
import debugLib from 'debug'
Expand Down Expand Up @@ -34,7 +34,7 @@ type ProjectConfigManagerOptions = {
ctx: DataContext
configFile: string | false
projectRoot: string
handlers: IpcHandler[]
handlers: PluginIpcHandler[]
hasCypressEnvFile: boolean
eventRegistrar: EventRegistrar
onError: (cypressError: CypressError) => void
Expand Down
6 changes: 3 additions & 3 deletions packages/data-context/src/util/pluginHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { IpcHandler } from '../data'
import type { PluginIpcHandler } from '../data'

let pluginHandlers: IpcHandler[] = []
let pluginHandlers: PluginIpcHandler[] = []

export const getServerPluginHandlers = () => {
return pluginHandlers
}

export const registerServerPluginHandler = (handler: IpcHandler) => {
export const registerServerPluginHandler = (handler: PluginIpcHandler) => {
pluginHandlers.push(handler)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/server/lib/controllers/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { get as errorsGet } from '../errors'
import preprocessor from '../plugins/preprocessor'
import type { Cfg } from '../project-base'
import type { Request, Response } from 'express'
import type { PreprocessorError } from '@packages/types'

const debug = Debug('cypress:server:controllers:spec')

Expand Down Expand Up @@ -49,7 +50,7 @@ export = {
})
.catch({ code: 'ECONNABORTED' }, ignoreECONNABORTED)
.catch({ code: 'EPIPE' }, ignoreEPIPE)
.catch((err: any) => {
.catch((err: PreprocessorError) => {
debug(`preprocessor error for spec '%s': %s`, spec, err.stack)

if (!config.isTextTerminal) {
Expand Down
37 changes: 0 additions & 37 deletions packages/server/lib/plugins/dev-server.js

This file was deleted.

60 changes: 60 additions & 0 deletions packages/server/lib/plugins/dev-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import '../cwd'

import { EventEmitter } from 'events'
import debug from 'debug'
import * as plugins from '../plugins'
import type { FullConfig, SpecWithRelativeRoot, PluginIpcHandler } from '@packages/types'

const debugFn = debug('cypress:ct:dev-server')

const baseEmitter = new EventEmitter()

interface SpecsChangedOptions {
neededForJustInTimeCompile?: boolean
}

interface SpecsChangedData {
specs: SpecWithRelativeRoot[]
options?: SpecsChangedOptions
}

interface CompileSuccessData {
specFile?: string
}

plugins.registerHandler((ipc: PluginIpcHandler) => {
baseEmitter.on('dev-server:specs:changed', (specsAndOptions: SpecsChangedData) => {
ipc.send('dev-server:specs:changed', specsAndOptions)
})

ipc.on('dev-server:compile:success', ({ specFile }: CompileSuccessData = {}) => {
baseEmitter.emit('dev-server:compile:success', { specFile })
})
})

// for simpler stubbing from unit tests
interface DevServerAPI {
emitter: EventEmitter
start: (options: { specs: Cypress.Spec[], config: FullConfig }) => Promise<Cypress.ResolvedDevServerConfig>
updateSpecs: (specs: SpecWithRelativeRoot[], options?: SpecsChangedOptions) => void
close: () => void
}

const API: DevServerAPI = {
emitter: baseEmitter,

start ({ specs, config }: { specs: Cypress.Spec[], config: FullConfig }) {
return plugins.execute('dev-server:start', { specs, config })
},

updateSpecs (specs: SpecWithRelativeRoot[], options?: SpecsChangedOptions) {
baseEmitter.emit('dev-server:specs:changed', { specs, options })
},

close () {
debugFn('close dev-server')
baseEmitter.removeAllListeners()
},
}

export default API
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason we have both module.exports and export default here @jennifer-shehane ? Since the code is internal we should just need export default API and any play this is required we just change the require('dev-server') to require('dev-server').default

Copy link
Member Author

Choose a reason for hiding this comment

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

Yah I think they were being used in tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

This may be some leftover code from me trying to get the utils to work, I’ll revisit next week

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@jennifer-shehane it's likely stubbing something that is now exported on the default. i'll pull the branch down and check

149 changes: 0 additions & 149 deletions packages/server/lib/plugins/preprocessor.js

This file was deleted.

Loading
Loading