server decaf cleanup

cleanup
This commit is contained in:
Zach Bloomquist
2020-06-04 13:35:05 -04:00
parent e7d1f313b0
commit fe785749e8
48 changed files with 116 additions and 546 deletions

View File

@@ -10,7 +10,7 @@ The error we received was:
Cannot find module '/foo/bar/.projects/e2e/node_modules/module-does-not-exist'
Require stack:
- lib/reporter.coffee
- lib/reporter.js
- lib/project.js
- lib/modes/run.js
- lib/modes/index.js

View File

@@ -1,15 +1,3 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let intervals
const _ = require('lodash')
const os = require('os')
const debug = require('debug')('cypress:server:api')
@@ -17,19 +5,17 @@ const request = require('@cypress/request-promise')
const errors = require('@cypress/request-promise/errors')
const Promise = require('bluebird')
const humanInterval = require('human-interval')
const {
agent,
} = require('@packages/network')
const { agent } = require('@packages/network')
const pkg = require('@packages/root')
const machineId = require('./util/machine_id')
const routes = require('./util/routes')
const system = require('./util/system')
const cache = require('./cache')
const THIRTY_SECONDS = humanInterval('30 seconds')
const SIXTY_SECONDS = humanInterval('60 seconds')
const TWO_MINUTES = humanInterval('2 minutes')
let intervals
let DELAYS = [
THIRTY_SECONDS,
SIXTY_SECONDS,
@@ -122,8 +108,8 @@ const tagError = function (err) {
// retry on timeouts, 5xx errors, or any error without a status code
const isRetriableError = (err) => {
return (err instanceof Promise.TimeoutError) ||
(500 <= err.statusCode && err.statusCode < 600) ||
(err.statusCode == null)
(500 <= err.statusCode && err.statusCode < 600) ||
(err.statusCode == null)
}
module.exports = {

View File

@@ -1,15 +1,4 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const path = require('path')
const Promise = require('bluebird')
const fs = require('./util/fs')
const appData = require('./util/app_data')

View File

@@ -1,13 +1,3 @@
/* eslint-disable
prefer-rest-params,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _write = process.stdout.write
const _log = process.log
@@ -18,19 +8,11 @@ const restore = function () {
}
const stdout = function () {
// always restore right when we start capturing
// restore()
const logs = []
// lazily backup write to enable
// injection
const {
write,
} = process.stdout
const {
log,
} = process
// lazily backup write to enable injection
const { write } = process.stdout
const { log } = process
// electron adds a new process.log
// method for windows instead of process.stdout.write
@@ -39,6 +21,7 @@ const stdout = function () {
process.log = function (str) {
logs.push(str)
// eslint-disable-next-line prefer-rest-params
return log.apply(this, arguments)
}
}
@@ -46,6 +29,7 @@ const stdout = function () {
process.stdout.write = function (str) {
logs.push(str)
// eslint-disable-next-line prefer-rest-params
return write.apply(this, arguments)
}

View File

@@ -1,21 +1,6 @@
/* eslint-disable
default-case,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const R = require('ramda')
const la = require('lazy-ass')
const path = require('path')
const check = require('check-more-types')
const Promise = require('bluebird')
const deepDiff = require('return-deep-diff')
const errors = require('./errors')
@@ -42,7 +27,6 @@ const CYPRESS_SPECIAL_ENV_VARS = [
const dashesOrUnderscoresRe = /^(_-)+/
const oneOrMoreSpacesRe = /\s+/
const everythingAfterFirstEqualRe = /=(.+)/
const toWords = (str) => {
return str.trim().split(oneOrMoreSpacesRe)
@@ -257,6 +241,7 @@ const validateNoBreakingConfig = (cfg) => {
return errors.throw('RENAMED_CONFIG_OPTION', key, 'trashAssetsBeforeRuns')
case 'videoRecording':
return errors.throw('RENAMED_CONFIG_OPTION', key, 'video')
default:
}
}
})
@@ -312,7 +297,7 @@ const utils = {
// null - if there is an error finding the file
discoverModuleFile (options) {
debug('discover module file %o', options)
const { filename, projectRoot, isDefault } = options
const { filename, isDefault } = options
if (!isDefault) {
// they have it explicitly set, so it should be there
@@ -524,11 +509,12 @@ module.exports = {
})
},
updateWithPluginValues (cfg, overrides = {}) {
// diff the overrides with cfg
// including nested objects (env)
debug('starting config %o', cfg)
debug('overrides %o', overrides)
updateWithPluginValues (cfg, overrides) {
if (!overrides) {
overrides = {}
}
debug('updateWithPluginValues %o', { cfg, overrides })
// make sure every option returned from the plugins file
// passes our validation functions
@@ -789,8 +775,6 @@ module.exports = {
})
.then((result) => {
if (result === null) {
const configFile = obj.configFile || CONFIG_DEFAULTS.configFile
return errors.throw('PLUGINS_FILE_ERROR', path.resolve(obj.projectRoot, pluginsFile))
}

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const debug = require('debug')('cypress:server:controllers:client')
const socketIo = require('@packages/socket')

View File

@@ -1,14 +1,3 @@
/* eslint-disable
brace-style,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const R = require('ramda')
const path = require('path')
@@ -17,7 +6,6 @@ const cwd = require('../cwd')
const glob = require('../util/glob')
const specsUtil = require('../util/specs')
const pathHelpers = require('../util/path_helpers')
const CacheBuster = require('../util/cache_buster')
const debug = require('debug')('cypress:server:controllers')
const { escapeFilenameInUrl } = require('../util/escape_filename')
@@ -87,8 +75,8 @@ module.exports = {
return true
}).then(R.tap((specs) => {
return debug('filtered __all specs %o', specs)
})).map((spec) => // grab the name of each
{
})).map((spec) => {
// grab the name of each
return spec.absolute
}).map(convertSpecPath)
}

View File

@@ -1,14 +1,3 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const send = require('send')
const reporter = require('@packages/reporter/lib/resolve-dist')

View File

@@ -1,15 +1,4 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const cache = require('../cache')
const send = require('send')
const os = require('os')
const fs = require('../util/fs')

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const send = require('send')
const staticPkg = require('@packages/static')

View File

@@ -1,15 +1,3 @@
/* eslint-disable
brace-style,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const mime = require('mime')
const Promise = require('bluebird')
@@ -124,9 +112,8 @@ module.exports = {
},
parseContentType (response) {
const ret = (type) => //+ "; charset=utf-8"
{
return mime.getType(type)
const ret = (type) => {
return mime.getType(type) //+ "; charset=utf-8"
}
if (isValidJSON(response)) {

View File

@@ -1,16 +1,8 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const path = require('path')
// helper for resolving to the current working directory
// since electron does not play nice with process.cwd()
// this function should always return path.dirname('package.json')
const appPath = (function () {
// if lib is our basename then we haven't
// been concatted or moved and we need to

View File

@@ -1,22 +1,11 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
require('./util/fs')
const os = require('os')
//
// NOTE
//
// by loading "./cwd" we are changing the current working directory
// NOTE: by loading "./cwd" we are changing the current working directory
// to the "packages/server" folder
const cwd = require('./cwd')
require('./cwd')
const Promise = require('bluebird')
const debug = require('debug')('cypress:server')
@@ -48,7 +37,7 @@ if (env === 'development') {
Promise.config(config)
// note: we print error in development mode only
// NOTE: errors are printed in development mode only
try {
// i wish we didn't have to do this but we have to append
// these command line switches immediately

View File

@@ -1,17 +1,4 @@
/* eslint-disable
default-case,
no-case-declarations,
no-console,
no-const-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS203: Remove `|| {}` from converted for-own loops
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
/* eslint-disable no-console */
const _ = require('lodash')
const strip = require('strip-ansi')
const chalk = require('chalk')
@@ -91,6 +78,9 @@ const isCypressErr = (err) => {
}
const getMsgByType = function (type, arg1 = {}, arg2, arg3) {
// NOTE: declarations in case blocks are forbidden so we declare them up front
let filePath; let err; let msg; let str
switch (type) {
case 'CANNOT_TRASH_ASSETS':
return `\
@@ -131,7 +121,7 @@ Your project has set the configuration option: \`chromeWebSecurity: false\`
This option will not have an effect in ${_.capitalize(arg1)}. Tests that rely on web security being disabled will not run as expected.\
`
case 'BROWSER_NOT_FOUND_BY_NAME':
let str = `\
str = `\
Can't run because you've entered an invalid browser name.
Browser: '${arg1}' was not found on your system or is not supported by Cypress.
@@ -159,7 +149,7 @@ See https://on.cypress.io/migration-guide for more information on breaking chang
return str
case 'BROWSER_NOT_FOUND_BY_PATH':
const msg = `\
msg = `\
We could not identify a known browser at the path you provided: \`${arg1}\`
The output from the command we ran was:\
@@ -531,8 +521,8 @@ Can't run project because port is currently in use: ${chalk.blue(arg1)}
${chalk.yellow('Assign a different port with the \'--port <port>\' argument or shut down the other running process.')}\
`
case 'ERROR_READING_FILE':
const filePath = `\`${arg1}\``
const err = `\`${arg2}\``
filePath = `\`${arg1}\``
err = `\`${arg2}\``
return `\
Error reading from: ${chalk.blue(filePath)}
@@ -1022,6 +1012,7 @@ Enable write permissions to this directory to ensure screenshots and videos are
If you don't require screenshots or videos to be stored you can safely ignore this warning.\
`
default:
}
}

View File

@@ -1,17 +1,6 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const Promise = require('bluebird')
const pkg = require('@packages/root')
const path = require('path')
const api = require('./api')
const user = require('./user')
const system = require('./util/system')
@@ -20,7 +9,6 @@ const system = require('./util/system')
// data in the path
const pathRe = /'?((\/|\\+|[a-z]:\\)[^\s']+)+'?/ig
const pathSepRe = /[\/\\]+/
const fileNameRe = /[^\s'/]+\.\w+:?\d*$/i
const stripPath = (text) => {
return (text || '').replace(pathRe, (path) => {
const fileName = _.last(path.split(pathSepRe)) || ''

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const Promise = require('bluebird')
const execa = require('execa')
const R = require('ramda')
@@ -33,8 +26,8 @@ module.exports = {
log('in folder:', projectRoot)
return execa.shell(cmd, { cwd, env, shell })
// do we want to return all fields returned by execa?
.then((result) => {
// do we want to return all fields returned by execa?
result.shell = shell
result.cmd = cmd

View File

@@ -1,13 +1,3 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
// TODO: move this to packages/core-file-server
const _ = require('lodash')
@@ -16,7 +6,6 @@ const url = require('url')
const http = require('http')
const path = require('path')
const send = require('send')
const errors = require('./errors')
const allowDestroy = require('./util/server_destroy')
const random = require('./util/random')
const networkFailures = require('./util/network_failures')

View File

@@ -1,24 +1,10 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const path = require('path')
const Promise = require('bluebird')
const fs = require('./util/fs')
module.exports = {
readFile (projectRoot, file, options = {}) {
const filePath = path.resolve(projectRoot, file)
const readFn = path.extname(filePath) === '.json' ?
fs.readJsonAsync
:
fs.readFileAsync
const readFn = path.extname(filePath) === '.json' ? fs.readJsonAsync : fs.readFileAsync
return readFn(filePath, options.encoding || 'utf8')
.then((contents) => {

View File

@@ -1,21 +1,9 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const path = require('path')
const check = require('syntax-error')
const debug = require('debug')('cypress:server:fixture')
const coffee = require('../../../packages/coffee')
const Promise = require('bluebird')
const jsonlint = require('jsonlint')
const cwd = require('./cwd')
const errors = require('./errors')
const fs = require('./util/fs')
const glob = require('./util/glob')
@@ -38,10 +26,6 @@ const extensions = [
const queue = {}
const lastCharacterIsNewLine = (str) => {
return str[str.length - 1] === '\n'
}
const friendlyJsonParse = function (s) {
jsonlint.parse(s) // might throw good error
@@ -59,8 +43,6 @@ module.exports = {
.then(function () {
debug('fixture exact name exists', p)
const ext = path.extname(fixture)
return this.parseFile(p, fixture, options)
}).catch(function (e) {
if (e.code !== 'ENOENT') {

View File

@@ -1,17 +1,5 @@
/* eslint-disable
brace-style,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const {
dialog,
} = require('electron')
const { dialog } = require('electron')
module.exports = {
show () {
@@ -29,9 +17,9 @@ module.exports = {
}
return dialog.showOpenDialog(props)
.then((obj) => // return the first path since there can only ever
// be a single directory selection
{
.then((obj) => {
// return the first path since there can only ever
// be a single directory selection
return _.get(obj, ['filePaths', 0])
})
},

View File

@@ -1,16 +1,4 @@
/* eslint-disable
no-case-declarations,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
/* eslint-disable no-case-declarations */
const _ = require('lodash')
const ipc = require('electron').ipcMain
const { shell, clipboard } = require('electron')
@@ -22,7 +10,6 @@ const pkg = require('./package')
const logs = require('./logs')
const auth = require('./auth')
const Windows = require('./windows')
const api = require('../api')
const open = require('../util/open')
const user = require('../user')
const errors = require('../errors')
@@ -356,9 +343,9 @@ const handleEvent = function (options, bus, event, id, type, arg) {
.catch((err) => {
err.type = _.get(err, 'statusCode') === 403 ?
'ALREADY_MEMBER'
: (_.get(err, 'statusCode') === 422) && /existing/.test(__guard__(err.errors != null ? err.errors.userId : undefined, (x) => {
: (_.get(err, 'statusCode') === 422) && /existing/.test(err.errors && err.errors.userId, (x) => {
return x.join('')
})) ?
}) ?
'ALREADY_REQUESTED'
:
err.type || 'UNKNOWN'
@@ -426,7 +413,3 @@ module.exports = {
},
}
function __guard__ (value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined
}

View File

@@ -1,13 +1,3 @@
/* eslint-disable
no-console,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const chalk = require('chalk')
const logger = require('../logger')
@@ -40,6 +30,7 @@ module.exports = {
const str = JSON.stringify(log)
const color = (i % 2) === 0 ? 'cyan' : 'yellow'
// eslint-disable-next-line no-console
return console.log(chalk[color](str))
})
})

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const Promise = require('bluebird')
const json = require('@packages/root')

View File

@@ -1,29 +1,10 @@
/* eslint-disable
brace-style,
no-unused-vars,
prefer-rest-params,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const uri = require('url')
const Promise = require('bluebird')
const cyDesktop = require('@packages/desktop-gui')
const extension = require('@packages/extension')
const contextMenu = require('electron-context-menu')
const {
BrowserWindow,
} = require('electron')
const { BrowserWindow } = require('electron')
const debug = require('debug')('cypress:server:windows')
const cwd = require('../cwd')
const user = require('../user')
const savedState = require('../saved_state')
let windows = {}
@@ -42,15 +23,6 @@ const getByType = (type) => {
return windows[type]
}
const getCookieUrl = (props) => {
return extension.getCookieUrl(props)
}
const firstOrNull = (cookies) => // normalize into null when empty array
{
return cookies[0] != null ? cookies[0] : null
}
const setWindowProxy = function (win) {
if (!process.env.HTTP_PROXY) {
return
@@ -175,18 +147,18 @@ module.exports = {
const win = this._newBrowserWindow(options)
win.on('blur', function () {
return options.onBlur.apply(win, arguments)
win.on('blur', function (...args) {
return options.onBlur.apply(win, args)
})
win.on('focus', function () {
return options.onFocus.apply(win, arguments)
win.on('focus', function (...args) {
return options.onFocus.apply(win, args)
})
win.once('closed', function () {
win.once('closed', function (...args) {
win.removeAllListeners()
return options.onClose.apply(win, arguments)
return options.onClose.apply(win, args)
})
// the webview loses focus on navigation, so we
@@ -200,12 +172,12 @@ module.exports = {
})
}
win.webContents.on('crashed', function () {
return options.onCrashed.apply(win, arguments)
win.webContents.on('crashed', function (...args) {
return options.onCrashed.apply(win, args)
})
win.webContents.on('new-window', function () {
return options.onNewWindow.apply(win, arguments)
win.webContents.on('new-window', function (...args) {
return options.onNewWindow.apply(win, args)
})
ts = options.trackState
@@ -267,9 +239,8 @@ module.exports = {
win.webContents.id = _.uniqueId('webContents')
win.once('closed', () => // slice the window out of windows reference
{
return delete windows[options.type]
win.once('closed', () => {
delete windows[options.type]
})
// enable our url to be a promise

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
require('./environment')
const konfig = require('konfig')

View File

@@ -1,5 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
// lightweight logging for Node
// only shows log messages if running with
// DEBUG=cypress:start ...

View File

@@ -1,14 +1,4 @@
/* eslint-disable
no-console,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
/* eslint-disable no-console */
const path = require('path')
const _ = require('lodash')
const Promise = require('bluebird')

View File

@@ -1,34 +1,22 @@
/* eslint-disable
no-console,
no-undef,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
require('../cwd')
const _ = require('lodash')
const EE = require('events')
const path = require('path')
const debug = require('debug')('cypress:server:preprocessor')
const Promise = require('bluebird')
const appData = require('../util/app_data')
const cwd = require('../cwd')
const plugins = require('../plugins')
const resolve = require('./resolve')
const errorMessage = function (err = {}) {
return ((((left1 = err.stack != null ? err.stack : err.annotated) != null ? left1 : err.message) || err.toString()))
return (err.stack || err.annotated || err.message || err.toString())
.replace(/\n\s*at.*/g, '')
.replace(/From previous event:\n?/g, '')
}
const clientSideError = function (err) {
// eslint-disable-next-line no-console
console.log(err.message)
err = errorMessage(err)

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const EE = require('events')
const debug = require('debug')('cypress:server:plugins')

View File

@@ -54,7 +54,7 @@ class Project extends EE {
}
this.projectRoot = path.resolve(projectRoot)
this.watchers = Watchers()
this.watchers = new Watchers()
this.cfg = null
this.spec = null
this.browser = null
@@ -68,7 +68,7 @@ class Project extends EE {
open (options = {}) {
debug('opening project instance %s', this.projectRoot)
debug('project open options %o', options)
this.server = Server()
this.server = new Server()
_.defaults(options, {
report: false,

View File

@@ -1,12 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let setContext
require('./environment')
const _ = require('lodash')
@@ -20,6 +11,8 @@ const replServer = repl.start({
prompt: '> ',
})
let setContext
// preserve the repl history
history(replServer, path.join(process.env.HOME, '.node_history'))

View File

@@ -1,17 +1,3 @@
/* eslint-disable
no-case-declarations,
no-self-assign,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const path = require('path')
// mocha-* is used to allow us to have later versions of mocha specified in devDependencies
@@ -25,8 +11,6 @@ const debug = require('debug')('cypress:server:reporter')
const Promise = require('bluebird')
const { overrideRequire } = require('./override_require')
const STATS = 'suites tests passes pending failures start end duration'.split(' ')
// override calls to `require('mocha*')` when to always resolve with a mocha we control
// otherwise mocha will be resolved from project's node_modules and might not work with our code
const customReporterMochaPath = path.dirname(require.resolve('mocha-7.0.1'))
@@ -135,10 +119,9 @@ const mergeRunnable = (eventName) => {
}
const safelyMergeRunnable = function (hookProps, runnables) {
let runnable
const { hookId, title, hookName, body, type } = hookProps
if (!(runnable = runnables[hookId])) {
if (!runnables[hookId]) {
runnables[hookId] = {
hookId,
type,
@@ -158,9 +141,6 @@ const mergeErr = function (runnable, runnables, stats) {
test.err = runnable.err
test.state = 'failed'
if (test.duration == null) {
test.duration = test.duration
}
if (runnable.type === 'hook') {
test.failedFromHookId = runnable.hookId
@@ -223,7 +203,11 @@ class Reporter {
this.reporterOptions = reporterOptions
}
setRunnables (rootRunnable = { title: '' }) {
setRunnables (rootRunnable) {
if (!rootRunnable) {
rootRunnable = { title: '' }
}
// manage stats ourselves
this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, skipped: 0, failures: 0 }
this.runnables = {}
@@ -246,6 +230,7 @@ class Reporter {
const runnable = (() => {
switch (type) {
case 'suite':
// eslint-disable-next-line no-case-declarations
const suite = createSuite(runnableProps, parent)
suite.tests = _.map(runnableProps.tests, (testProps) => {

View File

@@ -1,14 +1,3 @@
/* eslint-disable
brace-style,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const mime = require('mime')
const path = require('path')
@@ -22,7 +11,6 @@ let debug = require('debug')('cypress:server:screenshot')
const plugins = require('./plugins')
const fs = require('./util/fs')
const glob = require('./util/glob')
const pathHelpers = require('./util/path_helpers')
const RUNNABLE_SEPARATOR = ' -- '
const pathSeparatorRe = /[\\\/]/g
@@ -201,8 +189,8 @@ const clearMultipartState = function () {
multipartImages = []
}
const imagesMatch = (img1, img2) => // using Buffer::equals here
{
const imagesMatch = (img1, img2) => {
// using Buffer::equals here
return img1.bitmap.data.equals(img2.bitmap.data)
}
@@ -313,9 +301,9 @@ const ensureUniquePath = function (withoutExt, extension, num = 0) {
})
}
const sanitizeToString = (title) => // test titles may be values which aren't strings like
// null or undefined - so convert before trying to sanitize
{
const sanitizeToString = (title) => {
// test titles may be values which aren't strings like
// null or undefined - so convert before trying to sanitize
return sanitize(_.toString(title))
}

View File

@@ -1,16 +1,5 @@
/* eslint-disable
brace-style,
no-unused-vars,
prefer-rest-params,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
require('./cwd')
const _ = require('lodash')
const url = require('url')
const http = require('http')
@@ -21,7 +10,6 @@ const evilDns = require('evil-dns')
const isHtml = require('is-html')
const httpProxy = require('http-proxy')
const la = require('lazy-ass')
const check = require('check-more-types')
const httpsProxy = require('@packages/https-proxy')
const compression = require('compression')
const debug = require('debug')('cypress:server:server')
@@ -41,7 +29,6 @@ const statusCode = require('./util/status_code')
const headersUtil = require('./util/headers')
const allowDestroy = require('./util/server_destroy')
const { SocketWhitelist } = require('./util/socket_whitelist')
const cwd = require('./cwd')
const errors = require('./errors')
const logger = require('./logger')
const Socket = require('./socket')
@@ -58,9 +45,9 @@ const ALLOWED_PROXY_BYPASS_URLS = [
'/__cypress/static/favicon.ico',
]
const _isNonProxiedRequest = (req) => // proxied HTTP requests have a URL like: "http://example.com/foo"
// non-proxied HTTP requests have a URL like: "/foo"
{
const _isNonProxiedRequest = (req) => {
// proxied HTTP requests have a URL like: "http://example.com/foo"
// non-proxied HTTP requests have a URL like: "/foo"
return req.proxiedUrl.startsWith('/')
}
@@ -122,8 +109,6 @@ const notSSE = (req, res) => {
return (req.headers.accept !== 'text/event-stream') && compression.filter(req, res)
}
// currently not making use of event emitter
// but may do so soon
class Server {
constructor () {
if (!(this instanceof Server)) {
@@ -156,16 +141,11 @@ class Server {
// handle the proxied url in case
// we have not yet started our websocket server
app.use((req, res, next) => {
let m
setProxiedUrl(req)
// if we've defined some middlware
// then call this. useful in tests
m = this._middleware
if (m) {
m(req, res)
// useful for tests
if (this._middleware) {
this._middleware(req, res)
}
// always continue on
@@ -190,8 +170,8 @@ class Server {
return app
}
createRoutes () {
return require('./routes').apply(null, arguments)
createRoutes (...args) {
return require('./routes').apply(null, args)
}
getHttpServer () {
@@ -488,7 +468,7 @@ class Server {
return currentPromisePhase = fn()
}
this._urlResolver = (p = new Promise((resolve, reject, onCancel) => {
return this._urlResolver = (p = new Promise((resolve, reject, onCancel) => {
let urlFile
onCancel(() => {
@@ -554,9 +534,9 @@ class Server {
this._remoteVisitingUrl = false
const statusIs2xxOrAllowedFailure = () => // is our status code in the 2xx range, or have we disabled failing
// on status code?
{
const statusIs2xxOrAllowedFailure = () => {
// is our status code in the 2xx range, or have we disabled failing
// on status code?
return statusCode.isOk(incomingRes.statusCode) || options.failOnStatusCode === false
}

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const Promise = require('bluebird')
const debug = require('debug')('cypress:server:task')

View File

@@ -1,33 +1,14 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const debug = require('debug')('cypress:server:updater')
const semver = require('semver')
const request = require('@cypress/request')
const NwUpdater = require('node-webkit-updater')
const pkg = require('@packages/root')
const {
agent,
} = require('@packages/network')
const { agent } = require('@packages/network')
const cwd = require('./cwd')
const konfig = require('./konfig')
const { machineId } = require('./util/machine_id')
// backup the original cwd
const localCwd = cwd()
const osxAppRe = /\.app$/
const linuxAppRe = /Cypress$/i
NwUpdater.prototype.checkNewVersion = function (cb) {
const gotManifest = function (err, req, data) {
let e; let newVersion
@@ -146,7 +127,7 @@ class Updater {
}
static check (options = {}) {
return Updater().check(options)
return new Updater().check(options)
}
}

View File

@@ -1,16 +1,4 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const r = require('@cypress/request')
const rp = require('@cypress/request-promise')
const Promise = require('bluebird')
const fs = require('./util/fs')
module.exports = {

View File

@@ -1,10 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const debug = require('debug')('cypress:server:user')
const api = require('./api')
const cache = require('./cache')

View File

@@ -1,18 +1,6 @@
/* eslint-disable
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const _ = require('lodash')
const chokidar = require('chokidar')
const dependencyTree = require('dependency-tree')
const pathHelpers = require('./util/path_helpers')
class Watchers {
constructor () {

View File

@@ -160,7 +160,7 @@ describe "Routes", ->
httpsServer.start(8443),
## and open our cypress server
@server = Server(Watchers())
@server = new Server(new Watchers())
@server.open(cfg, project)
.spread (port) =>

View File

@@ -71,7 +71,7 @@ describe "Server", ->
httpsServer.start(8443),
## and open our cypress server
@server = Server()
@server = new Server()
@server.open(cfg)
.spread (port) =>

View File

@@ -30,7 +30,7 @@ describe "Web Sockets", ->
.then (@cfg) =>
@ws = new ws.Server({port: wsPort})
@server = Server()
@server = new Server()
@server.open(@cfg)
.then =>

View File

@@ -348,7 +348,7 @@ describe('Proxy Performance', function () {
// turn off morgan
config.morgan = false
cyServer = Server()
cyServer = new Server()
return cyServer.open(config)
}),

View File

@@ -5,7 +5,7 @@ snapshot = require("snap-shot-it")
describe "lib/reporter", ->
beforeEach ->
@reporter = Reporter()
@reporter = new Reporter()
@root = {
id: 'r1'

View File

@@ -28,7 +28,7 @@ describe "lib/server", ->
config.set({projectRoot: "/foo/bar/"})
.then (cfg) =>
@config = cfg
@server = Server()
@server = new Server()
@oldFileServer = @server._fileServer
@server._fileServer = @fileServer
@@ -191,9 +191,10 @@ describe "lib/server", ->
it "sets _socket and calls _socket#startListening", ->
@server.open(@config)
.then =>
@server.startWebsockets(1, 2, 3)
arg2 = {}
@server.startWebsockets(1, 2, arg2)
expect(@startListening).to.be.calledWith(@server.getHttpServer(), 1, 2, 3)
expect(@startListening).to.be.calledWith(@server.getHttpServer(), 1, 2, arg2)
context "#reset", ->
beforeEach ->
@@ -310,7 +311,7 @@ describe "lib/server", ->
context "#_onDomainSet", ->
beforeEach ->
@server = Server()
@server = new Server()
it "sets port to 443 when omitted and https:", ->
ret = @server._onDomainSet("https://staging.google.com/foo/bar")

View File

@@ -24,7 +24,7 @@ describe "lib/socket", ->
Fixtures.scaffold()
@todosPath = Fixtures.projectPath("todos")
@server = Server(@todosPath)
@server = new Server(@todosPath)
config.get(@todosPath)
.then (@cfg) =>

View File

@@ -10,13 +10,13 @@ _ = require("lodash")
describe "lib/updater", ->
context "interface", ->
it "returns an updater instance", ->
u = Updater({})
u = new Updater({})
expect(u).to.be.instanceof Updater
context "#getPackage", ->
beforeEach ->
pkg.foo = "bar"
@updater = Updater({})
@updater = new Updater({})
afterEach ->
delete pkg.foo
@@ -29,12 +29,12 @@ describe "lib/updater", ->
context "#getClient", ->
it "sets .client to new Updater", ->
u = Updater({})
u = new Updater({})
u.getClient()
expect(u.client).to.have.property("checkNewVersion")
it "returns .client if exists", ->
u = Updater({})
u = new Updater({})
client = u.getClient()
client2 = u.getClient()
expect(client).to.eq(client2)
@@ -43,7 +43,7 @@ describe "lib/updater", ->
beforeEach ->
@get = sinon.spy(request, "get")
@updater = Updater({})
@updater = new Updater({})
it "sends x-cypress-version", (done) ->
@updater.getClient().checkNewVersion =>
@@ -78,12 +78,12 @@ describe "lib/updater", ->
})
done()
return
context "#check", ->
beforeEach ->
@updater = Updater({quit: sinon.spy()})
@updater = new Updater({quit: sinon.spy()})
@updater.getClient()
sinon.stub(@updater.client, "checkNewVersion")

View File

@@ -13,7 +13,7 @@ describe "lib/watchers", ->
})
sinon.stub(chokidar, "watch").returns(@standardWatcher)
@watchers = Watchers()
@watchers = new Watchers()
it "returns instance of watcher class", ->
expect(@watchers).to.be.instanceof(Watchers)