-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '10.0-release' into tgriesser/chore/UNIFY-1256-auto-merg…
…e-config * 10.0-release: chore: Move component-index generation to scaffold-config package (#21090) fix: label text should be clickable to toggle snapshot highlight (#21122) feat: add next preset to webpack-dev-server-fresh (#21069) chore: add dev-servers as deps to server to be included in the binary (#21142) fix: do not highlight preExtension if selected option is renameFolder (#21121) fix(unify): Remove 'Reconfigure' dropdown from Testing Type chooser (#21063) feat(unify): launchpad header breadcrumbs and reusable tooltip component (#20648) test: add windows-test-kitchensink job (#20847) fix: aut centering and height calculation (#21019) chore: fix tests that fail on windows (#21055) fix: running a new test after already having run tests (#21087) fix: ct project setup framework keys for next and nuxt (#21116) fix: remove MountReturn from scaffolded ct support file (#21119) fix: do not scaffold fixtures if folder exist (#21078) fix: revert "fix: types for Cypress.Commands.add (#20376)" (#21104) chore: Update Chrome (stable) to 100.0.4896.127 and Chrome (beta) to 101.0.4951.34 (#21083) fix: types for Cypress.Commands.add (#20376) (#20377)
- Loading branch information
Showing
141 changed files
with
8,034 additions
and
1,084 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"chrome:beta": "101.0.4951.26", | ||
"chrome:stable": "100.0.4896.88" | ||
"chrome:beta": "101.0.4951.34", | ||
"chrome:stable": "100.0.4896.127" | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Writing Cross-Platform JavaScript | ||
|
||
Cypress works on Linux, macOS and Windows. This includes both installing from npm, as well as for local development. Code should be written in a platform agnostic style. | ||
|
||
## Handling File Paths | ||
|
||
Throughout the code base, we access the file system in various ways, and need to be conscious of how we do so to ensure Cypress can be used and developed seamlessly on multiple platforms. One thing to keep in mind is file paths and file separators. macOS and Linux systems use `/`, and Windows uses `\`. | ||
|
||
|
||
As a general rule, we want to use **native paths** where possible. There are a few reasons for this. Whereever we display a file path, we want to use the native file separator, since that is what the user will expect on their platform. In general, we can use the Node.js `path` module to handle this: | ||
|
||
```js | ||
// on linux-like systems | ||
path.join('cypress', 'e2e') //=> `cypress/e2e` | ||
|
||
// on Windows | ||
path.join('cypress', 'e2e') //=> `cypress\e2e` | ||
``` | ||
|
||
There are some exceptions to this, namely the [`globby`](https://www.npmjs.com/package/globby) module, which only supports `/` (see [here](https://github.com/sindresorhus/globby#api)) when writing glob patterns. In these cases, where an API is posix only, you can use `path.posix.join`, which will always use `/`, even on a Windows system: | ||
|
||
```js | ||
// don't do | ||
const files = await globby('my-project\cypress\e2e\**\*') | ||
|
||
// do | ||
const files = await globby('my-project/cypress/e2e/**/*') | ||
|
||
// or you can convert it by splitting by path.sep | ||
// and joining with `path.posix.join` | ||
const glob = path.posix.join('my-project/cypress/e2e/**/*'.split(path.sep)) | ||
``` | ||
|
||
The general rule of using `path` where possible applies to moving around the file system, too: | ||
|
||
```js | ||
path.resolve('../', '/../', '../') | ||
// '/home' on Linux | ||
// '/Users' on OSX | ||
// 'C:\\Users' on Windows | ||
``` | ||
|
||
In general, you want to avoid writing file system code using `/` and `\`, and use Node.js APIs where possible - those are cross platform and guarenteed to work. | ||
|
||
## Use Node.js Scripts | ||
|
||
For many developers, it's tempting to write a quick bash script to automate tasks. Maybe you'd like to delete all `.js` files, so you add a script to `package.json`: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"clean": "rm -rf **/*.js" | ||
} | ||
} | ||
``` | ||
|
||
This will stop developers on Windows from running `yarn clean` unless they are specifically using a POSIX shell (like Git Bash). Instead, opt for a Node.js script where possible, or use a cross-platform Node.js module. In this case, we could use the [`rimraf`](https://www.npmjs.com/package/rimraf) module: | ||
|
||
```json | ||
{ | ||
"devDependencies": { | ||
"rimraf": "3.0.2", | ||
}, | ||
"scripts": { | ||
"clean": "rimraf '**/*.js'" | ||
} | ||
} | ||
``` | ||
|
||
Now your script is cross-platform. | ||
|
||
## Use the os Module | ||
|
||
You can use the `os` module to handle platform differences. One such example is line endings; `\n` on linux systems, and `\r\n` on Windows. Instead. use `os.EOL`. To check the current platform, use `os.arch()`: | ||
|
||
```ts | ||
import os from 'os' | ||
|
||
os.EOL // \n on linux, \r\n on windows | ||
|
||
os.platform() | ||
// 'linux' on Linux | ||
// 'win32' on Windows (32-bit / 64-bit) | ||
// 'darwin' on OSX | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import debugFn from 'debug' | ||
import type { ViteDevServerConfig } from './devServer' | ||
|
||
const debug = debugFn('cypress:vite-dev-server:getVite') | ||
|
||
export type Vite = typeof import('vite') | ||
|
||
// "vite-dev-server" is bundled in the binary, so we need to require.resolve "vite" | ||
// from root of the active project since we don't bundle vite internally but rather | ||
// use the version the user has installed | ||
export function getVite (config: ViteDevServerConfig): Vite { | ||
try { | ||
const viteImportPath = require.resolve('vite', { paths: [config.cypressConfig.projectRoot] }) | ||
|
||
debug('resolved viteImportPath as %s', viteImportPath) | ||
|
||
return require(viteImportPath) | ||
} catch (err) { | ||
throw new Error(`Could not find "vite" in your project's dependencies. Please install "vite" to fix this error.\n\n${err}`) | ||
} | ||
} |
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
Oops, something went wrong.