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

Dependency Extraction Webpack Plugin: Fix test issues #57332

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP


exports[`DependencyExtractionWebpackPlugin Webpack \`combine-assets\` should produce expected output: Asset file 'assets.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`combine-assets\` should produce expected output: Asset file 'assets.php' should match snapshot 1`] = `
"<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => '52d35a0af8a5fb869915'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => '0af6c51a8e6ac934b85a')); "<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'cbe985cf6e1a25d848e5'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => '7f3970305cf0aecb54ab'));
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`combine-assets\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`combine-assets\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -31,12 +31,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`combine-assets\` should pro
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`dynamic-import\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('wp-blob'), 'version' => '47f8a22aa6c04c930f5f'); "<?php return array('dependencies' => array('wp-blob'), 'version' => 'c0e8a6f22065ea096606');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`dynamic-import\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -49,12 +49,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should pro
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '35d057cb1c8a30094445'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'fc2d750fc9e08c5749db');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`function-output-filename\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`function-output-filename\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -72,12 +72,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`function-output-filename\`
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`has-extension-suffix\` should produce expected output: Asset file 'index.min.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`has-extension-suffix\` should produce expected output: Asset file 'index.min.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '27e49c80f699647ec11c'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'c3f17b34fdd974d57d0f');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`has-extension-suffix\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`has-extension-suffix\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -95,26 +95,26 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`has-extension-suffix\` shou
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`no-default\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`no-default\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(), 'version' => 'cdc72dbcdf872f6141c7'); "<?php return array('dependencies' => array(), 'version' => '43880e6c42e7c39fcdf1');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`no-default\` should produce expected output: External modules should match snapshot 1`] = `[]`; exports[`DependencyExtractionWebpackPlugin scripts Webpack \`no-default\` should produce expected output: External modules should match snapshot 1`] = `[]`;


exports[`DependencyExtractionWebpackPlugin Webpack \`no-deps\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`no-deps\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(), 'version' => '091ffcd70d94dd16e773'); "<?php return array('dependencies' => array(), 'version' => '143ed23d4b8be5611fcb');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] = `[]`; exports[`DependencyExtractionWebpackPlugin scripts Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] = `[]`;


exports[`DependencyExtractionWebpackPlugin Webpack \`option-function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`option-function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '35d057cb1c8a30094445'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'fc2d750fc9e08c5749db');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`option-function-output-filename\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`option-function-output-filename\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -132,12 +132,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`option-function-output-file
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`option-output-filename\` should produce expected output: Asset file 'main-foo.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`option-output-filename\` should produce expected output: Asset file 'main-foo.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '35d057cb1c8a30094445'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'fc2d750fc9e08c5749db');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`option-output-filename\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`option-output-filename\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -155,9 +155,9 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`option-output-filename\` sh
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`output-format-json\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] = `"{"dependencies":["lodash"],"version":"abdb687afe609197ad7e"}"`; exports[`DependencyExtractionWebpackPlugin scripts Webpack \`output-format-json\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] = `"{"dependencies":["lodash"],"version":"7bd48470d799a795bf9a"}"`;


exports[`DependencyExtractionWebpackPlugin Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -167,12 +167,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`output-format-json\` should
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`overrides\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`overrides\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('wp-blob', 'wp-script-handle-for-rxjs', 'wp-url'), 'version' => '2a29b245fc3d0509b5a8'); "<?php return array('dependencies' => array('wp-blob', 'wp-script-handle-for-rxjs', 'wp-url'), 'version' => '708c71445153f1d07e4a');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`overrides\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`overrides\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand Down Expand Up @@ -206,22 +206,22 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`overrides\` should produce
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'a.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'a.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('wp-blob'), 'version' => '4514ed711f6c035e0887'); "<?php return array('dependencies' => array('wp-blob'), 'version' => 'd3cda564b538b44d38ef');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'b.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'b.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '168d32b5fb42f9e5d8ce'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '420d636da562e71648f7');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'runtime.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'runtime.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array(), 'version' => 'b4058959bcd0df37cd79'); "<?php return array('dependencies' => array(), 'version' => 'dc673033633cae5c6702');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`runtime-chunk-single\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`runtime-chunk-single\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -239,12 +239,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`runtime-chunk-single\` shou
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`style-imports\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`style-imports\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'beb3f6752168c2983cdd'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '4c661914a4e4d80b8a0b');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`style-imports\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`style-imports\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -262,12 +262,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`style-imports\` should prod
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`wordpress\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '35d057cb1c8a30094445'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'fc2d750fc9e08c5749db');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`wordpress\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand All @@ -285,12 +285,12 @@ exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress\` should produce
] ]
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`wordpress-require\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] = `
"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'ed2bd4e7df46768bb3c2'); "<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '40370eb4ce6428562da6');
" "
`; `;


exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 1`] = ` exports[`DependencyExtractionWebpackPlugin scripts Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 1`] = `
[ [
{ {
"externalType": "window", "externalType": "window",
Expand Down
35 changes: 21 additions & 14 deletions packages/dependency-extraction-webpack-plugin/test/build.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const webpack = require( 'webpack' );
const fixturesPath = path.join( __dirname, 'fixtures' ); const fixturesPath = path.join( __dirname, 'fixtures' );
const configFixtures = fs.readdirSync( fixturesPath ).sort(); const configFixtures = fs.readdirSync( fixturesPath ).sort();


describe( 'DependencyExtractionWebpackPlugin', () => {
afterAll( () => rimraf( path.join( __dirname, 'build' ) ) ); afterAll( () => rimraf( path.join( __dirname, 'build' ) ) );


describe( 'DependencyExtractionWebpackPlugin scripts', () => {
describe.each( configFixtures )( 'Webpack `%s`', ( configCase ) => { describe.each( configFixtures )( 'Webpack `%s`', ( configCase ) => {
const testDirectory = path.join( fixturesPath, configCase ); const testDirectory = path.join( fixturesPath, configCase );
const outputDirectory = path.join( __dirname, 'build', configCase ); const outputDirectory = path.join( __dirname, 'build', configCase );
Expand All @@ -26,10 +26,10 @@ describe( 'DependencyExtractionWebpackPlugin', () => {
// This afterEach is necessary to prevent watched tests from retriggering on every run. // This afterEach is necessary to prevent watched tests from retriggering on every run.
afterEach( () => rimraf( outputDirectory ) ); afterEach( () => rimraf( outputDirectory ) );


test( 'should produce expected output', () => test( 'should produce expected output', async () => {
new Promise( ( resolve ) => {
const options = Object.assign( const options = Object.assign(
{ {
target: 'web',
context: testDirectory, context: testDirectory,
entry: './index.js', entry: './index.js',
mode: 'production', mode: 'production',
Expand All @@ -39,13 +39,27 @@ describe( 'DependencyExtractionWebpackPlugin', () => {
moduleIds: 'named', moduleIds: 'named',
}, },
output: {}, output: {},
experiments: {},
}, },
require( path.join( testDirectory, 'webpack.config.js' ) ) require( path.join( testDirectory, 'webpack.config.js' ) )
); );
options.output.path = outputDirectory; options.output.path = outputDirectory;


webpack( options, ( err, stats ) => { /** @type {webpack.Stats} */
expect( err ).toBeNull(); const stats = await new Promise( ( resolve, reject ) =>
webpack( options, ( err, _stats ) => {
if ( err ) {
return reject( err );
}
resolve( _stats );
} )
);

if ( stats.hasErrors() ) {
throw new Error(
stats.toString( { errors: true, all: false } )
);
}


const assetFiles = glob( const assetFiles = glob(
`${ outputDirectory }/+(*.asset|assets).@(json|php)` `${ outputDirectory }/+(*.asset|assets).@(json|php)`
Expand All @@ -57,9 +71,7 @@ describe( 'DependencyExtractionWebpackPlugin', () => {
assetFiles.forEach( ( assetFile ) => { assetFiles.forEach( ( assetFile ) => {
const assetBasename = path.basename( assetFile ); const assetBasename = path.basename( assetFile );


expect( expect( fs.readFileSync( assetFile, 'utf-8' ) ).toMatchSnapshot(
fs.readFileSync( assetFile, 'utf-8' )
).toMatchSnapshot(
`Asset file '${ assetBasename }' should match snapshot` `Asset file '${ assetBasename }' should match snapshot`
); );
} ); } );
Expand All @@ -73,9 +85,7 @@ describe( 'DependencyExtractionWebpackPlugin', () => {
}; };


// Webpack stats external modules should match. // Webpack stats external modules should match.
const externalModules = Array.from( const externalModules = Array.from( stats.compilation.modules )
stats.compilation.modules
)
.filter( ( { externalType } ) => externalType ) .filter( ( { externalType } ) => externalType )
.sort( compareByModuleIdentifier ) .sort( compareByModuleIdentifier )
.map( ( module ) => ( { .map( ( module ) => ( {
Expand All @@ -86,9 +96,6 @@ describe( 'DependencyExtractionWebpackPlugin', () => {
expect( externalModules ).toMatchSnapshot( expect( externalModules ).toMatchSnapshot(
'External modules should match snapshot' 'External modules should match snapshot'
); );

resolve();
} ); } );
} ) );
} ); } );
} ); } );
Loading