-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lmiller1990/windows-fails' of github.com:cypress-io/cyp…
…ress into lmiller1990/windows-fails
- Loading branch information
Showing
4 changed files
with
95 additions
and
3 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
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 @@ | ||
# Remaining Platform Agnostic | ||
|
||
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 be concious of how we do so to ensure Cypress can be used and developed seemlessly on multiple platforms. One thing to keep in mind is file paths and file separators. macOS and Linux systems that use `/`, and Windows which uses `\`. | ||
|
||
|
||
As a general rule, we want to use **native paths** where possible. There are a few reasons for this. Where ever 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`. 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
6d465c8
There was a problem hiding this comment.
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
6d465c8
There was a problem hiding this comment.
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
6d465c8
There was a problem hiding this comment.
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally: