Skip to content

Commit

Permalink
Added TypeScript type checker + Fixed type errors. (#5780)
Browse files Browse the repository at this point in the history
* Added type_check.js

* Now checks cli, too.

* Ignored a line that should fail.

* Removed cli shims and post-install.

* Updated @types/chai to fix type error.

* Fixed keyboard type errors.

* Updated typescript to 3.7.2 to fix window.Node error in dom/document.

* Removed tsconfig errors that caused type errors in reporter and runner.

* Ignored error test by dtslint. Becaust it's done by type_check.js

* Added npm command.

* Added it to CI.

* Added skipLibCheck option.

* Removed checking chai folder existence.

copy of chai is unnecessary.

* Added 'ignore-progress' option for CI.

* Show success message when type check is finished successfully.

* Use ignore-progress option on CI.

* Moved type definitions from devDependencies to dependencies.

* Fixed new type errors after rebase.

* Updated type errors.

* Removed cli. Because its types are checked by dtslint.

* type_check -> type-check for consistency.

* Updated json-schema.

* Updated blob-util.

* Fix wrong command in CI.

* Revert "Updated blob-util."

This reverts commit e46549a.
Because it's a breaking change.

* Remove copies of @types if exists.

* Fix stream buffer type error.

* Fix type errors in ui-components.

* Fix type failure.

* Fix lint error.

* Fix type errors

* Regenerate yarn.lock

* Fix type error.

* Fix type failures.

Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
  • Loading branch information
3 people committed Mar 17, 2020
1 parent 296c3b8 commit ee494d0
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 332 deletions.
5 changes: 2 additions & 3 deletions circle.yml
Expand Up @@ -318,11 +318,10 @@ jobs:
- run:
command: ls -la types
working_directory: cli
- run:
command: ls -la chai
working_directory: cli/types
- run:
command: yarn lerna exec --scope cypress "yarn dtslint"
- run:
command: yarn type-check --ignore-progress
- store-npm-logs

"server-unit-tests":
Expand Down
20 changes: 10 additions & 10 deletions cli/package.json
Expand Up @@ -22,6 +22,16 @@
"dependencies": {
"@cypress/listr-verbose-renderer": "0.4.1",
"@cypress/xvfb": "1.2.4",
"@types/blob-util": "1.3.3",
"@types/bluebird": "3.5.29",
"@types/chai": "4.2.7",
"@types/chai-jquery": "1.1.40",
"@types/jquery": "3.3.31",
"@types/lodash": "4.14.149",
"@types/minimatch": "3.0.3",
"@types/mocha": "5.2.7",
"@types/sinon": "7.5.1",
"@types/sinon-chai": "3.2.3",
"@types/sizzle": "2.3.2",
"arch": "2.1.1",
"bluebird": "3.7.2",
Expand Down Expand Up @@ -60,16 +70,6 @@
"devDependencies": {
"@cypress/sinon-chai": "1.1.0",
"@packages/root": "*",
"@types/blob-util": "1.3.3",
"@types/bluebird": "3.5.29",
"@types/chai": "4.2.7",
"@types/chai-jquery": "1.1.40",
"@types/jquery": "3.3.31",
"@types/lodash": "4.14.149",
"@types/minimatch": "3.0.3",
"@types/mocha": "5.2.7",
"@types/sinon": "7.5.1",
"@types/sinon-chai": "3.2.3",
"babel-cli": "6.26.0",
"babel-preset-es2015": "6.24.1",
"chai": "3.5.0",
Expand Down
90 changes: 27 additions & 63 deletions cli/scripts/post-install.js
@@ -1,64 +1,28 @@
#!/usr/bin/env node

const { includeTypes } = require('./utils')
const shell = require('shelljs')
const { join } = require('path')
const resolvePkg = require('resolve-pkg')

shell.set('-v') // verbose
shell.set('-e') // any error is fatal

// We include the TypeScript definitions for the bundled 3rd party tools
// thus we need to copy them from "dev" dependencies into our types folder
// and we need to sometimes tweak these types files to use relative paths
// This ensures that globals like Cypress.$, Cypress._ etc are property typed
// yet we do not install "@types/.." packages with "npm install cypress"
// because they can conflict with user's own libraries

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

shell.cp('-R', source, 'types')
const fs = require('../lib/fs')
const path = require('path')

/**
* https://github.com/cypress-io/cypress/pull/5780
* Folder names in "node_modules/@types" that were copied to cli/types to generate index.d.ts.
* They cause type errors in type checker. So, they should be removed.
*/
const includeTypes = [
'blob-util',
'bluebird',
'lodash',
'mocha',
'minimatch',
'sinon',
'sinon-chai',
'chai',
'chai-jquery',
'jquery',
]

includeTypes.forEach((t) => {
const dir = path.join(__dirname, '../types', t)

if (fs.existsSync(dir)) {
fs.removeSync(dir)
}
})

// 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 = join('types', 'jquery', 'dist')

shell.rm('-rf', typesJqueryDistFolder)

// fix paths to Chai, jQuery and other types to be relative
shell.sed(
'-i',
'<reference types="chai" />',
'<reference path="../chai/index.d.ts" />',
join('types', 'chai-jquery', 'index.d.ts'),
)

shell.sed(
'-i',
'<reference types="jquery" />',
'<reference path="../jquery/index.d.ts" />',
join('types', 'chai-jquery', 'index.d.ts'),
)

const sinonChaiFilename = join('types', 'sinon-chai', 'index.d.ts')

shell.sed(
'-i',
'<reference types="chai" />',
'<reference path="../chai/index.d.ts" />',
sinonChaiFilename,
)

// also use relative import via path for sinon-chai
// there is reference comment line we need to fix to be relative
shell.sed(
'-i',
'<reference types="sinon" />',
'<reference path="../sinon/index.d.ts" />',
sinonChaiFilename,
)

// and an import sinon line to be changed to relative path
shell.sed('-i', 'from \'sinon\';', 'from \'../sinon\';', sinonChaiFilename)
8 changes: 0 additions & 8 deletions cli/scripts/start-build.js
@@ -1,7 +1,5 @@
#!/usr/bin/env node

const { includeTypes } = require('./utils')
const { join } = require('path')
const shell = require('shelljs')

shell.set('-v') // verbose
Expand All @@ -15,12 +13,6 @@ shell.cp('NPM_README.md', 'build/README.md')
shell.cp('.release.json', 'build/.release.json')
// copies our typescript definitions
shell.cp('-R', 'types/*.ts', 'build/types/')
// copies 3rd party typescript definitions
includeTypes.forEach((folder) => {
const source = join('types', folder)

shell.cp('-R', source, 'build/types')
})

shell.exec('babel lib -d build/lib')
shell.exec('babel index.js -o build/index.js')
19 changes: 0 additions & 19 deletions cli/scripts/utils.js

This file was deleted.

13 changes: 0 additions & 13 deletions cli/types/cy-blob-util.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions cli/types/cy-bluebird.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions cli/types/cy-chai.d.ts

This file was deleted.

96 changes: 0 additions & 96 deletions cli/types/cy-minimatch.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions cli/types/cy-moment.d.ts

This file was deleted.

3 comments on commit ee494d0

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ee494d0 Mar 17, 2020

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/linux-x64/circle-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-282910/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/circle-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-282855/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ee494d0 Mar 17, 2020

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/darwin-x64/circle-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-282985/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/circle-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-282919/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ee494d0 Mar 17, 2020

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.2.1/win32-ia32/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.2.1/appveyor-develop-ee494d04ee532edec41f227ced0c639b3db78f5c-31513187/cypress.tgz

Please sign in to comment.