|
4 | 4 |
|
5 | 5 | ## Usage |
6 | 6 |
|
| 7 | +This package provide two modules: |
| 8 | + |
| 9 | +### `TenbinReporter` |
| 10 | + |
| 11 | +This module is served as the default export from `@tenbin/vitest/reporter`. |
| 12 | + |
| 13 | +`TenbinReporter` generates a JSON report showing the execution time (in seconds) for each test file, as shown below: |
| 14 | + |
| 15 | +```json:tenbin-report.json |
| 16 | +{ |
| 17 | + "tests/file-a.test.ts": 1.223, |
| 18 | + "tests/file-b.test.ts": 2.334, |
| 19 | + ... |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +The report is saved as `tenbin-report.json` in the current working directory (cwd). This file is uploaded to external storage, such as S3, and is used by `TenbinSequencer` when running next tests. In the case of GitHub Actions, the file can be stored using a cache that persists between workflows. (See the Example section for details.) |
| 24 | + |
| 25 | +### `TenbinSequencer` |
| 26 | + |
| 27 | +This module is served as the default export from `@tenbin/vitest/sequencer`. |
| 28 | + |
| 29 | +`TenbinSequencer` reads the `tenbin-report.json` file from the current working directory (cwd) and splits tests to minimize the differences in test execution times across shards For test files not listed in `tenbin-report.json`, the execution time is assumed to be 0 seconds. If the tenbin-report.json file is not found, the shards are split randomly. |
| 30 | + |
| 31 | +## Example |
| 32 | + |
7 | 33 | Install: |
8 | 34 |
|
9 | 35 | ```sh |
10 | 36 | npm i @tenbin/vitest -D |
11 | 37 | ``` |
12 | 38 |
|
13 | | -Vitest configuration: |
| 39 | +Configuration: |
14 | 40 |
|
15 | 41 | ```ts |
16 | 42 | import TenbinReporter from "@tenbin/vitest/reporter"; |
|
55 | 81 | run: pnpm install |
56 | 82 | - name: Run build |
57 | 83 | run: pnpm run build |
58 | | - # Restore the tenbin-report.json file, which records the execution time of each test file. |
59 | | - # @tenbin/vitest/sequencer use this file for sharding. |
| 84 | + # Restore tenbin-report.json file, which records the execution time of each test file. |
| 85 | + # @tenbin/vitest/sequencer uses this file for sharding. |
60 | 86 | - name: Restore tenbin-report.json |
61 | 87 | id: tenbin-report-cache |
62 | 88 | uses: actions/cache/restore@v4 |
|
67 | 93 | tenbin-report-* |
68 | 94 | - name: Run test |
69 | 95 | run: pnpx vitest --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} |
70 | | - # @tenbin/vitest/reporter generates a tenbin-report.json for each shard. |
| 96 | + # @tenbin/vitest/reporter generates tenbin-report.json for each shard. |
71 | 97 | - name: Upload tenbin-report.json |
72 | 98 | if: github.ref_name == 'main' |
73 | 99 | uses: actions/upload-artifact@v4 |
|
0 commit comments