magento / m2-devtools

Helpful in-browser debugging/inspection tools for the Magento 2 Front-End
Open Software License 3.0
170 stars 48 forks source link

Fix bug in generate.ts for layout handles with multiple results #26

Closed DrewML closed 5 years ago

DrewML commented 5 years ago

This issue is a:

Environment

Question Answer
Magento version N/A/
Browser + version N/A
node.js version (node -v) N/A
npm version (npm -v) N/A

Description

A change was made that allows you to collect multiple results from different pages for the same layout handle (think multiple separate product pages).

The intention is to merge together all modules under the same layout handle. However, right now, an AMD module identifier found from any 2 recording results gets pushed to commons. This means that, if you visit 2 product pages, 100% of those modules end up in commons, and you do not get a bundle for product pages.

Failing Test

// generate.test.ts
test('Correctly merges > 1 results for same layout handle', () => {
    const modulesByPageType = [
        {
            url: 'http://www.site.com/product1',
            pageConfigType: 'catalog-product-view',
            modules: ['product/common', 'product/common2', 'common/foo'],
        },
        {
            url: 'http://www.site.com/product2',
            pageConfigType: 'catalog-product-view',
            modules: ['product/common', 'product/common2', 'common/foo'],
        },
        {
            url: 'http://www.site.com/',
            pageConfigType: 'cms-index-index',
            modules: ['common/foo'],
        },
    ];
    const { modules } = generate(modulesByPageType, sampleRequireConfig);
    const byName = modulesByName(modules);

    expect(byName['bundles/shared'].include).toEqual(['common/foo']);
    expect(byName['bundles/catalog-product-view'].include).toEqual([
        'product/common',
        'product/common2',
    ]);
});
    expect(received).toEqual(expected)

    Expected value to equal:
      ["common/foo"]
    Received:
      ["product/common", "product/common2", "common/foo"]

Expected result:

See failing test above.

DrewML commented 5 years ago

Closed by #27.