Skip to content

Commit 73b86e7

Browse files
ota-meshiJounQin
andauthored
Update docs for contributing (#172)
* Update docs for contributing * Update * Update README.md Co-authored-by: JounQin <[email protected]> Co-authored-by: JounQin <[email protected]>
1 parent 86a1462 commit 73b86e7

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,40 @@ Please use GitHub's Issues/PRs.
331331

332332
### Development Tools
333333

334-
- `yarn test` runs tests and measures coverage.
334+
- `yarn test` runs tests.
335+
- `yarn cover` runs tests and measures coverage.
335336
- `yarn update` runs in order to update readme and recommended configuration.
336337

338+
### Test the Rule
339+
340+
Rule testing almost always uses fixtures.
341+
For example, for an `indent` rule, the `.ts` file that runs the test is `tests/src/rules/indent.ts` and the fixture is in `tests/fixtures/rules/indent`.
342+
The fixture directory has an `invalid` directory and a `valid` directory.
343+
344+
- The `invalid` directory contains test cases where the rule reports problems.
345+
- The `valid` directory contains test cases where the rule does not report a problem.
346+
347+
The fixture input file should be named `*-input.svelte`. It is automatically collected and tested.
348+
If your test requires configuration, you need to add a json file with the configuration.
349+
350+
- If you want to apply a configuration to `my-test-input.svelte`, add `my-test-config.json`.
351+
- If you want to apply the same configuration to all the fixtures in that directory, add `_config.json`.
352+
353+
To verify the output of invalid test cases requires `*-errors.json`, and `*-output.svelte` (for auto-fix). However, you don't have to add them yourself. If they do not exist, they will be automatically generated when you run the test. In other words, delete them manually when you want to recreate them.
354+
355+
**Tips**:
356+
357+
If you want to test only one rule, run the following command (for `indent` rule):
358+
359+
```sh
360+
yarn test -g indent
361+
```
362+
363+
Take https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha as reference for details.
364+
365+
If you want to test only `my-test-input.svelte`, add `my-test-config.json` and save `{"only": true}`.
366+
(Note that `{"only": true}` must be removed before making a pull request.)
367+
337368
### Working With Rules
338369

339370
This plugin uses [svelte-eslint-parser](https://github.com/ota-meshi/svelte-eslint-parser) for the parser. Check [here](https://ota-meshi.github.io/svelte-eslint-parser/) to find out about AST.

0 commit comments

Comments
 (0)