Skip to content

Commit

Permalink
✅ Remove special casing for tests from amp-mustache extension registr…
Browse files Browse the repository at this point in the history
…ation (ampproject#22598)

* Remove special casing for tests from amp-mustache production code

* Remove all `unregisterTemplate`s
  • Loading branch information
danielrozenberg authored Jun 4, 2019
1 parent 7e8509a commit d5acade
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
*/

AMP.extension('amp-mustache', '0.2', function(AMP) {
// First, unregister template to avoid "Duplicate template type"
// error due to multiple versions of amp-mustache in the same unit test run.
// This is due to transpilation of test code to ES5 which uses require() and,
// unlike import, causes side effects (AMP.registerTemplate) to be run.
// For unit tests, it doesn't actually matter which version of amp-mustache is
// registered. Integration tests should only have one script version included.
if (getMode().test) {
Services.templatesFor(window).unregisterTemplate(TAG);
}
AMP.registerTemplate(TAG, AmpMustache);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
* limitations under the License.
*/
(function (AMP) {
// First, unregister template to avoid "Duplicate template type"
// error due to multiple versions of amp-mustache in the same unit test run.
// This is due to transpilation of test code to ES5 which uses require() and,
// unlike import, causes side effects (AMP.registerTemplate) to be run.
// For unit tests, it doesn't actually matter which version of amp-mustache is
// registered. Integration tests should only have one script version included.
if (getMode().test) {
Services.templatesFor(window).unregisterTemplate(TAG);
}

AMP.registerTemplate(TAG, AmpMustache);
})(self.AMP);

Expand Down
11 changes: 0 additions & 11 deletions extensions/amp-mustache/0.1/amp-mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

import {Services} from '../../../src/services';
import {dict} from '../../../src/utils/object';
import {getMode} from '../../../src/mode';
import {isExperimentOn} from '../../../src/experiments';
import {iterateCursor, templateContentClone} from '../../../src/dom';
import {
Expand Down Expand Up @@ -155,14 +153,5 @@ export class AmpMustache extends AMP.BaseTemplate {
}

AMP.extension(TAG, '0.1', function(AMP) {
// First, unregister template to avoid "Duplicate template type"
// error due to multiple versions of amp-mustache in the same unit test run.
// This is due to transpilation of test code to ES5 which uses require() and,
// unlike import, causes side effects (AMP.registerTemplate) to be run.
// For unit tests, it doesn't actually matter which version of amp-mustache is
// registered. Integration tests should only have one script version included.
if (getMode().test) {
Services.templatesFor(window).unregisterTemplate(TAG);
}
AMP.registerTemplate(TAG, AmpMustache);
});
11 changes: 0 additions & 11 deletions extensions/amp-mustache/0.2/amp-mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

import {Services} from '../../../src/services';
import {dict} from '../../../src/utils/object';
import {getMode} from '../../../src/mode';
import {isExperimentOn} from '../../../src/experiments';
import {iterateCursor, templateContentClone} from '../../../src/dom';
import {purifyHtml, purifyTagsForTripleMustache} from '../../../src/purifier';
Expand Down Expand Up @@ -146,14 +144,5 @@ export class AmpMustache extends AMP.BaseTemplate {
}

AMP.extension(TAG, '0.2', function(AMP) {
// First, unregister template to avoid "Duplicate template type"
// error due to multiple versions of amp-mustache in the same unit test run.
// This is due to transpilation of test code to ES5 which uses require() and,
// unlike import, causes side effects (AMP.registerTemplate) to be run.
// For unit tests, it doesn't actually matter which version of amp-mustache is
// registered. Integration tests should only have one script version included.
if (getMode().test) {
Services.templatesFor(window).unregisterTemplate(TAG);
}
AMP.registerTemplate(TAG, AmpMustache);
});
14 changes: 1 addition & 13 deletions src/service/template-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import {Deferred} from '../utils/promise';
import {Services} from '../services';
import {dev, devAssert, userAssert} from '../log';
import {getMode} from '../mode';
import {dev, userAssert} from '../log';
import {getService, registerServiceBuilder} from '../service';
import {rootNodeFor, scopedQuerySelector} from '../dom';

Expand Down Expand Up @@ -374,17 +373,6 @@ export class Templates {
}
}

/**
* For testing only.
* @param {string} type
* @visibleForTesting
*/
unregisterTemplate(type) {
devAssert(getMode().test, 'Should only be used in test mode.');
delete this.templateClassMap_[type];
delete this.templateClassResolvers_[type];
}

/**
* @param {!BaseTemplate} impl
* @param {!JsonObject} data
Expand Down

0 comments on commit d5acade

Please sign in to comment.