Skip to content

Commit

Permalink
🧪 Enable experiment to upgrade amp-fit-text 0.1 to 1.0 (#32526)
Browse files Browse the repository at this point in the history
* Auto upgrade amp-fit-text to Bento version

* Import BaseElement instead

* Remove unused export

* Remove helper

* Remove experiment

* Skip e2e test if experiment is on

* Define in experiments-const.json

* Remove disable eslint

* "WEB" is not a supported environment

* Remove other disable eslint

* (empty)
  • Loading branch information
caroqliu committed Feb 9, 2021
1 parent 19a6038 commit aace6d6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build-system/global-configs/experiments-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
"expiration_date_utc": "2021-06-30",
"define_experiment_constant": "INI_LOAD_INOB"
},
"experimentC": {}
"experimentC": {
"name": "Bento performance analysis experiment",
"environment": "AMP",
"issue": "https://github.com/ampproject/amphtml/issues/32523",
"expiration_date_utc": "2021-12-31",
"define_experiment_constant": "BENTO_AUTO_UPGRADE"
}
}
1 change: 1 addition & 0 deletions build-system/global-configs/experiments-const.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BENTO_AUTO_UPGRADE": false,
"INI_LOAD_INOB": false,
"WITHIN_VIEWPORT_INOB": false
}
3 changes: 3 additions & 0 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ exports.rules = [
'extensions/amp-youtube/1.0/component.js->extensions/amp-video/1.0/video-iframe.js',
'extensions/amp-youtube/1.0/component.js->extensions/amp-video/1.0/video-wrapper.js',

// Bento amp-fit-text
'extensions/amp-fit-text/0.1/amp-fit-text.js->extensions/amp-fit-text/1.0/base-element.js',

// Amp geo in group enum
'extensions/amp-a4a/0.1/amp-a4a.js->extensions/amp-geo/0.1/amp-geo-in-group.js',
'extensions/amp-consent/0.1/consent-config.js->extensions/amp-geo/0.1/amp-geo-in-group.js',
Expand Down
14 changes: 14 additions & 0 deletions extensions/amp-fit-text/0.1/amp-fit-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
* limitations under the License.
*/

import {BaseElement as BentoFitText} from '../../amp-fit-text/1.0/base-element';
import {CSS} from '../../../build/amp-fit-text-0.1.css';
import {getLengthNumeral, isLayoutSizeDefined} from '../../../src/layout';
import {isAmphtml} from '../../../src/format';
import {px, setStyle, setStyles} from '../../../src/style';
import {throttle} from '../../../src/utils/rate-limit';

Expand Down Expand Up @@ -59,6 +61,18 @@ class AmpFitText extends AMP.BaseElement {
this.textContent_ = '';
}

/** @override */
upgradeCallback() {
if (
BENTO_AUTO_UPGRADE &&
typeof Element.prototype.attachShadow == 'function' &&
isAmphtml(this.element.ownerDocument)
) {
return new BentoFitText(this.element);
}
return null;
}

/** @override */
isLayoutSupported(layout) {
return isLayoutSizeDefined(layout);
Expand Down
4 changes: 4 additions & 0 deletions extensions/amp-fit-text/0.1/test-e2e/test-amp-fit-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describes.endtoend(
});

it('should render in correct font-size', async () => {
if (BENTO_AUTO_UPGRADE) {
this.skipTest();
}

await verifyElementStyles(await selectContentDiv('test1'), {
'font-size': '32px',
});
Expand Down

0 comments on commit aace6d6

Please sign in to comment.