diff --git a/packages/env/lib/config/test/config.js b/packages/env/lib/config/test/config.js index 5a79cb6d4f724a..1d5060f11ed799 100644 --- a/packages/env/lib/config/test/config.js +++ b/packages/env/lib/config/test/config.js @@ -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: 'tt1-blocks@0.4.3', 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', }, } ); diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 45e0edb0064695..41440738212cb6 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -6,6 +6,10 @@ - Enable by default code formatting for JSON files in the `format` command ([#40994](https://github.com/WordPress/gutenberg/pull/40994)). You can opt-out of this behavior by providing a custom file matcher, example: `wp-scripts format src/**/*.js`. +### Bug Fixes + +- Fix: env unit test fails on Windows ([#41070](https://github.com/WordPress/gutenberg/pull/41070)) + ## 23.0.0 (2022-05-04) ### Breaking Changes