Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exameple of testSquencer in typescript inside documentation readme.md file #15419

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
- `[docs]` `Revised documentation for .toHaveBeenCalled()` to accurately depict its functionality. ([#14853](https://github.com/jestjs/jest/pull/14853))
- `[docs]` Removed ExpressJS reference link from documentation due to dead link ([#15270](https://github.com/jestjs/jest/pull/15270))

## 29.7.1

### Chore & Maintenance

- `[docs]` Added example of `testSequencer` in typescript inside configuration.md file

## 29.7.0

### Features
Expand Down
31 changes: 30 additions & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@

For example, you may sort test paths alphabetically:

```js title="custom-sequencer.js"
```js tab
const Sequencer = require('@jest/test-sequencer').default;

class CustomSequencer extends Sequencer {
Expand Down Expand Up @@ -2228,6 +2228,35 @@
module.exports = CustomSequencer;
```

```ts tab
import TestSequencer, { ShardOptions } from '@jest/test-sequencer'

Check failure on line 2232 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

Import "ShardOptions" is only used as types
import { Test } from '@jest/test-result'

Check failure on line 2233 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

All imports in the declaration are only used as types. Use `import type`

export default class CustomSequencer extends TestSequencer {
/**
* Select tests for shard requested via --shard=shardIndex/shardCount
* Sharding is applied before sorting
*/
shard (tests: Test[], { shardIndex, shardCount }: ShardOptions): any[] {

Check failure on line 2240 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

Array type using 'Test[]' is forbidden. Use 'Array<Test>' instead

Check failure on line 2240 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

Array type using 'any[]' is forbidden. Use 'Array<any>' instead
const shardSize = Math.ceil(tests.length / shardCount)
const shardStart = shardSize * (shardIndex - 1)
const shardEnd = shardSize * shardIndex

return [...tests].sort((a, b) => (a.path > b.path ? 1 : -1)).slice(shardStart, shardEnd)
}

/**
* Sort test to determine order of execution

Check failure on line 2249 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

Expected JSDoc block to be aligned
* Sorting is applied after sharding
*/
sort (tests: Test[]): any[] {

Check failure on line 2252 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

Array type using 'Test[]' is forbidden. Use 'Array<Test>' instead

Check failure on line 2252 in docs/Configuration.md

View workflow job for this annotation

GitHub Actions / Lint

Array type using 'any[]' is forbidden. Use 'Array<any>' instead
const copyTests = [...tests]
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1))
}
}

```

Add `custom-sequencer` to your Jest configuration:

```js tab
Expand Down
Loading