Skip to content

Commit

Permalink
Add test for correct merge with regular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 17, 2024
1 parent 539e38b commit 751887b
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion tests/phpunit/tests/script-modules/wpScriptModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public static function data_invalid_script_module_data(): array {
/**
* @ticket 61500
*/
public function test_added_module_appears_in_importmap() {
public function test_included_module_appears_in_importmap() {
$this->script_modules->register( 'dependency', '/dep.js' );
$this->script_modules->register( 'example', '/example.js', array( 'dependency' ) );

Expand All @@ -927,7 +927,53 @@ public function test_added_module_appears_in_importmap() {
$this->assertSame( array(), $this->get_preloaded_script_modules() );

$import_map = $this->get_import_map();
$this->assertCount( 2, $import_map );
$this->assertArrayHasKey( 'example', $import_map );
$this->assertArrayHasKey( 'dependency', $import_map );
}

/**
* @ticket 61500
*/
public function test_included_modules_concat_With_enqueued_dependencies() {
$this->script_modules->register( 'dependency-enqueued', '/dep.js' );
$this->script_modules->register(
'enqueued',
'/example.js',
array(
array(
'id' => 'dependency-enqueued',
'import' => 'dynamic',
),
)
);
$this->script_modules->enqueue( 'enqueued' );

$this->script_modules->register( 'dependency', '/dep.js' );
$this->script_modules->register( 'example', '/example.js', array( 'dependency' ) );

// Only dependency-enqueued should be printed.
$enqueued = $this->get_enqueued_script_modules();
$this->assertCount( 1, $enqueued );
$this->assertArrayHasKey( 'enqueued', $enqueued );
$this->assertSame( array(), $this->get_preloaded_script_modules() );

$import_map = $this->get_import_map();
$this->assertCount( 1, $import_map );
$this->assertArrayHasKey( 'dependency-enqueued', $import_map );

// After including, the importmap should be populated.
$this->script_modules->include_in_import_map( 'example' );

$enqueued = $this->get_enqueued_script_modules();
$this->assertCount( 1, $enqueued );
$this->assertArrayHasKey( 'enqueued', $enqueued );
$this->assertSame( array(), $this->get_preloaded_script_modules() );

$import_map = $this->get_import_map();
$this->assertCount( 3, $import_map );
$this->assertArrayHasKey( 'dependency-enqueued', $import_map );
$this->assertArrayHasKey( 'dependency', $import_map );
$this->assertArrayHasKey( 'example', $import_map );
}
}

0 comments on commit 751887b

Please sign in to comment.