Skip to content

Commit

Permalink
Update contributing.md (#16508)
Browse files Browse the repository at this point in the history
* update developing requirements

* update command execution time

* promote yarn jest usage

* Update CONTRIBUTING.md

* update test timeout usage
  • Loading branch information
JLHwung committed May 18, 2024
1 parent 4f1e42b commit 0ee85cb
Showing 1 changed file with 53 additions and 27 deletions.
80 changes: 53 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Feel free to check out the `#discussion`/`#development` channels on our [Slack](

## Developing

_Node_: Check that Node is [installed](https://nodejs.org/en/download/) with version `^12.20 || >= 14.13`. You can check this with `node -v`.
_Node_: Check that Node is [installed](https://nodejs.org/en/download/) with version `^20.10.0 || >=22.0.0`. You can check this with `node -v`.

_Yarn_: Make sure that Yarn 1 is [installed](https://classic.yarnpkg.com/en/docs/install) with version >= `1.19.0`.
_Yarn_: Make sure that Yarn is [installed](https://yarnpkg.com/getting-started/install) with version `>=4.0.0`.

_Make_: If you are running Windows 10, you'll need to do one of the following:

Expand All @@ -48,7 +48,7 @@ _Make_: If you are running Windows 10, you'll need to do one of the following:

### Setup

Fork the `babel` repository to your GitHub Account.
[Fork](https://github.com/babel/babel/fork) the `babel` repository to your GitHub Account.

Then, run:

Expand Down Expand Up @@ -80,13 +80,15 @@ If you wish to build a copy of Babel for distribution, then run:
$ make build-dist
```

## Develop compiling to CommonJS or to ECMAScript modules
### Develop compiling to CommonJS or to ECMAScript modules

Babel can currently be compiled both to CJS and to ESM. You can toggle between those two
modes by running one of the following commands:

```sh
make use-esm
```

```sh
make use-cjs
```
Expand All @@ -100,7 +102,7 @@ If you never run a `make use-*` (or if you delete the `.module-type` file that t
#### Lint

```sh
# ~6 sec on a MacBook Pro (Mid 2015)
# ~19 sec on a MacBook Pro (Late 2021)
$ make lint
```

Expand All @@ -113,49 +115,55 @@ $ make fix
#### Tests + lint for all packages (slow) via:

```sh
# ~46 sec on a MacBook Pro (Mid 2015)
# ~32 sec on a MacBook Pro (Late 2021)
$ make test
```

#### All tests:

```sh
# ~40 sec on a MacBook Pro (Mid 2015)
$ make test-only
# ~13 sec on a MacBook Pro (Late 2021)
$ yarn jest
```

#### Run tests for Babel 8

```sh
$ BABEL_8_BREAKING=true yarn jest
```

#### Run tests for a specific package

When working on an issue, you will most likely want to focus on a particular [packages](https://github.com/babel/babel/tree/main/packages). Using `TEST_ONLY` will only run tests for that specific package.
When working on an issue, you will most likely want to focus on a particular [packages](https://github.com/babel/babel/tree/main/packages). For example, to run tests on `babel-cli`:

```sh
$ TEST_ONLY=babel-cli make test
$ yarn jest babel-cli
```

<details>
<summary>More options</summary>
<code>TEST_ONLY</code> will also match substrings of the package name:
It will also match substrings of the package name:

```sh
# Run tests for the @babel/plugin-transform-classes package.
$ TEST_ONLY=babel-plugin-transform-classes make test
$ yarn jest classes
```

Or you can use Yarn:
Or you can use the `TEST_ONLY` environment variable:

```sh
$ yarn jest babel-cli
$ TEST_ONLY=babel-cli make test-only
```

</details>
<br>

#### Run a subset of tests

Use the `TEST_GREP` variable to run a subset of tests by name:
Use the [Jest CLI `-t` option](https://jestjs.io/docs/cli#--testnamepatternregex) to run a subset of tests with a name that matches the regex:

```sh
$ TEST_GREP=transformation make test
$ yarn jest -t transformation
```

Substitute spaces for hyphens and forward slashes when targeting specific test names:
Expand All @@ -169,40 +177,57 @@ packages/babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/de
You can use:

```sh
$ TEST_GREP="arrow functions destructuring parameters" make test
$ yarn jest -t "arrow functions destructuring parameters"
```

Or you can directly use Yarn:
Or you can use the `TEST_GREP` environment variable:

```sh
$ yarn jest -t "arrow functions destructuring parameters"
$ TEST_GREP="arrow functions destructuring parameters" make test-only
```

#### Run test with Node debugger

To enable the Node.js debugger, set the <code>TEST_DEBUG</code> environment variable:
To enable the Node.js debugger, run node with `--inspect-brk` option and include the [Jest CLI `-i` option](https://jestjs.io/docs/cli#--runinband) or you [may not hit breakpoints with the chrome debugger](https://github.com/nodejs/node/issues/26609).

```sh
$ TEST_DEBUG=true make test
yarn run --inspect-brk jest -i packages/package-to-test
```

<details>
<summary>More options</summary>

You can also run `jest` directly, but you must remember to include `--runInBand` or `-i` or you [may not hit breakpoints with the chrome debugger](https://github.com/nodejs/node/issues/26609).
You can also set the <code>TEST_DEBUG</code> environment variable

```sh
$ TEST_DEBUG=true make test-only
```

```sh
yarn run --inspect-brk jest -i packages/package-to-test
```
</details>
<br>

You can combine `TEST_DEBUG` with `TEST_GREP` or `TEST_ONLY` to debug a subset of tests. If you plan to stay long in the debugger (which you'll likely do!), you may increase the test timeout by editing [test/testSetupFile.js](https://github.com/babel/babel/blob/main/test/testSetupFile.js).
You can combine `-i` with `-t` to debug a subset of tests. For example,

```sh
yarn run --inspect-brk jest -i babel-plugin-arrow-functions -t "destructuring parameters"
```

If you plan to stay long in the debugger (which you'll likely do!), you may increase the test timeout by the [Jest CLI `--testTimeout` option](https://jestjs.io/docs/cli#--testtimeoutnumber). For example to increase test timeout to 500 seconds

```sh
yarn run --inspect-brk jest -i babel-parser -t "my new test" --testTimeout=500000
```

To overwrite any test fixtures when fixing a bug or anything, add the env variable `OVERWRITE=true`

```sh
$ OVERWRITE=true TEST_ONLY=babel-plugin-transform-classes make test-only
$ OVERWRITE=true yarn jest babel-plugin-transform-classes
```

Sometimes you may have to update Babel 8 test fixtures as well, run `OVERWRITE=true` with `BABEL_8_BREAKING=true`:

```sh
$ BABEL_8_BREAKING=true OVERWRITE=true yarn jest babel-parser
```

#### Test coverage
Expand Down Expand Up @@ -361,6 +386,7 @@ For both `@babel/plugin-x` and `@babel/parser`, you can easily generate an `outp
#### Editor setup

We have JSON Schema definitions so that your editor can provide autocomplete for `options.json` files in fixtures:

- `./packages/babel-helper-fixtures/data/schema.json` for plugins/presets tests
- `./packages/babel-parser/test/schema.json` for parser tests

Expand Down

0 comments on commit 0ee85cb

Please sign in to comment.