Skip to content

Commit e0b7bd1

Browse files
committed
chore: cut over exec directory to vitest
1 parent ea18b2d commit e0b7bd1

19 files changed

+1498
-955
lines changed

cli/.mocharc.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
module.exports = {
22
// hardcoding the spec file names as they will be converted 1 by 1 to vitest
33
spec: [
4-
'test/lib/exec/info.spec.ts',
5-
'test/lib/exec/open.spec.ts',
6-
'test/lib/exec/run.spec.ts',
7-
'test/lib/exec/spawn.spec.ts',
8-
'test/lib/exec/versions.spec.ts',
9-
'test/lib/exec/xvfb.spec.ts',
104
'test/lib/tasks/cache.spec.ts',
115
'test/lib/tasks/dependency.spec.ts',
126
'test/lib/tasks/download.spec.ts',

cli/__snapshots__/run.spec.ts.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

cli/__snapshots__/spawn.spec.ts.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

cli/lib/exec/open.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const processOpenOptions = (options: any = {}): string[] => {
7474
return args
7575
}
7676

77-
export const start = (options: any = {}): any => {
77+
export const start = async (options: any = {}): Promise<any> => {
7878
function open (): any {
7979
try {
8080
const args = processOpenOptions(options)
@@ -96,8 +96,9 @@ export const start = (options: any = {}): any => {
9696
return open()
9797
}
9898

99-
return verifyModule.start()
100-
.then(open)
99+
await verifyModule.start()
100+
101+
return open()
101102
}
102103

103104
export default {

cli/lib/exec/run.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const runModule = {
164164
processRunOptions,
165165
isValidProject,
166166
// resolves with the number of failed tests
167-
start (options: any = {}): any {
167+
async start (options: any = {}): Promise<any> {
168168
_.defaults(options, {
169169
key: null,
170170
spec: null,
@@ -195,8 +195,9 @@ const runModule = {
195195
return run()
196196
}
197197

198-
return verifyModule.start()
199-
.then(run)
198+
await verifyModule.start()
199+
200+
return run()
200201
},
201202
}
202203

cli/lib/exec/spawn.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import xvfb from './xvfb'
1010
import verifyModule from '../tasks/verify'
1111
import { throwFormErrorText, getError, errors } from '../errors'
1212
import readline from 'readline'
13+
import { stdin, stdout, stderr } from 'process'
1314

1415
const debug = Debug('cypress:cli')
1516

@@ -50,7 +51,7 @@ function getStdio (needsXvfb: boolean): any {
5051
}
5152

5253
const spawnModule = {
53-
start (args: any, options: any = {}): any {
54+
async start (args: any, options: any = {}): Promise<any> {
5455
const needsXvfb = xvfb.isNeeded()
5556
let executable = state.getPathToExecutable(state.getBinaryDir())
5657

@@ -149,13 +150,15 @@ const spawnModule = {
149150
const child = cp.spawn(executable, args, stdioOptions)
150151

151152
function resolveOn (event: any): any {
152-
return function (code: any, signal: any): any {
153+
return async function (code: any, signal: any): Promise<any> {
153154
debug('child event fired %o', { event, code, signal })
154155

155156
if (code === null) {
156157
const errorObject = errors.childProcessKilled(event, signal)
157158

158-
return getError(errorObject).then(reject)
159+
const err = await getError(errorObject)
160+
161+
return reject(err)
159162
}
160163

161164
resolve(code)
@@ -168,8 +171,8 @@ const spawnModule = {
168171

169172
if (isPlatform('win32')) {
170173
const rl = readline.createInterface({
171-
input: process.stdin,
172-
output: process.stdout,
174+
input: stdin,
175+
output: stdout,
173176
})
174177

175178
// on windows, SIGINT does not propagate to the child process when ctrl+c is pressed
@@ -188,12 +191,12 @@ const spawnModule = {
188191
// child STDERR => process STDERR with additional filtering
189192
if (child.stdin) {
190193
debug('piping process STDIN into child STDIN')
191-
process.stdin.pipe(child.stdin)
194+
stdin.pipe(child.stdin)
192195
}
193196

194197
if (child.stdout) {
195198
debug('piping child STDOUT to process STDOUT')
196-
child.stdout.pipe(process.stdout)
199+
child.stdout.pipe(stdout)
197200
}
198201

199202
// if this is defined then we are manually piping for linux
@@ -210,7 +213,7 @@ const spawnModule = {
210213
}
211214

212215
// else pass it along!
213-
process.stderr.write(data)
216+
stderr.write(data)
214217
})
215218
}
216219

@@ -221,7 +224,7 @@ const spawnModule = {
221224
// into the child process. unpiping does not seem
222225
// to have any effect. so we're just catching the
223226
// error here and not doing anything.
224-
process.stdin.on('error', (err: any) => {
227+
stdin.on('error', (err: any) => {
225228
if (['EPIPE', 'ENOTCONN'].includes(err.code)) {
226229
return
227230
}
@@ -235,17 +238,22 @@ const spawnModule = {
235238
})
236239
}
237240

238-
const spawnInXvfb = (): any => {
239-
return xvfb
240-
.start()
241-
.then(userFriendlySpawn)
242-
.finally(xvfb.stop)
241+
const spawnInXvfb = async (): Promise<void> => {
242+
try {
243+
const linuxWithDisplayEnv = await xvfb.start()
244+
245+
const code = await userFriendlySpawn(linuxWithDisplayEnv)
246+
247+
return code
248+
} finally {
249+
await xvfb.stop()
250+
}
243251
}
244252

245-
const userFriendlySpawn = (linuxWithDisplayEnv: any): any => {
253+
const userFriendlySpawn = async (linuxWithDisplayEnv: any): Promise<any> => {
246254
debug('spawning, should retry on display problem?', Boolean(linuxWithDisplayEnv))
247255

248-
let brokenGtkDisplay: boolean
256+
let brokenGtkDisplay: boolean = false
249257

250258
const overrides: any = {}
251259

@@ -262,19 +270,27 @@ const spawnModule = {
262270
})
263271
}
264272

265-
return spawn(overrides)
266-
.then((code: any) => {
273+
try {
274+
const code: number = await spawn(overrides)
275+
267276
if (code !== 0 && brokenGtkDisplay) {
268277
util.logBrokenGtkDisplayWarning()
269278

270279
return spawnInXvfb()
271280
}
272281

273282
return code
274-
})
275-
// we can format and handle an error message from the code above
276-
// prevent wrapping error again by using "known: undefined" filter
277-
.catch({ known: undefined }, throwFormErrorText(errors.unexpected))
283+
} catch (error: any) {
284+
// we can format and handle an error message from the code above
285+
// prevent wrapping error again by using "known: undefined" filter
286+
if ((error as any).known === undefined) {
287+
const raiseErrorFn = throwFormErrorText(errors.unexpected)
288+
289+
await raiseErrorFn(error.message)
290+
}
291+
292+
throw error
293+
}
278294
}
279295

280296
if (needsXvfb) {

cli/lib/exec/versions.ts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Bluebird from 'bluebird'
21
import Debug from 'debug'
32
import path from 'path'
43
import util from '../util'
@@ -7,59 +6,62 @@ import { throwFormErrorText, errors } from '../errors'
76

87
const debug = Debug('cypress:cli')
98

10-
const getVersions = (): any => {
11-
return Bluebird.try(() => {
12-
if (util.getEnv('CYPRESS_RUN_BINARY')) {
13-
let envBinaryPath = path.resolve(util.getEnv('CYPRESS_RUN_BINARY') as string)
9+
const getBinaryDirectory = async (): Promise<string> => {
10+
if (util.getEnv('CYPRESS_RUN_BINARY')) {
11+
let envBinaryPath = path.resolve(util.getEnv('CYPRESS_RUN_BINARY') as string)
1412

15-
return state.parseRealPlatformBinaryFolderAsync(envBinaryPath)
16-
.then((envBinaryDir: any) => {
17-
if (!envBinaryDir) {
18-
return throwFormErrorText(errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))()
19-
}
13+
try {
14+
const envBinaryDir = await state.parseRealPlatformBinaryFolderAsync(envBinaryPath)
2015

21-
debug('CYPRESS_RUN_BINARY has binaryDir:', envBinaryDir)
16+
if (!envBinaryDir) {
17+
const raiseErrorFn = throwFormErrorText(errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))
2218

23-
return envBinaryDir
24-
})
25-
.catch({ code: 'ENOENT' }, (err: any) => {
26-
return throwFormErrorText(errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))(err.message)
27-
})
28-
}
19+
await raiseErrorFn()
20+
}
21+
22+
debug('CYPRESS_RUN_BINARY has binaryDir:', envBinaryDir)
23+
24+
return envBinaryDir
25+
} catch (err: any) {
26+
const raiseErrorFn = throwFormErrorText(errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))
2927

30-
return state.getBinaryDir()
31-
})
32-
.then(state.getBinaryPkgAsync)
33-
.then((pkg: any) => {
34-
const versions = {
35-
binary: state.getBinaryPkgVersion(pkg),
36-
electronVersion: state.getBinaryElectronVersion(pkg),
37-
electronNodeVersion: state.getBinaryElectronNodeVersion(pkg),
28+
await raiseErrorFn(err.message)
3829
}
30+
}
3931

40-
debug('binary versions %o', versions)
32+
return state.getBinaryDir()
33+
}
4134

42-
return versions
43-
})
44-
.then((binaryVersions: any) => {
45-
const buildInfo = util.pkgBuildInfo()
35+
const getVersions = async (): Promise<any> => {
36+
const binDir = await getBinaryDirectory()
4637

47-
let packageVersion = util.pkgVersion()
38+
const pkg = await state.getBinaryPkgAsync(binDir)
4839

49-
if (!buildInfo) packageVersion += ' (development)'
50-
else if (!buildInfo.stable) packageVersion += ' (pre-release)'
40+
const versions = {
41+
binary: state.getBinaryPkgVersion(pkg),
42+
electronVersion: state.getBinaryElectronVersion(pkg),
43+
electronNodeVersion: state.getBinaryElectronNodeVersion(pkg),
44+
}
5145

52-
const versions = {
53-
package: packageVersion,
54-
binary: binaryVersions.binary || 'not installed',
55-
electronVersion: binaryVersions.electronVersion || 'not found',
56-
electronNodeVersion: binaryVersions.electronNodeVersion || 'not found',
57-
}
46+
debug('binary versions %o', versions)
47+
48+
const buildInfo = util.pkgBuildInfo()
49+
50+
let packageVersion = util.pkgVersion()
51+
52+
if (!buildInfo) packageVersion += ' (development)'
53+
else if (!buildInfo.stable) packageVersion += ' (pre-release)'
54+
55+
const versionsFinal = {
56+
package: packageVersion,
57+
binary: versions.binary || 'not installed',
58+
electronVersion: versions.electronVersion || 'not found',
59+
electronNodeVersion: versions.electronNodeVersion || 'not found',
60+
}
5861

59-
debug('combined versions %o', versions)
62+
debug('combined versions %o', versions)
6063

61-
return versions
62-
})
64+
return versionsFinal
6365
}
6466

6567
const versionsModule = {

0 commit comments

Comments
 (0)