Skip to content
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

Fix test performance #169

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

vojtechszocs
Copy link
Contributor

@vojtechszocs vojtechszocs commented Oct 13, 2022

  • optimize test config for better performance (*)

  • keep using Jest 27.x but update testing-library dependencies

    • @testing-library/react must be 12.x because we're using React 17.x
    • @testing-library/dom was removed since it's pulled in via @testing-library/jest-dom
  • remove import '@testing-library/jest-dom' in test files

    • already covered via common setup packages/common/test-configs/setup-react.ts
  • update collectCoverageFrom to exclude tests and Storybook stories


According to kulshekhar/ts-jest#259 (comment) Jest workers run independently from each other, therefore each worker runs TypeScript compilation on its own, which results in slower times (due to multiple parallel TS compiler executions) which are offset by workers running in parallel.

Local testing via rm -rf /tmp/jest_rs ; yarn test shows that running all tests (includes code coverage collection) with isolatedModules: true is ~3.5 times faster. Since we don't really need full type checking when running tests (already covered by our "build" scripts which fail upon any TS type errors), it makes sense to always use isolatedModules: true.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 13, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vojtechszocs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 13, 2022
@@ -12,8 +10,13 @@ const config: InitialOptionsTsJest = {

collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['json', 'lcov', 'text'],
coverageReporters: ['lcov'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florkbr I think we only need the lcov reporter for integration with the CodeCov service.

Side note, patternfly-react also uses just the lcov reporter, see here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may eventually need the other reporters, but I think this is fine for now.

"test-print-config": "jest --showConfig",
"test-e2e": "yarn workspace @monorepo/e2e-sample-app run test-e2e",
"test-e2e-open": "yarn workspace @monorepo/e2e-sample-app run test-e2e-open",
"test-e2e-ci": "start-server-and-test 'yarn run-samples' '9000|9001' 'yarn test-e2e'",
"eslint": "eslint --max-warnings 0 --ext .js,.jsx,.ts,.tsx",
"eslint-print-config": "eslint --print-config",
"jest": "TZ=UTC jest",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's generally better to set env. variables when calling scripts, rather than inside scripts or programs.

Side note, patternfly-react also sets the timezone this way, see here.

@vojtechszocs
Copy link
Contributor Author

/hold

@vojtechszocs
Copy link
Contributor Author

Some more updates incoming.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 13, 2022
@vojtechszocs
Copy link
Contributor Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 13, 2022
@@ -5,7 +5,7 @@ const config: InitialOptionsTsJest = {
preset: 'ts-jest/presets/js-with-ts',

testMatch: ['**/*.test.(js|jsx|ts|tsx)'],
transformIgnorePatterns: ['/node_modules/(?!(@patternfly)/)'],
transformIgnorePatterns: ['/node_modules/'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this was one of the reasons of the slowdowns, since we instructed ts-jest to transform all PatternFly packages by default.

@vojtechszocs
Copy link
Contributor Author

/retest

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 13, 2022

@vojtechszocs: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@florkbr
Copy link
Contributor

florkbr commented Oct 13, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 13, 2022
@openshift-merge-robot openshift-merge-robot merged commit 874a96c into openshift:main Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants