Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Sep 29, 2024
1 parent d07a1ac commit b3663ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ Creates a 10 MiB file of all null characters.

Indicates if there is more than 1gb of total memory.

### ``escapePOSIXShell`shell command` ``

Escapes values in a string template literal to pass them as env variable. On Windows, this function
does not escape anything (which is fine for most paths, as `"` is not a valid
char in a path on Windows), so for tests that must pass on Windows, you should
use it only to escape paths, inside double quotes.
This function is meant to be used for tagged template strings.

```js
childProcess.execSync(...common.escapePOSIXShell`cp "${origin}" "${destination}"`);

Check failure on line 124 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'childProcess' is not defined

Check failure on line 124 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'common' is not defined

Check failure on line 124 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'origin' is not defined

Check failure on line 124 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'destination' is not defined

// When you need to specify specific options, and/or additional env variables:
const [cmd, opts] = common.escapePOSIXShell`cp "${origin}" "${destination}"`;

Check failure on line 127 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'common' is not defined

Check failure on line 127 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'origin' is not defined

Check failure on line 127 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'destination' is not defined
typeof cmd === 'string'; // true

Check failure on line 128 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected an assignment or function call and instead saw an expression
opts === undefined || typeof opts.env === 'object'; // true

Check failure on line 129 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected an assignment or function call and instead saw an expression
childProcess.execSync(cmd, { ...opts, stdio: 'ignore' });

Check failure on line 130 in test/common/README.md

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'childProcess' is not defined
childProcess.execSync(cmd, { stdio: 'ignore', env: { ...opts?.env, KEY: 'value' } });
```

When possible, avoid using a shell; that way, there's no need to escape values.

### `expectsError(validator[, exact])`

* `validator` [\<Object>][<Object>] | [\<RegExp>][<RegExp>] |
Expand Down
2 changes: 1 addition & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ function spawnPromisified(...args) {
}

/**
* Escape quoted values in a string template literal. On Windows, this function
* Escape values in a string template literal. On Windows, this function
* does not escape anything (which is fine for paths, as `"` is not a valid char
* in a path on Windows), so you should use it only to escape paths – or other
* values on tests which are skipped on Windows.
Expand Down

0 comments on commit b3663ac

Please sign in to comment.