-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: env unit test fails on Windows (#41070)
* Fix: env config unit test fails on Windows * remove blank lines * update readme * polish codes
- Loading branch information
Showing
2 changed files
with
75 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
const { readFile, stat } = require( 'fs' ).promises; | ||
const os = require( 'os' ); | ||
const { join, resolve } = require( 'path' ); | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -101,13 +102,17 @@ describe( 'readConfig', () => { | |
process.env.WP_ENV_HOME = 'here/is/a/path'; | ||
const configWith = await readConfig( '.wp-env.json' ); | ||
expect( | ||
configWith.workDirectoryPath.includes( 'here/is/a/path' ) | ||
configWith.workDirectoryPath.includes( | ||
join( 'here', 'is', 'a', 'path' ) | ||
) | ||
).toBe( true ); | ||
|
||
process.env.WP_ENV_HOME = undefined; | ||
const configWithout = await readConfig( '.wp-env.json' ); | ||
expect( | ||
configWithout.workDirectoryPath.includes( 'here/is/a/path' ) | ||
configWithout.workDirectoryPath.includes( | ||
join( 'here', 'is', 'a', 'path' ) | ||
) | ||
).toBe( false ); | ||
|
||
process.env.WP_ENV_HOME = oldEnvHome; | ||
|
@@ -126,13 +131,17 @@ describe( 'readConfig', () => { | |
process.env.WP_ENV_HOME = 'here/is/a/path'; | ||
const configWith = await readConfig( '.wp-env.json' ); | ||
expect( | ||
configWith.workDirectoryPath.includes( 'here/is/a/path' ) | ||
configWith.workDirectoryPath.includes( | ||
join( 'here', 'is', 'a', 'path' ) | ||
) | ||
).toBe( true ); | ||
|
||
process.env.WP_ENV_HOME = undefined; | ||
const configWithout = await readConfig( '.wp-env.json' ); | ||
expect( | ||
configWithout.workDirectoryPath.includes( 'here/is/a/path' ) | ||
configWithout.workDirectoryPath.includes( | ||
join( 'here', 'is', 'a', 'path' ) | ||
) | ||
).toBe( false ); | ||
|
||
process.env.WP_ENV_HOME = oldEnvHome; | ||
|
@@ -242,26 +251,31 @@ describe( 'readConfig', () => { | |
readFile.mockImplementation( () => | ||
Promise.resolve( | ||
JSON.stringify( { | ||
plugins: [ './relative', '../parent', '~/home' ], | ||
plugins: [ | ||
'./relative', | ||
'../parent', | ||
`${ os.homedir() }/home`, | ||
], | ||
} ) | ||
) | ||
); | ||
const config = await readConfig( '.wp-env.json' ); | ||
|
||
expect( config.env.development ).toMatchObject( { | ||
pluginSources: [ | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*relative$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*relative$/ ), | ||
basename: 'relative', | ||
}, | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*parent$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*parent$/ ), | ||
basename: 'parent', | ||
}, | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*home$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*home$/ ), | ||
basename: 'home', | ||
}, | ||
], | ||
|
@@ -270,17 +284,17 @@ describe( 'readConfig', () => { | |
pluginSources: [ | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*relative$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*relative$/ ), | ||
basename: 'relative', | ||
}, | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*parent$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*parent$/ ), | ||
basename: 'parent', | ||
}, | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*home$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*home$/ ), | ||
basename: 'home', | ||
}, | ||
], | ||
|
@@ -310,28 +324,28 @@ describe( 'readConfig', () => { | |
expect( config.env.development.pluginSources ).toEqual( [ | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*test1a$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*test1a$/ ), | ||
basename: 'test1a', | ||
}, | ||
] ); | ||
expect( config.env.development.themeSources ).toEqual( [ | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*test2a$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*test2a$/ ), | ||
basename: 'test2a', | ||
}, | ||
] ); | ||
expect( config.env.tests.pluginSources ).toEqual( [ | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*test1b$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*test1b$/ ), | ||
basename: 'test1b', | ||
}, | ||
] ); | ||
expect( config.env.tests.themeSources ).toEqual( [ | ||
{ | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*test2b$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*test2b$/ ), | ||
basename: 'test2b', | ||
}, | ||
] ); | ||
|
@@ -345,15 +359,19 @@ describe( 'readConfig', () => { | |
expect( config.env.development ).toMatchObject( { | ||
coreSource: { | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*relative$/ ), | ||
testsPath: expect.stringMatching( /^\/.*tests-relative$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*relative$/ ), | ||
testsPath: expect.stringMatching( | ||
/^(\/||\\).*tests-relative$/ | ||
), | ||
}, | ||
} ); | ||
expect( config.env.tests ).toMatchObject( { | ||
coreSource: { | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*relative$/ ), | ||
testsPath: expect.stringMatching( /^\/.*tests-relative$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*relative$/ ), | ||
testsPath: expect.stringMatching( | ||
/^(\/||\\).*tests-relative$/ | ||
), | ||
}, | ||
} ); | ||
} ); | ||
|
@@ -378,21 +396,21 @@ describe( 'readConfig', () => { | |
type: 'git', | ||
url: 'https://github.com/WordPress/gutenberg.git', | ||
ref: 'master', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
{ | ||
type: 'git', | ||
url: 'https://github.com/WordPress/gutenberg.git', | ||
ref: 'trunk', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
{ | ||
type: 'git', | ||
url: 'https://github.com/WordPress/gutenberg.git', | ||
ref: '5.0', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
{ | ||
|
@@ -401,7 +419,7 @@ describe( 'readConfig', () => { | |
'https://github.com/WordPress/theme-experiments.git', | ||
ref: '[email protected]', | ||
path: expect.stringMatching( | ||
/^\/.*theme-experiments\/tt1-blocks$/ | ||
/^(\/||\\).*theme-experiments(\/||\\)tt1-blocks$/ | ||
), | ||
basename: 'tt1-blocks', | ||
}, | ||
|
@@ -431,28 +449,32 @@ describe( 'readConfig', () => { | |
type: 'zip', | ||
url: | ||
'https://downloads.wordpress.org/plugin/gutenberg.zip', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: | ||
'https://downloads.wordpress.org/plugin/gutenberg.8.1.0.zip', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: | ||
'https://downloads.wordpress.org/theme/twentytwenty.zip', | ||
path: expect.stringMatching( /^\/.*twentytwenty$/ ), | ||
path: expect.stringMatching( | ||
/^(\/||\\).*twentytwenty$/ | ||
), | ||
basename: 'twentytwenty', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: | ||
'https://downloads.wordpress.org/theme/twentytwenty.1.3.zip', | ||
path: expect.stringMatching( /^\/.*twentytwenty$/ ), | ||
path: expect.stringMatching( | ||
/^(\/||\\).*twentytwenty$/ | ||
), | ||
basename: 'twentytwenty', | ||
}, | ||
], | ||
|
@@ -482,34 +504,42 @@ describe( 'readConfig', () => { | |
type: 'zip', | ||
url: | ||
'https://www.example.com/test/path/to/gutenberg.zip', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: | ||
'https://www.example.com/test/path/to/gutenberg.8.1.0.zip', | ||
path: expect.stringMatching( /^\/.*gutenberg.8.1.0$/ ), | ||
path: expect.stringMatching( | ||
/^(\/||\\).*gutenberg.8.1.0$/ | ||
), | ||
basename: 'gutenberg.8.1.0', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: | ||
'https://www.example.com/test/path/to/twentytwenty.zip', | ||
path: expect.stringMatching( /^\/.*twentytwenty$/ ), | ||
path: expect.stringMatching( | ||
/^(\/||\\).*twentytwenty$/ | ||
), | ||
basename: 'twentytwenty', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: | ||
'https://www.example.com/test/path/to/twentytwenty.1.3.zip', | ||
path: expect.stringMatching( /^\/.*twentytwenty.1.3$/ ), | ||
path: expect.stringMatching( | ||
/^(\/||\\).*twentytwenty.1.3$/ | ||
), | ||
basename: 'twentytwenty.1.3', | ||
}, | ||
{ | ||
type: 'zip', | ||
url: 'https://example.com/twentytwenty.1.3.zip', | ||
path: expect.stringMatching( /^\/.*twentytwenty.1.3$/ ), | ||
path: expect.stringMatching( | ||
/^(\/||\\).*twentytwenty.1.3$/ | ||
), | ||
basename: 'twentytwenty.1.3', | ||
}, | ||
], | ||
|
@@ -550,12 +580,12 @@ describe( 'readConfig', () => { | |
const matchObj = { | ||
test: { | ||
type: 'local', | ||
path: expect.stringMatching( /^\/.*relative$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*relative$/ ), | ||
basename: 'relative', | ||
}, | ||
test2: { | ||
type: 'git', | ||
path: expect.stringMatching( /^\/.*gutenberg$/ ), | ||
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ), | ||
basename: 'gutenberg', | ||
}, | ||
}; | ||
|
@@ -653,24 +683,25 @@ describe( 'readConfig', () => { | |
expect( config.env.development.mappings ).toEqual( { | ||
test1: { | ||
basename: 'test1', | ||
path: '/test1', | ||
// resolve is required to remove drive letters on Windows. | ||
path: resolve( '/test1' ), | ||
type: 'local', | ||
}, | ||
test3: { | ||
basename: 'test3', | ||
path: '/test3', | ||
path: resolve( '/test3' ), | ||
type: 'local', | ||
}, | ||
} ); | ||
expect( config.env.tests.mappings ).toEqual( { | ||
test1: { | ||
basename: 'test1', | ||
path: '/test1', | ||
path: resolve( '/test1' ), | ||
type: 'local', | ||
}, | ||
test2: { | ||
basename: 'test2', | ||
path: '/test2', | ||
path: resolve( '/test2' ), | ||
type: 'local', | ||
}, | ||
} ); | ||
|
@@ -702,14 +733,14 @@ describe( 'readConfig', () => { | |
expect( config.env.development.mappings ).toEqual( { | ||
test: { | ||
basename: 'test3', | ||
path: '/test3', | ||
path: resolve( '/test3' ), | ||
type: 'local', | ||
}, | ||
} ); | ||
expect( config.env.tests.mappings ).toEqual( { | ||
test: { | ||
basename: 'test2', | ||
path: '/test2', | ||
path: resolve( '/test2' ), | ||
type: 'local', | ||
}, | ||
} ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters