-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow customized sorting of test files prior to execution #2968
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6d61e62
feat(parallel-runs): allow custom comparator
erezrokah c9fd038
docs: add docs an recipe
erezrokah d915f78
fix(docs): use correct link to recipe
erezrokah 3fe59a7
fix(docs): 'tests -> test' typo
erezrokah 3b0c1e2
fix(docs): clarify default sorting method
erezrokah 028d632
Update docs/recipes/splitting-tests-ci.md
erezrokah 69069e3
Update docs/recipes/splitting-tests-ci.md
erezrokah 07c3eff
fix: remove comparator serialization
erezrokah 9836cd7
feat: make sorter available to all runs
erezrokah 44cdb86
test: add non-ci sorting test case
erezrokah 1ba1feb
Fix function name and indentation in recipe
novemberborn 2bb174c
Reorder recipe links
novemberborn 4aacf96
Link to new recipe
novemberborn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Splitting tests in CI | ||
|
||
AVA automatically detects whether your CI environment supports parallel builds using [ci-parallel-vars](https://www.npmjs.com/package/ci-parallel-vars). | ||
When parallel builds support is detected, AVA sorts the all detected test files by name, and splits them into chunks. | ||
Each CI machine is assigned a chunk of the tests, and then each chunk is run in parallel. | ||
|
||
To better distribute the tests across the machines, you can configure a custom comparator function. | ||
For example: | ||
erezrokah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**`ava.config.js`:** | ||
|
||
```js | ||
import fs from 'node:fs'; | ||
|
||
// Assuming 'test-data.json' structure is: | ||
// { | ||
// 'tests/test1.js': { order: 1 }, | ||
// 'tests/test2.js': { order: 0 } | ||
// } | ||
const testData = JSON.parse(fs.readFileSync('test-data.json', 'utf8')); | ||
|
||
export default { | ||
ciParallelRunsComparator: (file1, file2) => testData[file1].order - testData[file2].order, | ||
}; | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '2'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '2'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '2'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '1'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '1'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '1'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '0'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '0'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
test('at expected index', t => { | ||
t.is(process.env.CI_NODE_INDEX, '0'); | ||
}); |
5 changes: 5 additions & 0 deletions
5
test-tap/fixture/parallel-runs/custom-comparator/ava.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
files: ['*.cjs'], | ||
// Descending order | ||
ciParallelRunsComparator: (a, b) => b.localeCompare(a, [], {numeric: true}), | ||
}; |
3 changes: 3 additions & 0 deletions
3
test-tap/fixture/parallel-runs/custom-comparator/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.