Skip to content
Open
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
2 changes: 0 additions & 2 deletions cli/lib/VerboseRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dayjs from 'dayjs'
const formattedLog = (options: any, output: string): void => {
const timestamp = dayjs().format(options.dateFormat)

// eslint-disable-next-line no-console
console.log(`${chalk.dim(`[${timestamp}]`)} ${output}`)
}

Expand Down Expand Up @@ -40,7 +39,6 @@ const render = (tasks: any[], options: any): void => {
renderHelper(task, event, options)
},
(err: any) => {
// eslint-disable-next-line no-console
console.log(err)
},
)
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import runModule from './exec/run'
import util from './util'
import cliImport from './cli'

/**
/**
* Opens Cypress GUI
* @see https://on.cypress.io/module-api#cypress-open
*/
Expand Down
1 change: 0 additions & 1 deletion cli/lib/exec/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { start as spawnStart } from './spawn'
import util from '../util'
import state from '../tasks/state'
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/exec/xvfb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function isNeeded (): boolean {
return true
}

// async method, resolved with Boolean
// async method, resolved with Boolean
export async function verify (): Promise<boolean> {
try {
await xvfb.startAsync()
Expand Down
8 changes: 4 additions & 4 deletions cli/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ const logLevel = (): string => {

const error = (...messages: any[]): void => {
logs.push(messages.join(' '))
console.log(chalk.red(...messages)) // eslint-disable-line no-console
console.log(chalk.red(...messages))
}

const warn = (...messages: any[]): void => {
if (logLevel() === 'silent') return

logs.push(messages.join(' '))
console.log(chalk.yellow(...messages)) // eslint-disable-line no-console
console.log(chalk.yellow(...messages))
}

const log = (...messages: any[]): void => {
if (logLevel() === 'silent' || logLevel() === 'warn') return

logs.push(messages.join(' '))
console.log(...messages) // eslint-disable-line no-console
console.log(...messages)
}

const always = (...messages: any[]): void => {
logs.push(messages.join(' '))
console.log(...messages) // eslint-disable-line no-console
console.log(...messages)
}

// splits long text into lines and calls log()
Expand Down
32 changes: 16 additions & 16 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
"private": true,
"main": "dist/index.js",
"scripts": {
"build-cli": "rollup -c && yarn postbuild",
"prebuild": "yarn clean-cli-build && yarn postinstall && tsx ./scripts/prep-build-dir.ts",
"build": "rollup -c",
"postbuild": "yarn make-bin-executable && yarn sync-build-dist && yarn prepare-package-json && yarn bundle-ct-frameworks",
"build-cli": "rollup -c && yarn postbuild",
"bundle-ct-frameworks": "tsx ./scripts/bundle-ct-frameworks.ts",
"clean-cli-build": "rimraf build dist \"types/[!tests]*/\" types/net-stubbing.d.ts --glob",
"dtslint": "dtslint types",
"lint": "eslint",
"postinstall": "patch-package && tsx ./scripts/sync-typedefs.ts",
"prebuild": "yarn clean-cli-build && yarn postinstall && tsx ./scripts/prep-build-dir.ts",
"postbuild": "yarn make-bin-executable && yarn sync-build-dist && yarn prepare-package-json && yarn bundle-ct-frameworks",
"lint": "eslint",
"make-bin-executable": "tsx ./scripts/make-bin-executable.ts",
"prepare-package-json": "tsx ./scripts/prepare-package-json.ts",
"size": "t=\"cypress-v0.0.0.tgz\"; yarn pack --filename \"${t}\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"sync-build-dist": "tsx ./scripts/sync-build-dist.ts",
"test": "yarn test-unit",
"test-debug": "npx vitest --inspect-brk --no-file-parallelism --test-timeout=0",
"test-unit": "vitest run",
"types": "yarn dtslint",
"make-bin-executable": "tsx ./scripts/make-bin-executable.ts",
"sync-build-dist": "tsx ./scripts/sync-build-dist.ts",
"prepare-package-json": "tsx ./scripts/prepare-package-json.ts",
"bundle-ct-frameworks": "tsx ./scripts/bundle-ct-frameworks.ts"
"types": "yarn dtslint"
},
"dependencies": {
"@cypress/request": "^3.0.10",
Expand Down Expand Up @@ -62,8 +62,8 @@
"supports-color": "^8.1.1",
"systeminformation": "^5.31.1",
"tmp": "~0.2.4",
"tslib": "1.14.1",
"tree-kill": "1.2.2",
"tslib": "1.14.1",
"untildify": "^4.0.0",
"yauzl": "^2.10.0"
},
Expand All @@ -76,23 +76,22 @@
"@cypress/sinon-chai": "2.9.1",
"@cypress/svelte": "0.0.0-development",
"@cypress/vue": "0.0.0-development",
"@rollup/plugin-typescript": "^12.3.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-json": "^6.1.0",
"rollup": "^4.53.5",
"@packages/eslint-config": "0.0.0-development",
"@packages/root": "0.0.0-development",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-typescript": "^12.3.0",
"@types/bluebird": "3.5.33",
"@types/chai": "4.2.15",
"@types/chai-jquery": "1.1.43",
"@types/jquery": "3.3.31",
"@types/lodash": "4.17.21",
"@types/minimatch": "3.0.5",
"@types/mocha": "8.0.3",
"@types/shelljs": "^0.10.0",
"@types/sinon": "9.0.9",
"@types/sinon-chai": "3.2.12",
"@types/shelljs": "^0.10.0",
"dtslint": "4.2.1",
"eslint": "^9.31.0",
"execa-wrap": "1.4.0",
Expand All @@ -101,6 +100,7 @@
"nock": "13.2.9",
"resolve-pkg": "2.0.0",
"rimraf": "^6.1.2",
"rollup": "^4.53.5",
"semver": "^7.7.3",
"shelljs": "0.8.5",
"strip-ansi": "6.0.1",
Expand Down
97 changes: 52 additions & 45 deletions cli/scripts/sync-typedefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ shell.set('-e') // any error is fatal
// yet we do not install "@types/.." packages with "npm install cypress"
// because they can conflict with user's own libraries

fs.ensureDirSync(join(__dirname, '..', 'types'))

includeTypes.forEach((folder: string) => {
const source: string = resolvePkg(`@types/${folder}`, { cwd: __dirname })

fs.copySync(source, join(__dirname, '..', 'types', folder))
})

// jQuery v3.3.x includes "dist" folder that just references back to itself
// causing dtslint to think there are double definitions. Remove that folder.
const typesJqueryDistFolder: string = join('types', 'jquery', 'dist')

shell.rm('-rf', typesJqueryDistFolder)

/**
* Replaces "reference types=<n>" comment with "reference path=..." line.
* @param {string} typeName - like "chai" or "jquery"
Expand All @@ -53,46 +39,67 @@ function makeReferenceTypesCommentRelative (typeName: string, relativeTypesFileP
)
}

// fix paths to Chai, jQuery and other types to be relative
makeReferenceTypesCommentRelative('chai', '../chai/index.d.ts',
join('types', 'chai-jquery', 'index.d.ts'))
async function main (): Promise<void> {
await fs.ensureDir(join(__dirname, '..', 'types'))

for (const folder of includeTypes) {
const source: string = resolvePkg(`@types/${folder}`, { cwd: __dirname })

makeReferenceTypesCommentRelative('jquery', '../jquery/index.d.ts',
join('types', 'chai-jquery', 'index.d.ts'))
await fs.copy(source, join(__dirname, '..', 'types', folder))
}

const sinonChaiFilename: string = join('types', 'sinon-chai', 'index.d.ts')
// jQuery v3.3.x includes "dist" folder that just references back to itself
// causing dtslint to think there are double definitions. Remove that folder.
const typesJqueryDistFolder: string = join('types', 'jquery', 'dist')

makeReferenceTypesCommentRelative('chai', '../chai/index.d.ts', sinonChaiFilename)
shell.rm('-rf', typesJqueryDistFolder)

// also use relative import via path for sinon-chai
// there is reference comment line we need to fix to be relative
makeReferenceTypesCommentRelative('sinon', '../sinon/index.d.ts', sinonChaiFilename)
// fix paths to Chai, jQuery and other types to be relative
makeReferenceTypesCommentRelative('chai', '../chai/index.d.ts',
join('types', 'chai-jquery', 'index.d.ts'))

// and an import sinon line to be changed to relative path
shell.sed('-i', 'from "sinon";', 'from "../sinon";', sinonChaiFilename)
makeReferenceTypesCommentRelative('jquery', '../jquery/index.d.ts',
join('types', 'chai-jquery', 'index.d.ts'))

// copy experimental network stubbing type definitions
// so users can import: `import 'cypress/types/net-stubbing'`
fs.copySync(resolvePkg('@packages/net-stubbing/lib/external-types.ts'), 'types/net-stubbing.d.ts')
const sinonChaiFilename: string = join('types', 'sinon-chai', 'index.d.ts')

// https://github.com/cypress-io/cypress/issues/18069
// To avoid type clashes, some files should be commented out entirely by patch-package
// and uncommented here.
makeReferenceTypesCommentRelative('chai', '../chai/index.d.ts', sinonChaiFilename)

const filesToUncomment: string[] = [
'mocha/index.d.ts',
'jquery/JQuery.d.ts',
'jquery/legacy.d.ts',
'jquery/misc.d.ts',
]
// also use relative import via path for sinon-chai
// there is reference comment line we need to fix to be relative
makeReferenceTypesCommentRelative('sinon', '../sinon/index.d.ts', sinonChaiFilename)

filesToUncomment.forEach((file: string) => {
const filePath: string = join(__dirname, '../types', file)
const str: string = fs.readFileSync(filePath).toString()
// and an import sinon line to be changed to relative path
shell.sed('-i', 'from "sinon";', 'from "../sinon";', sinonChaiFilename)

const result: string = str.split('\n').map((line: string) => {
return line.startsWith('//z ') ? line.substring(4) : line
}).join('\n')
// copy experimental network stubbing type definitions
// so users can import: `import 'cypress/types/net-stubbing'`
await fs.copy(resolvePkg('@packages/net-stubbing/lib/external-types.ts'), 'types/net-stubbing.d.ts')

// https://github.com/cypress-io/cypress/issues/18069
// To avoid type clashes, some files should be commented out entirely by patch-package
// and uncommented here.

const filesToUncomment: string[] = [
'mocha/index.d.ts',
'jquery/JQuery.d.ts',
'jquery/legacy.d.ts',
'jquery/misc.d.ts',
]

for (const file of filesToUncomment) {
const filePath: string = join(__dirname, '../types', file)
const str: string = (await fs.readFile(filePath)).toString()

const result: string = str.split('\n').map((line: string) => {
return line.startsWith('//z ') ? line.substring(4) : line
}).join('\n')

await fs.writeFile(filePath, result)
}
}

fs.writeFileSync(filePath, result)
main().catch((err) => {
console.error(err)
process.exit(1)
})
1 change: 0 additions & 1 deletion cli/test/lib/exec/info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ vi.mock('../../../lib/tasks/state', async (importActual) => {
describe('exec info', () => {
const createStdoutCapture = () => {
const logs: string[] = []
// eslint-disable-next-line no-console
const originalOut = process.stdout.write

vi.spyOn(process.stdout, 'write').mockImplementation((strOrBugger: string | Uint8Array<ArrayBufferLike>) => {
Expand Down
1 change: 0 additions & 1 deletion cli/test/lib/tasks/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ vi.mock('../../../lib/util', async (importActual) => {
describe('lib/tasks/cache', () => {
const createStdoutCapture = () => {
const logs: string[] = []
// eslint-disable-next-line no-console
const originalOut = process.stdout.write

vi.spyOn(process.stdout, 'write').mockImplementation((strOrBugger: string | Uint8Array<ArrayBufferLike>) => {
Expand Down
9 changes: 5 additions & 4 deletions cli/test/lib/tasks/download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe('lib/tasks/download', function () {

const createStdoutCapture = () => {
const logs: string[] = []
// eslint-disable-next-line no-console
const originalOut = process.stdout.write

vi.spyOn(process.stdout, 'write').mockImplementation((strOrBugger: string | Uint8Array<ArrayBufferLike>) => {
Expand Down Expand Up @@ -294,10 +293,12 @@ describe('lib/tasks/download', function () {
let expectedFileSize: number
let onProgress: vi.Mock

beforeEach(function () {
expectedChecksum = hasha.fromFileSync(examplePath)
beforeEach(async function () {
expectedChecksum = await hasha.fromFile(examplePath)

expectedFileSize = fs.statSync(examplePath).size
const stat = await fs.stat(examplePath)

expectedFileSize = stat.size

onProgress = vi.fn().mockReturnValue(undefined)
debug('example file %s should have checksum %s and file size %d',
Expand Down
2 changes: 1 addition & 1 deletion cli/test/lib/tasks/state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('lib/tasks/state', function () {
const actualPath = (await vi.importActual<typeof import('path')>('path')).default

vi.mocked(path.resolve).mockImplementation((...args) => {
return actualPath.resolve.apply(actualPath, args)
return actualPath.resolve(...args)
})
})

Expand Down
1 change: 0 additions & 1 deletion cli/test/lib/tasks/unzip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ vi.mock('../../../lib/util', async (importActual) => {
describe('lib/tasks/unzip', function () {
const createStdoutCapture = () => {
const logs: string[] = []
// eslint-disable-next-line no-console
const originalOut = process.stdout.write

vi.spyOn(process.stdout, 'write').mockImplementation((strOrBugger: string | Uint8Array<ArrayBufferLike>) => {
Expand Down
4 changes: 3 additions & 1 deletion cli/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "node",
"types": ["node"]
"types": [
"node"
]
},
"include": [
"lib/**/*.mts"
Expand Down
2 changes: 1 addition & 1 deletion cli/types/cy-minimatch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ interface MinimatchOptions {
}

declare namespace Minimatch {
function minimatch(target: string, pattern: string, options?: MinimatchOptions): boolean
function minimatch (target: string, pattern: string, options?: MinimatchOptions): boolean
}
4 changes: 2 additions & 2 deletions cli/types/cypress-eventemitter.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Cypress, cy, Log inherits EventEmitter.
type EventEmitter2 = import("eventemitter2").EventEmitter2
type EventEmitter2 = import('eventemitter2').EventEmitter2

interface CyEventEmitter extends Omit<EventEmitter2, 'waitFor'> {
proxyTo: (cy: Cypress.cy) => null
Expand Down Expand Up @@ -30,4 +30,4 @@ interface NodeEventEmitter {

// We use the Buffer class for dealing with binary data, especially around the
// selectFile interface.
type BufferType = typeof import("buffer/").Buffer
type BufferType = typeof import('buffer/').Buffer
4 changes: 2 additions & 2 deletions cli/types/cypress-expect.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Cypress adds chai expect and assert to global
declare var expect: Chai.ExpectStatic
declare var assert: Chai.AssertStatic
declare let expect: Chai.ExpectStatic
declare let assert: Chai.AssertStatic
15 changes: 15 additions & 0 deletions cli/types/cypress-global-augmentation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Augments Window so that Cypress globals (Cypress, cy, expect, assert)
* are correctly typed when accessed as window.Cypress, window.cy, etc.
* Must be an external module so that declare global is allowed.
*/
export {}

declare global {
interface Window {
Cypress: Cypress.Cypress & CyEventEmitter
cy: Cypress.cy & CyEventEmitter
expect: Chai.ExpectStatic
assert: Chai.AssertStatic
}
}
4 changes: 2 additions & 2 deletions cli/types/cypress-global-vars.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cy.get('button').click()
cy.get('.result').contains('Expected text')
```
*/
declare var cy: Cypress.cy & CyEventEmitter
declare let cy: Cypress.cy & CyEventEmitter

/**
* Global variable `Cypress` holds common utilities and constants.
Expand All @@ -19,4 +19,4 @@ Cypress.version // => "1.4.0"
Cypress._ // => Lodash _
```
*/
declare var Cypress: Cypress.Cypress & CyEventEmitter
declare let Cypress: Cypress.Cypress & CyEventEmitter
Copy link

Choose a reason for hiding this comment

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

declare var to let breaks globalThis type access

High Severity

Changing declare var to declare let for cy, Cypress, expect, and assert in ambient declarations removes these globals from globalThis typing. In TypeScript, only declare var creates properties accessible on globalThis; declare let does not. This breaks code using globalThis.Cypress as a type reference — notably npm/react/src/createMount.ts and npm/react/src/types.ts which use globalThis.Cypress.Chainable<MountReturn> as return types. The test workaround using a type cast in cypress-tests.ts masks this regression rather than preserving the original behavior.

Additional Locations (1)

Fix in Cursor Fix in Web

Triggered by project rule: Overview

1 change: 1 addition & 0 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
/// <reference path="./cypress-global-vars.d.ts" />
/// <reference path="./cypress-type-helpers.d.ts" />
/// <reference path="./cypress-expect.d.ts" />
/// <reference path="./cypress-global-augmentation.d.ts" />
Loading
Loading