Skip to content

Commit 06c450a

Browse files
committed
update docs
1 parent b28657d commit 06c450a

6 files changed

Lines changed: 92 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Tenbin provides tools to minimize the differences in test execution times across shards.
44

5+
![Tenbin provides tools to minimize the differences in test execution times across shards.](./assets/tenbin-abstract.png)
6+
57
## Usage
68

79
- [Jest](./packages/jest/README.md)

assets/tenbin-abstract.png

74.7 KB
Loading

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Partition<T> = {
55

66
/**
77
* Partition data into k partitions such that the difference between the sum of the values of each partition is minimized.
8-
* see: https://en.wikipedia.org/wiki/Largest_differencing_method
8+
* cf: https://en.wikipedia.org/wiki/Largest_differencing_method
99
*/
1010
export function partition<T>(
1111
data: T[],

packages/jest/README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,39 @@
44

55
## Usage
66

7+
This package provide two modules:
8+
9+
### `TenbinReporter`
10+
11+
This module is served as the default export from `@tenbin/jest/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/jest/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+
733
Install:
834

935
```sh
1036
npm i @tenbin/jest -D
1137
```
1238

13-
Jest configuration:
39+
Configuration:
1440

1541
```js
1642
/** @type {import('jest').Config} */
@@ -50,8 +76,8 @@ jobs:
5076
run: pnpm install
5177
- name: Run build
5278
run: pnpm run build
53-
# Restore the tenbin-report.json file, which records the execution time of each test file.
54-
# @tenbin/jest/sequencer use this file for sharding.
79+
# Restore stenbin-report.json file, which records the execution time of each test file.
80+
# @tenbin/jest/sequencer uses this file for sharding.
5581
- name: Restore tenbin-report.json
5682
id: tenbin-report-cache
5783
uses: actions/cache/restore@v4
@@ -62,7 +88,7 @@ jobs:
6288
tenbin-report-*
6389
- name: Run test
6490
run: pnpx jest --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
65-
# @tenbin/jest/reporter generates a tenbin-report.json for each shard.
91+
# @tenbin/jest/reporter generates tenbin-report.json for each shard.
6692
- name: Upload tenbin-report.json
6793
if: github.ref_name == 'main'
6894
uses: actions/upload-artifact@v4

packages/playwright/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,40 @@
44

55
## Usage
66

7+
This package provides one function:
8+
9+
### `splitTests`
10+
11+
`splitTests` function divides test files based on the past [Playwright JSON report](https://playwright.dev/docs/test-reporters#json-reporter) specified in `reportFile`. It considers only files matching the `pattern` and ensures that each split has a balanced total execution time.
12+
13+
```ts
14+
import { defineConfig } from "@playwright/test";
15+
import { splitTests } from "@tenbin/playwright";
16+
17+
export default defineConfig({
18+
testMatch: splitTests({
19+
shard: "1/3",
20+
pattern: ["tests/**.test.ts"],
21+
reportFile: "./test-results.json",
22+
}),
23+
});
24+
```
25+
26+
Options:
27+
28+
- `shard`: test suite shard to execute in a format of `<index>/<count>`
29+
- `pattern`: glob pattern that defines which test files should be executed
30+
- `reportFile`: path to previous Playwright JSON report
31+
32+
## Example
33+
734
Install:
835

936
```sh
1037
npm i @tenbin/playwright -D
1138
```
1239

13-
Playwright configuration:
40+
Configuration:
1441

1542
```js
1643
import { defineConfig } from "@playwright/test";
@@ -55,7 +82,7 @@ jobs:
5582
- name: Run build
5683
run: pnpm run build
5784
# Restore test-results.json file, which records the execution time of each test file.
58-
# splitTests function use this file for sharding.
85+
# splitTests function uses this file for sharding.
5986
- name: Restore test-results.json
6087
uses: actions/cache/restore@v4
6188
with:

packages/vitest/README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,39 @@
44

55
## Usage
66

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+
733
Install:
834

935
```sh
1036
npm i @tenbin/vitest -D
1137
```
1238

13-
Vitest configuration:
39+
Configuration:
1440

1541
```ts
1642
import TenbinReporter from "@tenbin/vitest/reporter";
@@ -55,8 +81,8 @@ jobs:
5581
run: pnpm install
5682
- name: Run build
5783
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.
6086
- name: Restore tenbin-report.json
6187
id: tenbin-report-cache
6288
uses: actions/cache/restore@v4
@@ -67,7 +93,7 @@ jobs:
6793
tenbin-report-*
6894
- name: Run test
6995
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.
7197
- name: Upload tenbin-report.json
7298
if: github.ref_name == 'main'
7399
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)