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

Refactor: Improve internal code #378

Merged
merged 19 commits into from
Nov 21, 2023
Merged

Refactor: Improve internal code #378

merged 19 commits into from
Nov 21, 2023

Conversation

bryanjtc
Copy link
Member

@bryanjtc bryanjtc commented Nov 8, 2023

Pull Request Summary

Description:
This pull request introduces several changes and additions to the codebase. These changes enhance the codebase and improve error handling and type checking. Below is a detailed summary of the changes made in each file:

.github/workflows/typecheck.yml

  • Added a new workflow file named typecheck.yml.
  • This workflow runs on push and pull request events.
  • It uses Node.js version 18.x and installs dependencies using the bahmutov/npm-install action.
  • Finally, it runs the TypeScript type checker using yarn tsc.

src/config/jest-playwright.ts

  • Modified the browsers property by checking if TEST_BROWSERS exists.

src/csf/transformCsf.ts

  • Introduced a result variable and assigned the input to it.
  • Checked if testPrefixer exists, and if so, performed some additional operations.
  • If result is falsy, it's set to a null literal.

src/csf/transformCsf.test.ts

  • Created a new test file for the transformCsf function and prefixFunction.

src/playwright/transformPlaywright.ts

  • Updated the makeTitleFactory function to ensure the returned value is always a string.

src/setup-page.ts

  • Added conditional logic to check if testRunnerConfig exists before calling the defaultPrepare function.

src/test-storybook.ts

  • Improved error handling when an error occurs, including checking if the error is an instance of Error and creating an error object with a stack if necessary.

src/util/getCliOptions.test.ts

  • Added a new test case that checks whether default options are returned when no options are passed.
  • Added new test cases that check whether string options, boolean options and extra arguments are handled correctly.

src/util/getCliOptions.ts

  • Updated the handling of boolean and string options, ensuring they are correctly processed.

src/util/getParsedCliOptions.test.ts

  • Created a new test file for the getParsedCliOptions function.

src/util/getParsedCliOptions.ts

  • Improved error handling to catch and handle Commander errors.
  • Added an unknown option handling and warning for unknown options.

src/util/getStorybookMetadata.ts

  • Updated the getStorybookMetadata function to handle cases where configDir is not provided.

src/util/getTestRunnerConfig.test.ts

  • Added a new test file for the getTestRunnerConfig function.

src/util/getTestRunnerConfig.ts

  • Updated the getTestRunnerConfig function to handle cases where configDir is not provided.

tsconfig.json

  • Updated the TypeScript configuration to include stricter type checking and set noEmit to true.

Changes in jest.config.js:

  • ModuleNameMapper Added: A new moduleNameMapper section has been included to map various '@storybook/test-runner/playwright' paths to corresponding '/playwright' paths.

Additions in src/config/jest-playwright.test.ts:

  • New File Creation: This file introduces unit tests for the Jest configuration in a Playwright environment.

Additions in src/playwright/hooks.test.ts:

  • New File Creation: This file introduces unit tests for the hooks in a Playwright environment.

Additions in src/playwright/hooks.test.ts:

  • New File Creation: This file introduces unit tests for the hooks in a Playwright environment.

From #323

📦 Published PR as canary version: 0.15.3--canary.378.1843bee.0

✨ Test out this PR locally via:

npm install @storybook/[email protected]
# or 
yarn add @storybook/[email protected]

Copy link

codecov bot commented Nov 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (53fdd0f) 80.64% compared to head (e2afb66) 96.10%.

❗ Current head e2afb66 differs from pull request most recent head 1843bee. Consider uploading reports for the commit 1843bee to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             next     #378       +/-   ##
===========================================
+ Coverage   80.64%   96.10%   +15.46%     
===========================================
  Files          12       14        +2     
  Lines         217      257       +40     
  Branches       56       69       +13     
===========================================
+ Hits          175      247       +72     
+ Misses         42       10       -32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bryanjtc bryanjtc changed the title Enable strict mode Enable strict mode and added new tests Nov 8, 2023
@bryanjtc
Copy link
Member Author

bryanjtc commented Nov 8, 2023

@yannbf This is part 1 from the changes proposed in #323
This pr doesn't have any breaking changes. It should be easier to review.

@bryanjtc bryanjtc changed the title Enable strict mode and added new tests Enable strict mode and add new tests Nov 8, 2023
- Added Jest configuration file (jest.config.js) to project root.
- Created a new test file (jest-playwright.test.ts) in the src/config directory.
- This commit introduces the necessary setup for running tests using Jest Playwright.
- The Jest configuration file allows customization of Jest's behavior.
- The new test file will be used for writing tests using the Jest Playwright library.
- This addition enhances the project's testing capabilities and enables UI testing with Playwright.
This commit adds a new test file for testing the hooks functionality in Playwright.
@bryanjtc bryanjtc self-assigned this Nov 11, 2023
bryanjtc and others added 11 commits November 16, 2023 12:53
…ecessary conditional

The makePlayTest function in the transformCsf file has been simplified to remove an unnecessary conditional statement. The metaOrStoryPlay parameter is now optional, indicated by the use of the "?" symbol. This change was made to improve code readability and reduce complexity.
The TestRunnerConfig interface in the hooks.ts file now includes an optional tags property. This property allows users to include, exclude, or skip specific tags when running tests. The tags are defined as annotations in the story or meta. This change provides more flexibility and control over test execution based on specific tags.
- Updated the entry configuration in tsup.config.ts to include all JavaScript and TypeScript files in the src directory, excluding declaration files and test files.
- This change was made to ensure that only the necessary source files are included in the build process, improving build performance and reducing bundle size.
@yannbf
Copy link
Member

yannbf commented Nov 21, 2023

Hey @bryanjtc! Thank you so much for all these contributions! I finally have time to go through them, and will start reviewing, adding work on top of and responding to them.

@yannbf yannbf added the patch Increment the patch version when merged label Nov 21, 2023
@yannbf yannbf changed the title Enable strict mode and add new tests Refactor: Enable strict mode and improve internal code Nov 21, 2023
@yannbf yannbf changed the title Refactor: Enable strict mode and improve internal code Refactor: Improve internal code Nov 21, 2023
Copy link

🚀 PR was released in v0.16.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants