-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Conversation
web_src/js/utils/testhelper.ts
Outdated
// 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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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:
So let's use process.env.TEST
instead.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return process.env.NODE_ENV === 'test'; | |
return process.env.TEST === 'true'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
* 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)
See the comment of isInFrontendUnitTest