Skip to content

Commit

Permalink
fix: update cypress to Typescript 5 (#29568)
Browse files Browse the repository at this point in the history
* fix: update the monorepo to typescript 5

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* chore: updating v8 snapshot cache

* run ci to see problems [run ci]

* update vue-tsc and typings that conflict with update

* regen snapshot

* fix typescript errors ui test as stack trace behavior has changed

* fix server unit tests

* update cy.origin() spec based on stack traces and code frames

* update spec to include source map url

* run ci

* fix check-ts

* chore: fix system tests [run ci]

* add preprocessor tests to batteries included to exercise new logic

* run ci

* refactor unit tests to be a bit more dry

* pin typescript to ~5.4 and adjust config to ignroe deprecations but keep importsNotUsedAsValues

* add changelog entry

* add fixme issue to stack trace mismatches inside evaled context

* use import type webpack as webpack as a lib isn't actually invboked in the runner webpack config

* fix system test as adding 4 lines of comments impacts the stack trace line 4 lines (duh)

---------

Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>
  • Loading branch information
AtofStryker and cypress-bot[bot] committed Jun 4, 2024
1 parent 09c6876 commit f3b6766
Show file tree
Hide file tree
Showing 62 changed files with 599 additions and 566 deletions.
5 changes: 5 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ _Released 6/4/2024_

- Fixed a situation where the Launchpad would hang if the project config had not been loaded when the Launchpad first queries the current project. Fixes [#29486](https://github.com/cypress-io/cypress/issues/29486).
- Pre-emptively fix behavior with Chrome for when `unload` events are forcefully deprecated by using `pagehide` as a proxy. Fixes [#29241](https://github.com/cypress-io/cypress/issues/29241).
- Fixed an issue where `inlineSourceMaps` was still being used when `sourceMaps` was provided in a users typescript config for typescript version 5. Fixes [#26203](https://github.com/cypress-io/cypress/issues/26203).

**Dependency Updates:**

- Updated typescript from `4.7.4` to `5.3.3`. Addressed in [#29568](https://github.com/cypress-io/cypress/pull/29568).

**Misc:**

Expand Down
2 changes: 1 addition & 1 deletion npm/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@angular/core": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@cypress/mount-utils": "0.0.0-development",
"typescript": "^4.7.4",
"typescript": "~5.4.5",
"zone.js": "~0.11.4"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion npm/cypress-schematic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/node": "^18.17.5",
"chai": "4.2.0",
"mocha": "3.5.3",
"typescript": "^4.7.4"
"typescript": "^5.4.5"
},
"peerDependencies": {
"@angular/cli": ">=14",
Expand Down
4 changes: 2 additions & 2 deletions npm/grep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Filter tests using substring",
"main": "src/support.js",
"scripts": {
"cy:run": "node ../../scripts/cypress.js run --config specPattern='**/unit.js'",
"cy:open": "node ../../scripts/cypress.js open --e2e -b electron --config specPattern='**/unit.js'",
"cy:run": "node ../../scripts/cypress.js run --config specPattern='**/unit.js'",
"lint": "eslint . --ext .js,.ts"
},
"dependencies": {
Expand All @@ -16,7 +16,7 @@
"devDependencies": {
"cypress-each": "^1.11.0",
"cypress-expect": "^2.5.3",
"typescript": "^4.7.4"
"typescript": "^5.4.5"
},
"peerDependencies": {
"cypress": ">=10"
Expand Down
2 changes: 1 addition & 1 deletion npm/mount-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"rollup": "3.7.3",
"rollup-plugin-dts": "5.0.0",
"rollup-plugin-typescript2": "^0.29.0",
"typescript": "^4.7.4"
"typescript": "^5.4.5"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion npm/puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"sinon": "^13.0.1",
"sinon-chai": "^3.7.0",
"ts-node": "^10.9.2",
"typescript": "4.7.4"
"typescript": "5.4.5"
},
"peerDependencies": {
"cypress": ">=13.6.0"
Expand Down
2 changes: 1 addition & 1 deletion npm/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"react-router": "6.0.0-alpha.1",
"react-router-dom": "6.0.0-alpha.1",
"semver": "^7.5.3",
"typescript": "^4.7.4",
"typescript": "~5.4.5",
"vite": "4.5.2",
"vite-plugin-require-transform": "1.0.12"
},
Expand Down
2 changes: 1 addition & 1 deletion npm/react18/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"react-dom": "^16",
"rollup": "3.7.3",
"rollup-plugin-typescript2": "^0.29.0",
"typescript": "^4.7.4"
"typescript": "^5.4.5"
},
"peerDependencies": {
"@types/react": "^18",
Expand Down
2 changes: 1 addition & 1 deletion npm/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@cypress/mount-utils": "0.0.0-development",
"svelte": "^3.49.0",
"typescript": "^4.7.4"
"typescript": "^5.4.5"
},
"peerDependencies": {
"cypress": ">=10.6.0",
Expand Down
5 changes: 5 additions & 0 deletions npm/vite-dev-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"esModuleInterop": true,
/** Allows us to strip internal types sourced from webpack */
"stripInternal": true,
"ignoreDeprecations": "5.0",
/*
* TODO: remove importsNotUsedAsValues after typescript 5.5 and up as it will no longer work. If we want the same behavior
* as importsNotUsedAsValues, we need to use "verbatimModuleSyntax", which will require this package to be an ES Module.
*/
"importsNotUsedAsValues": "error",
/* skips checking declaration types. we skip this because we have multiple versions of vite installed as dev dependencies */
"skipLibCheck": true,
Expand Down
4 changes: 2 additions & 2 deletions npm/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"debug": "^4.3.4",
"globby": "^11.0.1",
"tailwindcss": "1.1.4",
"typescript": "^4.7.4",
"typescript": "~5.4.5",
"vite": "4.5.2",
"vue": "3.2.47",
"vue-i18n": "9.0.0-rc.6",
"vue-router": "^4.0.0",
"vue-tsc": "^0.3.0",
"vue-tsc": "^2.0.19",
"vuex": "^4.0.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion npm/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@rollup/plugin-replace": "^2.3.1",
"@vue/test-utils": "^1.3.1",
"tslib": "^2.1.0",
"typescript": "^4.7.4",
"typescript": "~5.4.5",
"vue": "2.7.16"
},
"peerDependencies": {
Expand Down
45 changes: 40 additions & 5 deletions npm/webpack-batteries-included-preprocessor/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const path = require('path')
const fs = require('fs-extra')
const JSON5 = require('json5')
const webpack = require('webpack')
const Debug = require('debug')
const webpackPreprocessor = require('@cypress/webpack-preprocessor')

const debug = Debug('cypress:webpack-batteries-included-preprocessor')

const hasTsLoader = (rules) => {
return rules.some((rule) => {
if (!rule.use || !Array.isArray(rule.use)) return false
Expand All @@ -12,6 +17,38 @@ const hasTsLoader = (rules) => {
})
}

const getTSCompilerOptionsForUser = (configFilePath) => {
const compilerOptions = {
sourceMap: false,
inlineSourceMap: true,
inlineSources: true,
downlevelIteration: true,
}

if (!configFilePath) {
return compilerOptions
}

try {
// If possible, try to read the user's tsconfig.json and see if sourceMap is configured
// eslint-disable-next-line no-restricted-syntax
const tsconfigJSON = fs.readFileSync(configFilePath, 'utf8')
// file might have trailing commas, new lines, etc. JSON5 can parse those correctly
const parsedJSON = JSON5.parse(tsconfigJSON)

// if the user has sourceMap's configured, set the option to true and turn off inlineSourceMaps
if (parsedJSON?.compilerOptions?.sourceMap) {
compilerOptions.sourceMap = true
compilerOptions.inlineSourceMap = false
compilerOptions.inlineSources = false
}
} catch (e) {
debug(`error in getTSCompilerOptionsForUser. Returning default...`, e)
} finally {
return compilerOptions
}
}

const addTypeScriptConfig = (file, options) => {
// shortcut if we know we've already added typescript support
if (options.__typescriptSupportAdded) return options
Expand All @@ -30,6 +67,8 @@ const addTypeScriptConfig = (file, options) => {
// package using require('tsconfig'), so we alias it as 'tsconfig-aliased-for-wbip'
const configFile = require('tsconfig-aliased-for-wbip').findSync(path.dirname(file.filePath))

const compilerOptions = getTSCompilerOptionsForUser(configFile)

webpackOptions.module.rules.push({
test: /\.tsx?$/,
exclude: [/node_modules/],
Expand All @@ -38,11 +77,7 @@ const addTypeScriptConfig = (file, options) => {
loader: require.resolve('ts-loader'),
options: {
compiler: options.typescript,
compilerOptions: {
inlineSourceMap: true,
inlineSources: true,
downlevelIteration: true,
},
compilerOptions,
logLevel: 'error',
silent: true,
transpileOnly: true,
Expand Down
9 changes: 7 additions & 2 deletions npm/webpack-batteries-included-preprocessor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
"coffeescript": "2.6.0",
"constants-browserify": "^1.0.0",
"crypto-browserify": "^3.12.0",
"debug": "^4.3.4",
"domain-browser": "^4.22.0",
"events": "^3.3.0",
"fs-extra": "^9.1.0",
"https-browserify": "^1.0.0",
"json5": "2.2.3",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"pnp-webpack-plugin": "^1.7.0",
Expand All @@ -50,10 +53,12 @@
"@types/mocha": "^8.0.2",
"@types/webpack": "^5.28.1",
"chai": "^4.2.0",
"fs-extra": "^9.1.0",
"decache": "^4.6.2",
"mocha": "^8.1.1",
"mock-require": "3.0.3",
"react": "^16.13.1",
"typescript": "^4.7.4"
"sinon": "18.0.0",
"typescript": "^5.4.5"
},
"peerDependencies": {
"@cypress/webpack-preprocessor": "^5.4.4"
Expand Down
Loading

5 comments on commit f3b6766

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f3b6766 Jun 4, 2024

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.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.11.1/linux-x64/develop-f3b67666a5db0438594339c379cf27e1fd1e4abc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f3b6766 Jun 4, 2024

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.11.1/linux-arm64/develop-f3b67666a5db0438594339c379cf27e1fd1e4abc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f3b6766 Jun 5, 2024

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.11.1/darwin-arm64/develop-f3b67666a5db0438594339c379cf27e1fd1e4abc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f3b6766 Jun 5, 2024

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.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.11.1/darwin-x64/develop-f3b67666a5db0438594339c379cf27e1fd1e4abc/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f3b6766 Jun 5, 2024

Choose a reason for hiding this comment

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

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

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.11.1/win32-x64/develop-f3b67666a5db0438594339c379cf27e1fd1e4abc/cypress.tgz

Please sign in to comment.