Skip to content

Commit

Permalink
test: rebalance test suite (#5972)
Browse files Browse the repository at this point in the history
* test: glob no longer in use by test suite

* test: remove manual balancing of tests

* chore: remove tools package

* test: match workflow parallelism count to matrix machine count

* chore: npm audit fix

* chore: update documentation around test balancing
  • Loading branch information
mrstork authored Jan 2, 2025
1 parent ef21c2b commit 314ce08
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 432 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
env:
# split tests across multiple machines
CI_NODE_INDEX: ${{ matrix.machine }}
CI_NODE_TOTAL: 4
CI_NODE_TOTAL: 5
with:
timeout_minutes: 30
max_attempts: 3
Expand Down
6 changes: 0 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ See our [testing documentation](packages/build/tests/README.md) to learn about o

After submitting the pull request, please make sure the Continuous Integration checks (GitHub actions) are passing.

### Testing in CI

To speed up CI, we load balance the tests across multiple machines. The information required to load balance the tests
is stored in `tests-metadata.json`, and later used by our test [runner](ava.config.js#L10). To regenerate the data (e.g.
when adding a new test file) run `npm test:measure` and commit the changes to GitHub.

### Testing locally

The `@netlify/testing` package will need to be built regardless of which package you are working on. In order to do this
Expand Down
20 changes: 0 additions & 20 deletions ava.base.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
import fs, { existsSync } from 'fs'
import path from 'path'
import process from 'process'

import { isCI } from 'ci-info'
import * as execa from 'execa'

const { execaCommand } = execa
if (process.argv.includes('-w')) {
execaCommand('tsc -w', { cleanup: true })
}

// `tests-metadata.json` is created by running `npx lerna run test:measure --scope @netlify/build`
const testData = existsSync('tests-metadata.json') ? JSON.parse(fs.readFileSync('tests-metadata.json', 'utf-8')) : {}

const getOrder = (file) => {
const fileRelative = path.relative(process.cwd(), file).replace(/\\/g, '/')
if (testData[fileRelative]) {
return testData[fileRelative].order
}

console.warn(`Missing test metadata for ${fileRelative}`)
return Number.MAX_SAFE_INTEGER
}

const sortTestFiles = (file1, file2) => getOrder(file1) - getOrder(file2)

const config = {
files: ['packages/**/tests/*.{cjs,mjs,js}', 'packages/**/tests/**/tests.{cjs,mjs,js}'],
verbose: true,
Expand All @@ -34,8 +16,6 @@ const config = {
environmentVariables: {
FORCE_COLOR: '1',
},
// we only sort in CI to split efficiently across machines
...(isCI && { sortTestFiles }),
}

export default config
Loading

0 comments on commit 314ce08

Please sign in to comment.