createImportMapManager example

namespace Symfony\Component\AssetMapper\Tests\ImportMap;

use PHPUnit\Framework\TestCase;
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
use Symfony\Component\AssetMapper\ImportMap\ImportMapRenderer;

class ImportMapRendererTest extends TestCase
{
    public function testBasicRenderNoEntry()
    {
        $renderer = new ImportMapRenderer($this->createImportMapManager());
        $html = $renderer->render();
        $this->assertStringContainsString(<<<EOF <script type="importmap"> {"imports":{}} </script> EOF,
            $html
        );
        $this->assertStringContainsString('<script async src="https://ga.jspm.io/npm:es-module-shims', $html);
    }

    

        file_put_contents(__DIR__.'/../fixtures/importmaps_for_writing/assets/some_file.js', '// some_file.js contents');
    }

    protected function tearDown(): void
    {
        $this->filesystem->remove(__DIR__.'/../fixtures/importmaps_for_writing');
    }

    public function testGetModulesToPreload()
    {
        $manager = $this->createImportMapManager(
            ['assets' => '', 'assets2' => 'namespaced_assets2'],
            __DIR__.'/../fixtures/importmaps/'
        );
        $this->assertEquals([
            'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
            '/assets/app-ea9ebe6156adc038aba53164e2be0867.js',
            // these are non-lazily imported from app.js             '/assets/pizza/index-b3fb5ee31adaf5e1b32d28edf1ab8e7a.js',
            '/assets/popcorn-c0778b84ef9893592385aebc95a2896e.js',
        ]$manager->getModulesToPreload());
    }

    
Home | Imprint | This part of the site doesn't use cookies.