Skip to content

Commit 9f02d4e

Browse files
authored
feat(docs): add hints on debugging and running tests (#1267)
1 parent b7ff9cc commit 9f02d4e

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

CONTRIBUTING.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,51 @@ To get up and running, install the dependencies and run the tests:
55
```bash
66
yarn
77
yarn test
8-
```
98

10-
Run `yarn prettier path/to/file.php` to format a single file.
9+
# format a single file
10+
yarn prettier path/to/file.php`
11+
12+
# run a single test
13+
yarn test tests/{folder of your choice}
14+
```
1115

1216
Here's what you need to know about the tests:
1317
1418
* The tests use [Jest](https://facebook.github.io/jest/) snapshots.
1519
* You can make changes and run `jest -u` (or `yarn test -u`) to update the snapshots. Then run `git diff` to take a look at what changed. Always update the snapshots when opening a PR.
1620
* You can run `AST_COMPARE=1 yarn test` for a more robust test run. That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent.
17-
* If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file and run it in an editor like VS Code.
1821
1922
Run `yarn lint --fix` to automatically format files.
2023
2124
If you can, take look at [commands.md](https://github.com/prettier/prettier/blob/master/commands.md) and check out [Wadler's paper](http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf) to understand how Prettier works.
25+
26+
## Debugging
27+
28+
### VScode
29+
30+
Add the following configuration to `.vscode/launch.json`:
31+
32+
```json
33+
{
34+
"type": "node",
35+
"request": "launch",
36+
"name": "Prettify test.php",
37+
"skipFiles": [
38+
"<node_internals>/**"
39+
],
40+
"program": "${workspaceRoot}/node_modules/.bin/prettier",
41+
"args": ["--plugin=.", "--parser=php", "foo.php"],
42+
"cwd": "${workspaceRoot}",
43+
"outputCapture": "std"
44+
}
45+
```
46+
47+
Afterwards, paste some PHP code into `test.php`, add a breakpoint, and start the debugger.
48+
49+
### Browser
50+
51+
```
52+
node --inspect-brk node_modules/.bin/jest --runInBand tests/{folder of your choice}/`
53+
```
54+
55+
Details about debugging in the Browser can be found in the [Jest troubleshooting docs](https://jestjs.io/docs/en/troubleshooting).

0 commit comments

Comments
 (0)