Skip to content

Commit 55604a0

Browse files
authored
[Docs] Update README (#4)
1 parent 8c116d0 commit 55604a0

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
# typescript-coverage
1+
# `Typescript Coverage`
2+
3+
## Intro
4+
5+
> A dead-simple criteria to track your Typescript migration.
6+
7+
To measure Typescript coverage, we simply divide the total number of lines in TS by the total number of lines in the project.
8+
That's it, nothing more. Easy, huh?
9+
10+
## Example output
11+
12+
![An output example when run in terminal](/img/example.png)
13+
14+
## Our approach
15+
16+
- We locate all the files according to the `include` and `exclude` options.
17+
- If the file extension belongs to `tsExtensions`, we consider the whole file written in TS. Its line number is added to "lines in TS".
18+
- In any case, its line number is added to "all lines".
19+
- We divide "lines in TS" by "all lines" to get the final percentage.
220

321
## Installation
4-
Install it alongside its peer dependencies (`chalk` and `glob`)
22+
23+
Install the package alongside its peer dependencies (`chalk` and `glob`) with your favorite package manager:
524

625
```bash
726
npm install --save-dev typescript-coverage chalk glob
@@ -15,4 +34,49 @@ yarn add --dev typescript-coverage chalk glob
1534
pnpm install --save-dev typescript-coverage chalk glob
1635
```
1736

18-
⚠️You will need node 20 and pnpm for local development
37+
## Using in your project
38+
39+
1. Add a new script to your `package.json`:
40+
41+
```json
42+
{
43+
"scripts": {
44+
"typescript-coverage": "typescript-coverage"
45+
}
46+
}
47+
```
48+
49+
2. Create a `type-coverage.config.json` file in the root of your project to customize the coverage calculation (optional).
50+
When no config was found, the following defaults will be used:
51+
52+
```json5
53+
{
54+
// how to find the files to analyze (glob syntax)
55+
include: 'src/**/*.{ts,tsx,js,jsx}',
56+
// the files or the folders to ignore: mocks, tests, etc. (glob syntax)
57+
exclude: ['**/__tests__/**'],
58+
// whether to ignore empty lines
59+
ignoreEmptyLines: false,
60+
// the files that are consider written in TS (could be .ts, .tsx, .mts, .cts, etc)
61+
tsExtensions: ['.ts', '.tsx'],
62+
}
63+
```
64+
65+
## System requirements
66+
67+
- The project uses top-level `await` with ES modules and thus requires Node v14.8.0 or higher (tested on Node 18 and 20).
68+
- To run the tests locally, the PNPM package manager must be installed. Note: this requirement only applies if you are contributing to the project.
69+
70+
## Caveats
71+
72+
- For simplicity, we are only looking at the file extension but the content isn't validated. A linter or a Typescript compiler will take care of that.
73+
- If the file has a `.ts` extension but the content is not a valid TS code, it will still be treated as TS.
74+
- No type inference is taken into account.
75+
- If the file is a mixture of JS and TS code but has a `.ts` extension, all the lines will be counted as TS.
76+
- We don't ignore comments. Taking different comments into account (inline, multiline) would further complicate it.
77+
78+
## Our story
79+
80+
At Prose, we've been migrating two projects to Typescript.
81+
We needed the simplest way to track our progress, so we created `typescript-coverage` — a minimalistic tool focused on this sole goal.
82+
Instead of copying and pasting it into every project, we decided to make it an open-source package for anyone facing the same challenge 💚

img/example.png

84.4 KB
Loading

0 commit comments

Comments
 (0)