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

Make frontend unit test code could know it is in testing #32656

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

wxiaoguang
Copy link
Contributor

See the comment of isInFrontendUnitTest

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 27, 2024
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 27, 2024
@wxiaoguang wxiaoguang mentioned this pull request Nov 27, 2024
// even if backend is in testing mode, frontend could be complied in production mode
// so this function only checks if the frontend is in unit testing mode (usually from *.test.ts files)
export function isInFrontendUnitTest() {
return process.env.NODE_ENV === 'test';
Copy link
Member

Choose a reason for hiding this comment

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

Can you check if NODE_ENV=production make test-frontend still sets the correct test env? I assume it will, but good to verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes or no, I guess it isn't in this PR's scope and it doesn't affect anything.

Copy link
Member

Choose a reason for hiding this comment

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

Well it certainly is "in scope" if your solution does not work in all cases, and some users are known to alter NODE_ENV.

Copy link
Member

@silverwind silverwind Nov 27, 2024

Choose a reason for hiding this comment

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

I tested it and vitest does not set test when the env var is present:

https://github.com/vitest-dev/vitest/blob/7b35d13a6f235ce2b5bb406107980d36c19e9a2f/packages/vitest/src/node/pool.ts#L125

So let's use process.env.TEST instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not my solution, that's the official approach.

There is no trick, but only process.env.NODE_ENV, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
return process.env.NODE_ENV === 'test';
return process.env.TEST === 'true';

Copy link
Member

Choose a reason for hiding this comment

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

See below. I think it's a more robust approach, now using process.env.TEST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already done in #32656 (comment)

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 27, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 27, 2024
@lunny lunny merged commit 5a50b27 into go-gitea:main Nov 27, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.24.0 milestone Nov 27, 2024
@wxiaoguang wxiaoguang deleted the fix-frontend-test branch November 28, 2024 01:45
@wxiaoguang wxiaoguang modified the milestones: 1.24.0, 1.23.0 Nov 28, 2024
@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Nov 28, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Nov 28, 2024
* giteaofficial/main:
  Allow cropping an avatar before setting it (go-gitea#32565)
  Add webpack EnvironmentPlugin (go-gitea#32661)
  Move team related functions to service layer (go-gitea#32537)
  Make frontend unit test code could know it is in testing (go-gitea#32656)
  Add priority to protected branch (go-gitea#32286)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Feb 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend size/S Denotes a PR that changes 10-29 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants