-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: env unit test fails on Windows #41070
Conversation
plugins: [ | ||
'./relative', | ||
'../parent', | ||
`${ os.homedir() }/home`, |
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 use os.homeDir()
because tilde (~
) is not recognized as a home directory path in Windows.
@@ -653,24 +682,24 @@ describe( 'readConfig', () => { | |||
expect( config.env.development.mappings ).toEqual( { | |||
test1: { | |||
basename: 'test1', | |||
path: '/test1', | |||
path: resolve( '/test1' ), |
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.
resolve
may seem meaningless, but it is necessary to remove the drive letter (e.g. C:
) on Windows OS.
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.
Could you add this as a comment in the code?
Size Change: 0 B Total Size: 1.24 MB ℹ️ View Unchanged
|
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.
Nice, thank you for working on this! I just left a couple style notes that might make the code more clear :)
@@ -251,17 +264,17 @@ describe( 'readConfig', () => { | |||
pluginSources: [ | |||
{ | |||
type: 'local', | |||
path: expect.stringMatching( /^\/.*relative$/ ), | |||
path: expect.stringMatching( /^(\/||\\).*relative$/ ), |
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.
Would it be easier to match based on path.sep
for these tests?
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.
if we use variables( path.sep
) in a regular expression, we need to generate a regExp
.
I used this method because I think newRregExp
makes the code verbose.
Also, I could not figure out how to embed a non-escaping backslash in the regexp 😅
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.
Thanks, that makes sense!
@@ -653,24 +682,24 @@ describe( 'readConfig', () => { | |||
expect( config.env.development.mappings ).toEqual( { | |||
test1: { | |||
basename: 'test1', | |||
path: '/test1', | |||
path: resolve( '/test1' ), |
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.
Could you add this as a comment in the code?
Thanks for the review! |
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.
These changes make sense to me. Only caveat is that it seems easy enough for something to cause a regression in this area, as we don't have a way to run CI tests in Windows (as far as I know). That said, hopefully these changes are enough to encourage any future devs to be mindful of including os-specific paths :)
Part of #39388
What?
This PR fixes a problem that wp-env unit test fails on Windows OS.
This PR will allow Jest unit tests to be complete correctly on Windows OS.
Why?
The main cause is that the path separator of the
.wp-json
values read viareadConfig
is backslashes in Windows OS.The information on this variable is as follows:
See variable information
How?
I replaced forward slashes with OS delimiter and fixed other OS-dependent problems.
Testing Instructions
One test
npm run test-unit -- ./packages/env/lib/config/test/config.js
All tests
npm run test-unit
If the tests fails, narrow down
maxWorkers
as follows: