hono icon indicating copy to clipboard operation
hono copied to clipboard

test: introduce build tests

Open usualoma opened this issue 1 year ago • 8 comments

We should test for the following aspects.

  • The product of the build does not contain unintended files (as a result of tree shaking).
  • The file size has not increased unintentionally.

As for the file size check, information could be added as a comment to each pull request (like coverage) in the future, but this pull request does not go that far.

This pull request will enable the following outputs to be obtained.

vitest -c .vitest.config/build.ts --run

 ✓ build_tests/build.test.ts (5)
   ✓ app-jsx (1)
     ✓ should not be included /jsx/dom/ in sources
   ✓ app-simple (2)
     ✓ should not be included http-exception in sources
     ✓ should not be included /jsx/ in sources
   ✓ jsx-dom-all (1)
     ✓ should not be included /helper/html in sources
   ✓ jsx-dom-simple (1)
     ✓ should not be included /jsx/base in sources

tsx ./build_tests/report.ts

app-jsx: 8.9 KiB
app-simple: 7.5 KiB
jsx-dom-all: 5.2 KiB
jsx-dom-simple: 3.5 KiB

The author should do the following, if applicable

  • [x] Add tests
  • [x] Run tests
  • [x] bun run format:fix && bun run lint:fix to format the code
  • [x] Add TSDoc/JSDoc to document the code

usualoma avatar Jun 15 '24 00:06 usualoma

Codecov Report

Attention: Patch coverage is 0% with 118 lines in your changes missing coverage. Please review.

Project coverage is 93.90%. Comparing base (614dff0) to head (9483d22).

Files Patch % Lines
build_tests/src/jsx-dom-all.tsx 0.00% 32 Missing :warning:
build_tests/src/jsx-dom-simple.tsx 0.00% 27 Missing :warning:
build_tests/build.ts 0.00% 24 Missing :warning:
build_tests/src/app-jsx.tsx 0.00% 15 Missing :warning:
build_tests/report.ts 0.00% 12 Missing :warning:
build_tests/src/app-simple.ts 0.00% 8 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2975      +/-   ##
==========================================
- Coverage   94.73%   93.90%   -0.84%     
==========================================
  Files         136      142       +6     
  Lines       13335    13453     +118     
  Branches     2251     2284      +33     
==========================================
  Hits        12633    12633              
- Misses        702      820     +118     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 15 '24 04:06 codecov[bot]

Errors in the test have been fixed. The content added by this pull request is excluded from the coverage measurement.

usualoma avatar Jun 15 '24 04:06 usualoma

Hi @usualoma

I also thought we had to have a measuring bundle/file size like yours. This seems great, but I have another idea. Please wait a bit until I show you it. Thanks!

yusukebe avatar Jun 16 '24 21:06 yusukebe

Hey @usualoma

Regarding this matter, I think we should first monitor bundle sizes. Ideally, the CI will tell us the current bundle sizes and how they have increased from the main branch.

To do it, I found 3rd party library instead of implementing it by myself. There are several libraries, but the Size Limit seems to be best:

https://github.com/ai/size-limit

I've tried a little with CLI in my machine:

CleanShot 2024-06-21 at 23 47 57@2x

At first glance, I couldn't find a good way to integrate with GitHub Actions, though it has integrations with CircleCI, TravisCI, etc (perhaps we may have to use them to store the results?).

Anyway, we can use it or refer to it.

yusukebe avatar Jun 21 '24 14:06 yusukebe

@yusukebe Regarding github action, I think this is what you are looking for : https://github.com/andresz1/size-limit-action

Jayllyz avatar Jun 21 '24 14:06 Jayllyz

@Jayllyz

Ohh, thanks. Can this compare the result of PR with the main's?

yusukebe avatar Jun 21 '24 15:06 yusukebe

I don't think so. A workaround would be to update the size limit during the release workflow. (I don't know if this is the best solution).

EDIT : This one compare with the base branch. https://github.com/preactjs/compressed-size-action

Jayllyz avatar Jun 21 '24 15:06 Jayllyz

@yusukebe Thank you! I too think "ai/size-limit" is cool.

Bundle size is certainly the most important.

I was hoping in addition to that to be able to check that 'certain modules are not included', as achieved in the pull request https://github.com/honojs/hono/pull/2885. I think "a module is included that shouldn't be included" could be considered an obvious "bug".

However, it is expensive to keep track of 'modules that should not be included' in detail, and at the moment it would be fine to just use 'ai/size-limit'.

usualoma avatar Jun 21 '24 20:06 usualoma