Skip to content

Commit 43a2bbb

Browse files
committed
[DOCS] Add debugging workflow info docs
1 parent d5696dd commit 43a2bbb

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,57 @@ require('codemod-cli').runTransform(
7575
)
7676
```
7777

78+
## Debugging Workflow
79+
Oftentimes, you want to debug the codemod or the transform to identify issues with the code or to understand
80+
how the transforms are working, or to troubleshoot why some tests are failing.
81+
82+
Hence we recommend a debugging work-flow like below to quickly find out what is causing the issue.
83+
84+
### 1. Place `debugger` statements
85+
Add `debugger` statements, in appropriate places in the code. For example:
86+
87+
```js
88+
...
89+
const params = a.value.params.map(p => {
90+
debugger;
91+
if(p.type === "SubExpression") {
92+
return transformNestedSubExpression(p)
93+
...
94+
```
95+
96+
### 2. Inspect the process with node debug
97+
Here we are going to start the tests selectively in node debug mode. Since the
98+
codemod is bootstrapped using [codemod-cli](https://github.com/rwjblue/codemod-cli) which is using [jest](https://jestjs.io/) in turn
99+
to run the tests, jest is having an option `-t <name-of-spec>` to run a particular
100+
set of tests instead of running the whole test suite.
101+
102+
We are making use of both these features to start our tests in this particular fashion.
103+
For more details on node debug, visit the [official](https://nodejs.org/en/docs/guides/debugging-getting-started/)
104+
Node.js debugging guide, and for jest documentation on tests, [here](https://jestjs.io/docs/en/cli)
105+
106+
```sh
107+
node --inspect-brk ./node_modules/.bin/codemod-cli -t '<fixture-name>'
108+
```
109+
110+
For example, if you want to debug the `null-subexp.input.hbs` fixture or only that particular test case is failing
111+
because of an issue.
112+
113+
```sh
114+
node --inspect-brk ./node_modules/.bin/codemod-cli -t 'null-subexp'
115+
```
116+
117+
Sometimes we need to use `--runInBand` flag for the debugger statements to be hit when focusing the test with jest
118+
119+
For example:
120+
121+
```sh
122+
node --inspect-brk ./node_modules/.bin/jest --testNamePattern "ember-concurrency transforms correctly" --runInBand
123+
```
124+
125+
Once you run the above command, your tests will start running in debug mode and your breakpoints will be
126+
triggered appropriately when that particular block of code gets executed. You can run the debugger inside
127+
Chrome browser dev-tools. More details on [here](https://developers.google.com/web/tools/chrome-devtools/javascript/)
128+
78129
Contributing
79130
------------------------------------------------------------------------------
80131

0 commit comments

Comments
 (0)