From 4f69d04a48269923c6c34d761585bf524629b164 Mon Sep 17 00:00:00 2001 From: Ryan Cebulko Date: Mon, 26 Apr 2021 19:59:08 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Organize=20polyfills=20in?= =?UTF-8?q?=20prep=20for=20type-checking=20and=20core=20extraction=20(#340?= =?UTF-8?q?20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move rest of polyfills unit tests to test/unit/polyfills * Move polyfill stubs into polyfills/stubs and update imports * Revert debugging change --- build-system/test-configs/dep-check-config.js | 18 +++++++++--------- build-system/test-configs/forbidden-terms.js | 8 ++------ .../0.1/amp-intersection-observer-polyfill.js | 2 +- .../0.1/amp-resize-observer-polyfill.js | 2 +- .../test/test-amp-resize-observer-polyfill.js | 2 +- src/polyfills/intersection-observer.js | 2 +- src/polyfills/resize-observer.js | 2 +- .../stubs}/intersection-observer-stub.js | 2 +- .../stubs}/resize-observer-stub.js | 2 +- src/runtime.js | 4 ++-- .../test-array-includes.js} | 2 +- .../test-custom-elements.js} | 2 +- .../test-document-contains.js} | 4 ++-- .../test-domtokenlist-toggle.js} | 4 ++-- .../polyfills/test-intersection-observer.js | 2 +- .../test-math-sign.js} | 4 ++-- .../test-object-assign.js} | 4 ++-- .../test-object-values.js} | 4 ++-- test/unit/polyfills/test-resize-observer.js | 2 +- 19 files changed, 34 insertions(+), 38 deletions(-) rename src/{polyfillstub => polyfills/stubs}/intersection-observer-stub.js (99%) rename src/{polyfillstub => polyfills/stubs}/resize-observer-stub.js (99%) rename test/unit/{test-polyfill-array-includes.js => polyfills/test-array-includes.js} (98%) rename test/unit/{test-polyfill-custom-elements.js => polyfills/test-custom-elements.js} (98%) rename test/unit/{test-polyfill-document-contains.js => polyfills/test-document-contains.js} (96%) rename test/unit/{test-polyfill-domtokenlist-toggle.js => polyfills/test-domtokenlist-toggle.js} (97%) rename test/unit/{test-polyfill-math-sign.js => polyfills/test-math-sign.js} (94%) rename test/unit/{test-polyfill-object-assign.js => polyfills/test-object-assign.js} (93%) rename test/unit/{test-polyfill-object-values.js => polyfills/test-object-values.js} (91%) diff --git a/build-system/test-configs/dep-check-config.js b/build-system/test-configs/dep-check-config.js index 9f4ce6defca2..0f7e8ec8301b 100644 --- a/build-system/test-configs/dep-check-config.js +++ b/build-system/test-configs/dep-check-config.js @@ -428,7 +428,7 @@ exports.rules = [ mustNotDependOn: 'src/base-element.js', }, { - filesMatching: 'src/polyfills/**/*.js', + filesMatching: 'src/polyfills/*.js', mustNotDependOn: '**/*.js', allowlist: [ 'src/polyfills/fetch.js->src/log.js', @@ -436,24 +436,24 @@ exports.rules = [ 'src/polyfills/fetch.js->src/core/types/index.js', 'src/polyfills/fetch.js->src/core/types/object.js', 'src/polyfills/fetch.js->src/utils/bytes.js', - 'src/polyfills/intersection-observer.js->src/polyfillstub/intersection-observer-stub.js', - 'src/polyfills/resize-observer.js->src/polyfillstub/resize-observer-stub.js', + 'src/polyfills/intersection-observer.js->src/polyfills/stubs/intersection-observer-stub.js', + 'src/polyfills/resize-observer.js->src/polyfills/stubs/resize-observer-stub.js', 'src/polyfills/custom-elements.js->src/resolved-promise.js', ], }, { - filesMatching: 'src/polyfillstub/**/*.js', + filesMatching: 'src/polyfills/stubs/**/*.js', mustNotDependOn: '**/*.js', allowlist: [ - 'src/polyfillstub/intersection-observer-stub.js->src/services.js', - 'src/polyfillstub/intersection-observer-stub.js->src/resolved-promise.js', - 'src/polyfillstub/resize-observer-stub.js->src/services.js', - 'src/polyfillstub/resize-observer-stub.js->src/resolved-promise.js', + 'src/polyfills/stubs/intersection-observer-stub.js->src/services.js', + 'src/polyfills/stubs/intersection-observer-stub.js->src/resolved-promise.js', + 'src/polyfills/stubs/resize-observer-stub.js->src/services.js', + 'src/polyfills/stubs/resize-observer-stub.js->src/resolved-promise.js', ], }, { filesMatching: '**/*.js', - mustNotDependOn: 'src/polyfills/**/*.js', + mustNotDependOn: 'src/polyfills/*.js', allowlist: [ // DO NOT add extensions/ files '3p/polyfills.js->src/polyfills/math-sign.js', diff --git a/build-system/test-configs/forbidden-terms.js b/build-system/test-configs/forbidden-terms.js index 6b22127a1950..0889ec854e09 100644 --- a/build-system/test-configs/forbidden-terms.js +++ b/build-system/test-configs/forbidden-terms.js @@ -804,10 +804,6 @@ const forbiddenTermsGlobal = { 'test/unit/test-mustache.js', 'test/unit/test-pass.js', 'test/unit/test-platform.js', - 'test/unit/test-polyfill-document-contains.js', - 'test/unit/test-polyfill-math-sign.js', - 'test/unit/test-polyfill-object-assign.js', - 'test/unit/test-polyfill-object-values.js', 'test/unit/test-pull-to-refresh.js', 'test/unit/test-purifier.js', 'test/unit/test-render-delaying-services.js', @@ -954,8 +950,8 @@ const forbiddenTermsSrcInclusive = { message: bannedTermsHelpString, allowlist: [ 'src/friendly-iframe-embed.js', - 'src/polyfillstub/intersection-observer-stub.js', - 'src/polyfillstub/resize-observer-stub.js', + 'src/polyfills/stubs/intersection-observer-stub.js', + 'src/polyfills/stubs/resize-observer-stub.js', 'src/service/extensions-impl.js', 'src/service/crypto-impl.js', ], diff --git a/extensions/amp-intersection-observer-polyfill/0.1/amp-intersection-observer-polyfill.js b/extensions/amp-intersection-observer-polyfill/0.1/amp-intersection-observer-polyfill.js index c87b566248ea..3d4f230b01a5 100644 --- a/extensions/amp-intersection-observer-polyfill/0.1/amp-intersection-observer-polyfill.js +++ b/extensions/amp-intersection-observer-polyfill/0.1/amp-intersection-observer-polyfill.js @@ -17,7 +17,7 @@ import {installIntersectionObserver} from 'intersection-observer/intersection-observer.install'; import {maybeSetupCrossOriginObserver} from './cross-origin-observer'; import {registerServiceBuilder} from '../../../src/service'; -import {upgradePolyfill} from '../../../src/polyfillstub/intersection-observer-stub'; +import {upgradePolyfill} from '../../../src/polyfills/stubs/intersection-observer-stub'; const TAG = 'amp-intersection-observer-polyfill'; diff --git a/extensions/amp-resize-observer-polyfill/0.1/amp-resize-observer-polyfill.js b/extensions/amp-resize-observer-polyfill/0.1/amp-resize-observer-polyfill.js index 4e4bde196a66..228eed40b30b 100644 --- a/extensions/amp-resize-observer-polyfill/0.1/amp-resize-observer-polyfill.js +++ b/extensions/amp-resize-observer-polyfill/0.1/amp-resize-observer-polyfill.js @@ -16,7 +16,7 @@ import {installResizeObserver} from '../../../third_party/resize-observer-polyfill/ResizeObserver.install'; import {registerServiceBuilder} from '../../../src/service'; -import {upgradePolyfill} from '../../../src/polyfillstub/resize-observer-stub'; +import {upgradePolyfill} from '../../../src/polyfills/stubs/resize-observer-stub'; const TAG = 'amp-resize-observer-polyfill'; diff --git a/extensions/amp-resize-observer-polyfill/0.1/test/test-amp-resize-observer-polyfill.js b/extensions/amp-resize-observer-polyfill/0.1/test/test-amp-resize-observer-polyfill.js index b75ebb4a584d..630e6b2b8ade 100644 --- a/extensions/amp-resize-observer-polyfill/0.1/test/test-amp-resize-observer-polyfill.js +++ b/extensions/amp-resize-observer-polyfill/0.1/test/test-amp-resize-observer-polyfill.js @@ -17,7 +17,7 @@ import { ResizeObserverStub, installStub, -} from '../../../../src/polyfillstub/resize-observer-stub'; +} from '../../../../src/polyfills/stubs/resize-observer-stub'; import {upgradeResizeObserverPolyfill} from '../amp-resize-observer-polyfill'; describes.realWin('amp-resize-observer-polyfill', {amp: false}, (env) => { diff --git a/src/polyfills/intersection-observer.js b/src/polyfills/intersection-observer.js index 305791240867..431ab69de319 100644 --- a/src/polyfills/intersection-observer.js +++ b/src/polyfills/intersection-observer.js @@ -22,7 +22,7 @@ import { installStub, shouldLoadPolyfill, -} from '../polyfillstub/intersection-observer-stub'; +} from '../polyfills/stubs/intersection-observer-stub'; /** * Installs the IntersectionObserver polyfill. There are a few different modes of operation. diff --git a/src/polyfills/resize-observer.js b/src/polyfills/resize-observer.js index 48213c2b91be..02a78998ff8e 100644 --- a/src/polyfills/resize-observer.js +++ b/src/polyfills/resize-observer.js @@ -22,7 +22,7 @@ import { installStub, shouldLoadPolyfill, -} from '../polyfillstub/resize-observer-stub'; +} from '../polyfills/stubs/resize-observer-stub'; /** * Installs the ResizeObserver polyfill. There are a few different modes of diff --git a/src/polyfillstub/intersection-observer-stub.js b/src/polyfills/stubs/intersection-observer-stub.js similarity index 99% rename from src/polyfillstub/intersection-observer-stub.js rename to src/polyfills/stubs/intersection-observer-stub.js index 1f34501f18e7..480ab580437c 100644 --- a/src/polyfillstub/intersection-observer-stub.js +++ b/src/polyfills/stubs/intersection-observer-stub.js @@ -23,7 +23,7 @@ * amp-intersection-observer-polyfill extension. */ -import {Services} from '../services'; +import {Services} from '../../services'; const UPGRADERS = '_upgraders'; const NATIVE = '_native'; diff --git a/src/polyfillstub/resize-observer-stub.js b/src/polyfills/stubs/resize-observer-stub.js similarity index 99% rename from src/polyfillstub/resize-observer-stub.js rename to src/polyfills/stubs/resize-observer-stub.js index e8baac6d5587..b18289ddcfbe 100644 --- a/src/polyfillstub/resize-observer-stub.js +++ b/src/polyfills/stubs/resize-observer-stub.js @@ -23,7 +23,7 @@ * amp-resize-observer-polyfill extension. */ -import {Services} from '../services'; +import {Services} from '../../services'; const UPGRADERS = '_upgraders'; const STUB = '_stub'; diff --git a/src/runtime.js b/src/runtime.js index 277623280029..0a93e2640d18 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -40,8 +40,8 @@ import { import {internalRuntimeVersion} from './internal-version'; import {isExperimentOn, toggleExperiment} from './experiments'; import {reportErrorForWin} from './error-reporting'; -import {scheduleUpgradeIfNeeded as scheduleInObUpgradeIfNeeded} from './polyfillstub/intersection-observer-stub'; -import {scheduleUpgradeIfNeeded as scheduleResObUpgradeIfNeeded} from './polyfillstub/resize-observer-stub'; +import {scheduleUpgradeIfNeeded as scheduleInObUpgradeIfNeeded} from './polyfills/stubs/intersection-observer-stub'; +import {scheduleUpgradeIfNeeded as scheduleResObUpgradeIfNeeded} from './polyfills/stubs/resize-observer-stub'; import {setStyle} from './style'; import {startupChunk} from './chunk'; import {stubElementsForDoc} from './service/custom-element-registry'; diff --git a/test/unit/test-polyfill-array-includes.js b/test/unit/polyfills/test-array-includes.js similarity index 98% rename from test/unit/test-polyfill-array-includes.js rename to test/unit/polyfills/test-array-includes.js index 2bd8426322db..9b7fe12249b6 100644 --- a/test/unit/test-polyfill-array-includes.js +++ b/test/unit/polyfills/test-array-includes.js @@ -14,7 +14,7 @@ * limitations under the License. */ -import {install} from '../../src/polyfills/array-includes'; +import {install} from '../src/polyfills/array-includes'; describes.fakeWin('Array.includes', {}, (env) => { beforeEach(() => { diff --git a/test/unit/test-polyfill-custom-elements.js b/test/unit/polyfills/test-custom-elements.js similarity index 98% rename from test/unit/test-polyfill-custom-elements.js rename to test/unit/polyfills/test-custom-elements.js index 5a0bdfeb50db..72d0bd88c874 100644 --- a/test/unit/test-polyfill-custom-elements.js +++ b/test/unit/polyfills/test-custom-elements.js @@ -14,7 +14,7 @@ * limitations under the License. */ -import {copyProperties, install} from '../../src/polyfills/custom-elements'; +import {copyProperties, install} from '../src/polyfills/custom-elements'; describes.realWin( 'install patches', diff --git a/test/unit/test-polyfill-document-contains.js b/test/unit/polyfills/test-document-contains.js similarity index 96% rename from test/unit/test-polyfill-document-contains.js rename to test/unit/polyfills/test-document-contains.js index a3b1a69339ac..62720b7d1eaf 100644 --- a/test/unit/test-polyfill-document-contains.js +++ b/test/unit/polyfills/test-document-contains.js @@ -14,9 +14,9 @@ * limitations under the License. */ -import {install} from '../../src/polyfills/document-contains'; +import {install} from '../src/polyfills/document-contains'; -describe('HTMLDocument.contains', () => { +describes.sandboxed('HTMLDocument.contains', {}, () => { let fakeWinWithContains; let fakeWinWithoutContains; let nativeContains; diff --git a/test/unit/test-polyfill-domtokenlist-toggle.js b/test/unit/polyfills/test-domtokenlist-toggle.js similarity index 97% rename from test/unit/test-polyfill-domtokenlist-toggle.js rename to test/unit/polyfills/test-domtokenlist-toggle.js index e330022fb864..e9b3ae4c7c1a 100644 --- a/test/unit/test-polyfill-domtokenlist-toggle.js +++ b/test/unit/polyfills/test-domtokenlist-toggle.js @@ -14,8 +14,8 @@ * limitations under the License. */ -import {install} from '../../src/polyfills/domtokenlist'; -import {toArray} from '../../src/core/types/array'; +import {install} from '../src/polyfills/domtokenlist'; +import {toArray} from '../src/core/types/array'; describes.fakeWin( 'DOMTokenList.toggle/add on non-IE', diff --git a/test/unit/polyfills/test-intersection-observer.js b/test/unit/polyfills/test-intersection-observer.js index 0a3fe31d6a0a..70e033b62acd 100644 --- a/test/unit/polyfills/test-intersection-observer.js +++ b/test/unit/polyfills/test-intersection-observer.js @@ -20,7 +20,7 @@ import { resetStubsForTesting, shouldLoadPolyfill, upgradePolyfill, -} from '../../../src/polyfillstub/intersection-observer-stub'; +} from '../../../src/polyfills/stubs/intersection-observer-stub'; import {Services} from '../../../src/services'; import { install, diff --git a/test/unit/test-polyfill-math-sign.js b/test/unit/polyfills/test-math-sign.js similarity index 94% rename from test/unit/test-polyfill-math-sign.js rename to test/unit/polyfills/test-math-sign.js index d72ed67c7c0a..7e81dca82753 100644 --- a/test/unit/test-polyfill-math-sign.js +++ b/test/unit/polyfills/test-math-sign.js @@ -14,9 +14,9 @@ * limitations under the License. */ -import {sign} from '../../src/polyfills/math-sign'; +import {sign} from '../src/polyfills/math-sign'; -describe('Math.sign', () => { +describes.sandboxed('Math.sign', {}, () => { it('returns 1 for positive x', () => { expect(sign(1)).to.equal(1); expect(sign(10)).to.equal(1); diff --git a/test/unit/test-polyfill-object-assign.js b/test/unit/polyfills/test-object-assign.js similarity index 93% rename from test/unit/test-polyfill-object-assign.js rename to test/unit/polyfills/test-object-assign.js index e300eecaa805..45a83cd5fc02 100644 --- a/test/unit/test-polyfill-object-assign.js +++ b/test/unit/polyfills/test-object-assign.js @@ -14,9 +14,9 @@ * limitations under the License. */ -import {assign} from '../../src/polyfills/object-assign'; +import {assign} from '../src/polyfills/object-assign'; -describe('Object.assign', () => { +describes.sandboxed('Object.assign', {}, () => { it('should throw an error if target is null or undefined', () => { expect(() => assign(null, {a: 1})).to.throw( /Cannot convert undefined or null to object/ diff --git a/test/unit/test-polyfill-object-values.js b/test/unit/polyfills/test-object-values.js similarity index 91% rename from test/unit/test-polyfill-object-values.js rename to test/unit/polyfills/test-object-values.js index b184f0ca5a73..bafbb9456a48 100644 --- a/test/unit/test-polyfill-object-values.js +++ b/test/unit/polyfills/test-object-values.js @@ -14,9 +14,9 @@ * limitations under the License. */ -import {values} from '../../src/polyfills/object-values'; +import {values} from '../src/polyfills/object-values'; -describe('Object.values', () => { +describes.sandboxed('Object.values', {}, () => { it('should disallow null and undefined', () => { expect(() => values(null)).to.throw(); expect(() => values(undefined)).to.throw(); diff --git a/test/unit/polyfills/test-resize-observer.js b/test/unit/polyfills/test-resize-observer.js index 3adb90df856b..d45239bd933a 100644 --- a/test/unit/polyfills/test-resize-observer.js +++ b/test/unit/polyfills/test-resize-observer.js @@ -20,7 +20,7 @@ import { resetStubsForTesting, shouldLoadPolyfill, upgradePolyfill, -} from '../../../src/polyfillstub/resize-observer-stub'; +} from '../../../src/polyfills/stubs/resize-observer-stub'; import { install, installForChildWin,