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
feat(ci): Balance frontend tests #30949
Changes from 15 commits
6f2c4c3
fa6adcf
22b6d83
990bf90
898bcf5
cc4e09d
b269d83
057628a
f92a8e3
f38d2a4
381398d
8b499be
bca6d60
e207d1b
9d2ccdb
f998e28
24e1285
aade7e9
78ad50e
4a7c9e1
edde211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
}); | ||
}); |
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(); | ||
}); | ||
}); |
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(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,11 @@ describe('Dashboards > Create', function () { | |
// @ts-ignore | ||
body: TestStubs.Dashboard([{}], {id: '1', title: 'Custom Errors'}), | ||
}); | ||
|
||
mountGlobalModal(initialData.routerContext); | ||
|
||
const widgetTitle = 'Widget Title'; | ||
|
||
mountWithTheme( | ||
<CreateDashboard | ||
organization={initialData.organization} | ||
|
@@ -81,9 +85,8 @@ describe('Dashboards > Create', function () { | |
// Wrap with act because GlobalSelectionHeaderContainer triggers update | ||
await tick(); | ||
}); | ||
screen.getByTestId('widget-add').click(); | ||
|
||
mountGlobalModal(); | ||
screen.getByTestId('widget-add').click(); | ||
|
||
// Add a custom widget to the dashboard | ||
(await screen.findByText('Custom Widget')).click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here too? |
||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you write this in typescript as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not possible unfortunately: jestjs/jest#8810 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be
userEvent.click(screen.getByTestId('widget-add'))
?