-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
misc: convert server/lib/modes files to ts + add more cli options to Cloud terminal error outputs #31211
Merged
Merged
misc: convert server/lib/modes files to ts + add more cli options to Cloud terminal error outputs #31211
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a531b0f
chore: convert server/lib/modes files to ts
jennifer-shehane ce0c462
update snapshots
jennifer-shehane dc1756c
add back require
jennifer-shehane 1e3d8ad
fix call to errors.warning
jennifer-shehane 4e6ef41
Merge branch 'develop' into js-to-ts-server-2
jennifer-shehane 5b78bc4
Add changelog entry.
jennifer-shehane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require('./environment') | ||
import './environment' | ||
|
||
// we are not requiring everything up front | ||
// to optimize how quickly electron boots while | ||
|
@@ -9,14 +9,19 @@ require('./environment') | |
// essentially do it all again when we boot the correct | ||
// mode. | ||
|
||
const Promise = require('bluebird') | ||
const debug = require('debug')('cypress:server:cypress') | ||
const { getPublicConfigKeys } = require('@packages/config') | ||
const argsUtils = require('./util/args') | ||
const { telemetry } = require('@packages/telemetry') | ||
const { getCtx, hasCtx } = require('@packages/data-context') | ||
import Promise from 'bluebird' | ||
import Debug from 'debug' | ||
import { getPublicConfigKeys } from '@packages/config' | ||
import argsUtils from './util/args' | ||
import { telemetry } from '@packages/telemetry' | ||
import { getCtx, hasCtx } from '@packages/data-context' | ||
import type { AllCypressErrorObj } from '@packages/errors/src/errors' | ||
|
||
const warning = (code, args) => { | ||
const debug = Debug('cypress:server:cypress') | ||
|
||
type Mode = 'exit' | 'info' | 'interactive' | 'pkg' | 'record' | 'results' | 'run' | 'smokeTest' | 'version' | 'returnPkg' | 'exitWithCode' | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type may be more than is actually supported. It was hard to tell the definitive list by how this is called. |
||
const warning = function <Type extends keyof AllCypressErrorObj> (code: Type, ...args: Parameters<AllCypressErrorObj[Type]>) { | ||
return require('./errors').warning(code, args) | ||
} | ||
|
||
|
@@ -27,7 +32,7 @@ const exit = async (code = 0) => { | |
debug('about to exit with code', code) | ||
|
||
if (hasCtx()) { | ||
await getCtx().lifecycleManager.mainProcessWillDisconnect().catch((err) => { | ||
await getCtx().lifecycleManager.mainProcessWillDisconnect().catch((err: any) => { | ||
debug('mainProcessWillDisconnect errored with: ', err) | ||
}) | ||
} | ||
|
@@ -37,14 +42,14 @@ const exit = async (code = 0) => { | |
span?.setAttribute('exitCode', code) | ||
span?.end() | ||
|
||
await telemetry.shutdown().catch((err) => { | ||
await telemetry.shutdown().catch((err: any) => { | ||
debug('telemetry shutdown errored with: ', err) | ||
}) | ||
|
||
return process.exit(code) | ||
} | ||
|
||
const showWarningForInvalidConfig = (options) => { | ||
const showWarningForInvalidConfig = (options: any) => { | ||
const publicConfigKeys = getPublicConfigKeys() | ||
const invalidConfigOptions = require('lodash').keys(options.config).reduce((invalid, option) => { | ||
if (!publicConfigKeys.find((configKey) => configKey === option)) { | ||
|
@@ -63,7 +68,7 @@ const exit0 = () => { | |
return exit(0) | ||
} | ||
|
||
const exitErr = (err) => { | ||
const exitErr = (err: any) => { | ||
// log errors to the console | ||
// and potentially raygun | ||
// and exit with 1 | ||
|
@@ -77,12 +82,12 @@ const exitErr = (err) => { | |
}) | ||
} | ||
|
||
module.exports = { | ||
export = { | ||
isCurrentlyRunningElectron () { | ||
return require('./util/electron-app').isRunning() | ||
}, | ||
|
||
runElectron (mode, options) { | ||
runElectron (mode: Mode, options: any) { | ||
// wrap all of this in a promise to force the | ||
// promise interface - even if it doesn't matter | ||
// in dev mode due to cp.spawn | ||
|
@@ -107,7 +112,7 @@ module.exports = { | |
debug('starting Electron') | ||
const cypressElectron = require('@packages/electron') | ||
|
||
const fn = (code) => { | ||
const fn = (code: number) => { | ||
// juggle up the totalFailed since our outer | ||
// promise is expecting this object structure | ||
debug('electron finished with', code) | ||
|
@@ -144,7 +149,7 @@ module.exports = { | |
options = argsUtils.toObject(argv) | ||
|
||
showWarningForInvalidConfig(options) | ||
} catch (argumentsError) { | ||
} catch (argumentsError: any) { | ||
debug('could not parse CLI arguments: %o', argv) | ||
|
||
// note - this is promise-returned call | ||
|
@@ -153,6 +158,7 @@ module.exports = { | |
|
||
debug('from argv %o got options %o', argv, options) | ||
|
||
// @ts-expect-error TODO: Fix type that says attachRecordKey is not a function | ||
telemetry.exporter()?.attachRecordKey(options.key) | ||
|
||
if (options.headless) { | ||
|
@@ -202,14 +208,14 @@ module.exports = { | |
}) | ||
}, | ||
|
||
startInMode (mode, options) { | ||
startInMode (mode: Mode, options: any) { | ||
debug('starting in mode %s with options %o', mode, options) | ||
|
||
switch (mode) { | ||
case 'version': | ||
return require('./modes/pkg')(options) | ||
.get('version') | ||
.then((version) => { | ||
.then((version: any) => { | ||
return console.log(version) // eslint-disable-line no-console | ||
}).then(exit0) | ||
.catch(exitErr) | ||
|
@@ -221,7 +227,7 @@ module.exports = { | |
|
||
case 'smokeTest': | ||
return this.runElectron(mode, options) | ||
.then((pong) => { | ||
.then((pong: any) => { | ||
if (!this.isCurrentlyRunningElectron()) { | ||
return pong | ||
} | ||
|
@@ -236,7 +242,7 @@ module.exports = { | |
|
||
case 'returnPkg': | ||
return require('./modes/pkg')(options) | ||
.then((pkg) => { | ||
.then((pkg: any) => { | ||
return console.log(JSON.stringify(pkg)) // eslint-disable-line no-console | ||
}).then(exit0) | ||
.catch(exitErr) | ||
|
@@ -250,7 +256,7 @@ module.exports = { | |
// run headlessly and exit | ||
// with num of totalFailed | ||
return this.runElectron(mode, options) | ||
.then((results) => { | ||
.then((results: any) => { | ||
if (results.runs) { | ||
const isCanceled = results.runs.filter((run) => run.skippedSpec).length | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { toNumber } from 'lodash' | ||
import Promise from 'bluebird' | ||
|
||
export = (options) => { | ||
return Promise.try(() => { | ||
return toNumber(options.exitWithCode) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Promise from 'bluebird' | ||
import pkg from '@packages/root' | ||
|
||
export = () => { | ||
return Promise.resolve(pkg) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw where we set this null in another file, so this is possible