Skip to content

Get rid of the side effect of importing amp-abc.js #23839

@lannka

Description

@lannka
import {AmpAnalytics} from '../amp-analytics';

The above line in tests would have a side effect causing amp-analytics custom element registered on global window. We should consider split all extension js to

in amp-analytics/0.1/amp-analytics.js

export class AmpAnalytics {
  ...
}

in amp-analytics/0.1/main.js


AMP.extension(TAG, '0.1', AMP => {
  // Register doc-service factory.
  AMP.registerServiceForDoc(
    'amp-analytics-instrumentation',
    InstrumentationService
  );
  AMP.registerServiceForDoc('activity', Activity);
  installLinkerReaderService(AMP.win);
  AMP.registerServiceForDoc('amp-analytics-variables', VariableService);
  // Register the element.
  AMP.registerElement(TAG, AmpAnalytics);
});

No unit test should ever import main.js, amp.js etc.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions