Skip to content

Commit d456136

Browse files
authored
Switch pre-commit hook to pre-push; fix Jest --findRelatedTests behavior (#7163)
1 parent 0f42263 commit d456136

File tree

13 files changed

+56
-32
lines changed

13 files changed

+56
-32
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"**/@types/react": "^18",
6161
"react-focus-lock": "^2.9.5"
6262
},
63-
"pre-commit": [
63+
"pre-push": [
6464
"test-staged"
6565
],
6666
"dependencies": {
@@ -220,7 +220,7 @@
220220
"postcss-inline-svg": "^4.1.0",
221221
"postcss-loader": "^7.0.1",
222222
"postcss-styled-syntax": "^0.4.0",
223-
"pre-commit": "^1.2.2",
223+
"pre-push": "^0.1.4",
224224
"prettier": "^2.8.8",
225225
"process": "^0.11.10",
226226
"prop-types": "^15.6.0",

scripts/test-staged.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
const { execSync } = require('child_process');
22

3-
// find names of staged files
4-
const stagedFiles = execSync('git diff --cached --name-only --diff-filter=ACMR')
5-
.toString()
6-
.split(/[\r\n]+/g);
7-
8-
// execute tests related to the staged files
9-
execSync(`yarn test-unit --findRelatedTests ${stagedFiles.join(' ')}`, {
3+
// https://jestjs.io/docs/cli#--changedsince
4+
execSync(`yarn test-unit --changedSince main`, {
105
stdio: 'inherit',
116
});

scripts/tests/test-staged.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { execSync } = require('child_process');
2+
const path = require('path');
3+
const euiRoot = path.resolve(__dirname, '../../'); // NOTE: CI lists the EUI project root as app/ instead of eui/
4+
5+
describe('test-staged.js', () => {
6+
it('does not have --findRelatedTests regressions due to imports from src/components', () => {
7+
const outputString = execSync(
8+
'yarn test-unit --findRelatedTests --listTests src/components/beacon/beacon.tsx',
9+
{ cwd: euiRoot }
10+
).toString();
11+
const output = outputString
12+
.split('\n')
13+
.filter((item) => item.endsWith('test.tsx'));
14+
15+
expect(
16+
output[0].endsWith('src/components/tour/tour_step.test.tsx')
17+
).toBeTruthy();
18+
expect(
19+
output[1].endsWith('src/components/beacon/beacon.test.tsx')
20+
).toBeTruthy();
21+
22+
expect(output[2]).toBeUndefined();
23+
});
24+
});

src-docs/src/components/guide_section/_utils.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const dedent = require('dedent');
2-
const { renderJsSourceCode } = require('./_utils.js');
1+
import dedent from 'dedent';
2+
import { renderJsSourceCode } from './_utils';
33

44
describe('renderJsSourceCode', () => {
55
describe('EUI imports', () => {
@@ -41,8 +41,8 @@ describe('renderJsSourceCode', () => {
4141
expect(
4242
renderJsSourceCode({
4343
default: dedent(`
44-
import { EuiButton, EuiFlexGroup, EuiFlexItem } from '../../../src/components';
45-
import { useGeneratedHtmlId } from '../../../src/services';
44+
import { EuiButton, EuiFlexGroup, EuiFlexItem } from '../../src/components';
45+
import { useGeneratedHtmlId } from '../../src/services';
4646
4747
export default () => <EuiCode>{useGeneratedHtmlId()}</EuiCode>;`),
4848
})

src/components/card/card.styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { css } from '@emotion/react';
10-
import { EuiCardProps } from '..';
10+
1111
import {
1212
euiPaddingSize,
1313
euiSupportsHas,
@@ -18,6 +18,7 @@ import {
1818
import { UseEuiTheme } from '../../services';
1919
import { euiButtonColor } from '../../themes/amsterdam/global_styling/mixins';
2020

21+
import { EuiCardProps } from './card';
2122
const paddingKey = 'm';
2223
const halfPaddingKey = 's';
2324

src/components/card/card.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import { requiredProps } from '../../test';
1212
import { shouldRenderCustomStyles } from '../../test/internal';
1313
import { render } from '../../test/rtl';
1414

15-
import { EuiCard, ALIGNMENTS } from './card';
16-
17-
import { EuiIcon, EuiAvatar, EuiI18n } from '../../components';
15+
import { EuiIcon } from '../icon';
16+
import { EuiAvatar } from '../avatar';
17+
import { EuiI18n } from '../i18n';
1818
import { COLORS, SIZES } from '../panel/panel';
1919

20+
import { EuiCard, ALIGNMENTS } from './card';
21+
2022
describe('EuiCard', () => {
2123
test('is rendered', () => {
2224
const { container } = render(

src/components/card/card.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ import React, {
1515
} from 'react';
1616
import classNames from 'classnames';
1717

18-
import { CommonProps, ExclusiveUnion } from '../common';
1918
import {
2019
getSecureRelForTarget,
2120
useEuiTheme,
2221
cloneElementWithCss,
2322
} from '../../services';
23+
import { useGeneratedHtmlId } from '../../services/accessibility';
24+
import { validateHref } from '../../services/security/href_validator';
25+
26+
import { CommonProps, ExclusiveUnion } from '../common';
2427
import { EuiText } from '../text';
2528
import { EuiTitle } from '../title';
2629
import { EuiBetaBadge, EuiBetaBadgeProps } from '../badge/beta_badge';
2730
import { EuiIconProps } from '../icon';
28-
import { EuiCardSelect, EuiCardSelectProps } from './card_select';
29-
import { useGeneratedHtmlId } from '../../services/accessibility';
30-
import { validateHref } from '../../services/security/href_validator';
3131
import { EuiPanel, EuiPanelProps } from '../panel';
3232
import { EuiSpacer } from '../spacer';
33+
34+
import { EuiCardSelect, EuiCardSelectProps } from './card_select';
3335
import {
3436
euiCardBetaBadgeStyles,
3537
euiCardStyles,

src/components/popover/popover.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { act } from '@testing-library/react';
1212
import { shouldRenderCustomStyles } from '../../test/internal';
1313
import { requiredProps } from '../../test/required_props';
1414
import { render } from '../../test/rtl';
15-
import { EuiFocusTrap } from '../';
15+
16+
import { keys } from '../../services';
17+
import { EuiFocusTrap } from '../focus_trap';
1618

1719
import {
1820
EuiPopover,
@@ -21,8 +23,6 @@ import {
2123
PopoverAnchorPosition,
2224
} from './popover';
2325

24-
import { keys } from '../../services';
25-
2626
const actAdvanceTimersByTime = (time: number) =>
2727
act(() => jest.advanceTimersByTime(time));
2828

src/global_styling/functions/typography.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import React, { FunctionComponent, PropsWithChildren } from 'react';
1010
import { renderHook } from '@testing-library/react';
1111

12-
import { EuiProvider } from '../../components';
12+
import { EuiProvider } from '../../components/provider';
1313
import { useEuiTheme } from '../../services';
1414
import { EuiThemeFontScales, EuiThemeFontUnits } from '../variables/typography';
1515

src/services/theme/hooks.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import React from 'react';
1010
import { render, act } from '@testing-library/react';
1111
import { renderHook } from '../../test/rtl';
1212

13-
import { EuiProvider } from '../../components';
13+
import { EuiProvider } from '../../components/provider';
1414

1515
import { setEuiDevProviderWarning } from './warning';
1616
import {

0 commit comments

Comments
 (0)