Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,57 @@ require('codemod-cli').runTransform(
)
```

## Debugging Workflow
Oftentimes, you want to debug the codemod or the transform to identify issues with the code or to understand
how the transforms are working, or to troubleshoot why some tests are failing.

Hence we recommend a debugging work-flow like below to quickly find out what is causing the issue.

### 1. Place `debugger` statements
Add `debugger` statements, in appropriate places in the code. For example:

```js
...
const params = a.value.params.map(p => {
debugger;
if(p.type === "SubExpression") {
return transformNestedSubExpression(p)
...
```

### 2. Inspect the process with node debug
Here we are going to start the tests selectively in node debug mode. Since the
codemod is bootstrapped using [codemod-cli](https://github.com/rwjblue/codemod-cli) which is using [jest](https://jestjs.io/) in turn
to run the tests, jest is having an option `-t <name-of-spec>` to run a particular
set of tests instead of running the whole test suite.

We are making use of both these features to start our tests in this particular fashion.
For more details on node debug, visit the [official](https://nodejs.org/en/docs/guides/debugging-getting-started/)
Node.js debugging guide, and for jest documentation on tests, [here](https://jestjs.io/docs/en/cli)

```sh
node --inspect-brk ./node_modules/.bin/codemod-cli -t '<fixture-name>'
```

For example, if you want to debug the `null-subexp.input.hbs` fixture or only that particular test case is failing
because of an issue.

```sh
node --inspect-brk ./node_modules/.bin/codemod-cli -t 'null-subexp'
```

Sometimes we need to use `--runInBand` flag for the debugger statements to be hit when focusing the test with jest

For example:

```sh
node --inspect-brk ./node_modules/.bin/jest --testNamePattern "ember-concurrency transforms correctly" --runInBand
```

Once you run the above command, your tests will start running in debug mode and your breakpoints will be
triggered appropriately when that particular block of code gets executed. You can run the debugger inside
Chrome browser dev-tools. More details on [here](https://developers.google.com/web/tools/chrome-devtools/javascript/)

Contributing
------------------------------------------------------------------------------

Expand Down