Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): Balance frontend tests (#30949)
This adds a jest reporter to record the test durations of our frontend tests. It also changes our runner to look for a results JSON and attempt to balance tests between our CI runners so that each runner finishes around the same time. Previously, the tests were split by the # of test files (so each runner tested the same # of test *files*). Ideally we would add some automation to update the balance JSON file. But even without automating it, this should suffice for awhile (until we add new tests that are quite slow). Some automation ideas: * Scheduled workflow that runs the frontend tests and generates the results json * Generate the json while running tests, upload as GHA artifacts, and for each test run, pull from GHA artifacts and merge/generate the json (since test runs are sharded, they will have separate result json)
- Loading branch information
Showing
10 changed files
with
785 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import {mountWithTheme} from 'sentry-test/reactTestingLibrary'; | ||
import {mountWithTheme, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import Checkbox from 'sentry/components/checkbox'; | ||
|
||
describe('Checkbox', function () { | ||
it('renders', function () { | ||
it('renders', async function () { | ||
const {container} = mountWithTheme(<Checkbox onChange={() => {}} />); | ||
|
||
expect(await screen.findByRole('checkbox')).toBeInTheDocument(); | ||
expect(container).toSnapshot(); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import {mountWithTheme} from 'sentry-test/reactTestingLibrary'; | ||
import {mountWithTheme, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import CircleIndicator from 'sentry/components/circleIndicator'; | ||
|
||
describe('CircleIndicator', function () { | ||
it('renders', function () { | ||
const {container} = mountWithTheme(<CircleIndicator />); | ||
it('renders', async function () { | ||
const {container} = mountWithTheme( | ||
<CircleIndicator data-test-id="circleIndicator" /> | ||
); | ||
|
||
expect(await screen.findByTestId('circleIndicator')).toBeInTheDocument(); | ||
expect(container).toSnapshot(); | ||
}); | ||
}); |
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import {mountWithTheme} from 'sentry-test/reactTestingLibrary'; | ||
import {mountWithTheme, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import ReturnButton from 'sentry/views/settings/components/forms/returnButton'; | ||
|
||
describe('returnButton', function () { | ||
it('renders', function () { | ||
const {container} = mountWithTheme(<ReturnButton />); | ||
it('renders', async function () { | ||
const {container} = mountWithTheme(<ReturnButton data-test-id="returnButton" />); | ||
expect(await screen.findByTestId('returnButton')).toBeInTheDocument(); | ||
expect(container).toSnapshot(); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import {mountWithTheme} from 'sentry-test/reactTestingLibrary'; | ||
import {mountWithTheme, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import Tag from 'sentry/components/tagDeprecated'; | ||
|
||
describe('Tag', function () { | ||
it('renders', function () { | ||
describe('Tag (deprecated)', function () { | ||
it('renders', async function () { | ||
const {container} = mountWithTheme( | ||
<Tag priority="info" border size="small"> | ||
Text to Copy | ||
</Tag> | ||
); | ||
|
||
expect(await screen.findByText('Text to Copy')).toBeInTheDocument(); | ||
|
||
expect(container).toSnapshot(); | ||
}); | ||
}); |
This file contains 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 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 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,34 @@ | ||
/* eslint-env node */ | ||
/* eslint import/no-nodejs-modules:0 */ | ||
const fs = require('fs/promises'); | ||
|
||
class TestBalancer { | ||
constructor(globalConfig, options) { | ||
this._globalConfig = globalConfig; | ||
this._options = options; | ||
|
||
this.results = new Map(); | ||
} | ||
|
||
onTestFileResult(test) { | ||
const path = test.path.replace(this._globalConfig.rootDir, ''); | ||
this.results.set(path, test.duration); | ||
} | ||
|
||
onRunComplete(_contexts, results) { | ||
// results.success always returns false for me? | ||
if ( | ||
results.numTotalTests === 0 || | ||
results.numFailedTests > 0 || | ||
!this._options.enabled || | ||
!this._options.resultsPath | ||
) { | ||
return; | ||
} | ||
|
||
const data = JSON.stringify(Object.fromEntries(this.results), null, 2); | ||
fs.writeFile(this._options.resultsPath, data); | ||
} | ||
} | ||
|
||
module.exports = TestBalancer; |
Oops, something went wrong.