build: remove unnecessary polyfills from tests (#42567)
Removes the polyfills for `MutationObserver` and `setPrototypeOf` from our testing setup, because none of the browsers that we support require them. It also removes a bit of code and one external dependency. PR Close #42567
This commit is contained in:
parent
4001e9d808
commit
a66dd8834c
|
@ -59,7 +59,6 @@ module.exports = function(config) {
|
||||||
included: false,
|
included: false,
|
||||||
watched: false
|
watched: false
|
||||||
},
|
},
|
||||||
{pattern: 'node_modules/mutation-observer/index.js', included: false, watched: false},
|
|
||||||
|
|
||||||
{pattern: 'node_modules/rxjs/**', included: false, watched: false, served: true},
|
{pattern: 'node_modules/rxjs/**', included: false, watched: false, served: true},
|
||||||
'node_modules/reflect-metadata/Reflect.js',
|
'node_modules/reflect-metadata/Reflect.js',
|
||||||
|
|
|
@ -191,7 +191,6 @@
|
||||||
"karma-sauce-launcher": "^2.0.2",
|
"karma-sauce-launcher": "^2.0.2",
|
||||||
"madge": "^4.0.2",
|
"madge": "^4.0.2",
|
||||||
"multimatch": "^5.0.0",
|
"multimatch": "^5.0.0",
|
||||||
"mutation-observer": "^1.0.3",
|
|
||||||
"nock": "^13.0.3",
|
"nock": "^13.0.3",
|
||||||
"ora": "^5.0.0",
|
"ora": "^5.0.0",
|
||||||
"prettier": "^2.3.0",
|
"prettier": "^2.3.0",
|
||||||
|
|
101
test-main.js
101
test-main.js
|
@ -134,42 +134,6 @@ Promise
|
||||||
|
|
||||||
|
|
||||||
function loadCustomElementsPolyfills() {
|
function loadCustomElementsPolyfills() {
|
||||||
var loadedPromise = Promise.resolve();
|
|
||||||
|
|
||||||
// The custom elements polyfill relies on `MutationObserver`.
|
|
||||||
if (!window.MutationObserver) {
|
|
||||||
loadedPromise = loadedPromise
|
|
||||||
.then(function() {
|
|
||||||
return System.import('node_modules/mutation-observer/index.js');
|
|
||||||
})
|
|
||||||
.then(function(MutationObserver) {
|
|
||||||
window.MutationObserver = MutationObserver;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// The custom elements polyfill relies on `Object.setPrototypeOf()`.
|
|
||||||
if (!Object.setPrototypeOf) {
|
|
||||||
var getDescriptor = function getDescriptor(obj, prop) {
|
|
||||||
var descriptor;
|
|
||||||
while (obj && !descriptor) {
|
|
||||||
descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
|
||||||
obj = Object.getPrototypeOf(obj);
|
|
||||||
}
|
|
||||||
return descriptor || {};
|
|
||||||
};
|
|
||||||
var setPrototypeOf = function setPrototypeOf(obj, proto) {
|
|
||||||
for (var prop in proto) {
|
|
||||||
if (!obj.hasOwnProperty(prop)) {
|
|
||||||
Object.defineProperty(obj, prop, getDescriptor(proto, prop));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.defineProperty(setPrototypeOf, '$$shimmed', {value: true});
|
|
||||||
Object.setPrototypeOf = setPrototypeOf;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The custom elements polyfill will patch properties and methods on `(HTML)Element` and `Node`
|
// The custom elements polyfill will patch properties and methods on `(HTML)Element` and `Node`
|
||||||
// (among others), including `(HTML)Element#innerHTML` and `Node#removeChild()`:
|
// (among others), including `(HTML)Element#innerHTML` and `Node#removeChild()`:
|
||||||
// https://github.com/webcomponents/custom-elements/blob/4f7072c0dbda4beb505d16967acfffd33337b325/src/Patch/Element.js#L28-L73
|
// https://github.com/webcomponents/custom-elements/blob/4f7072c0dbda4beb505d16967acfffd33337b325/src/Patch/Element.js#L28-L73
|
||||||
|
@ -209,46 +173,39 @@ function loadCustomElementsPolyfills() {
|
||||||
// Allow ES5 functions as custom element constructors.
|
// Allow ES5 functions as custom element constructors.
|
||||||
'node_modules/@webcomponents/custom-elements/src/native-shim.js';
|
'node_modules/@webcomponents/custom-elements/src/native-shim.js';
|
||||||
|
|
||||||
loadedPromise = loadedPromise
|
return System.import(polyfillPath).then(function() {
|
||||||
.then(function() {
|
// `packages/compiler/test/schema/schema_extractor.ts` relies on
|
||||||
return System.import(polyfillPath);
|
// `HTMLElement.name`, but custom element polyfills will replace
|
||||||
})
|
// `HTMLElement` with an anonymous function.
|
||||||
.then(function() {
|
Object.defineProperty(HTMLElement, 'name', {value: 'HTMLElement'});
|
||||||
// `packages/compiler/test/schema/schema_extractor.ts` relies on
|
|
||||||
// `HTMLElement.name`, but custom element polyfills will replace
|
|
||||||
// `HTMLElement` with an anonymous function.
|
|
||||||
Object.defineProperty(HTMLElement, 'name', {value: 'HTMLElement'});
|
|
||||||
|
|
||||||
// Create helper functions on `window` for patching/restoring
|
// Create helper functions on `window` for patching/restoring
|
||||||
// properties/methods.
|
// properties/methods.
|
||||||
Object.keys(patchConfig).forEach(function(prop) {
|
Object.keys(patchConfig).forEach(function(prop) {
|
||||||
var patchMethod = '$$patch_' + prop;
|
var patchMethod = '$$patch_' + prop;
|
||||||
var restoreMethod = '$$restore_' + prop;
|
var restoreMethod = '$$restore_' + prop;
|
||||||
|
|
||||||
if (!patchTargets[prop]) {
|
if (!patchTargets[prop]) {
|
||||||
// No patching detected. Create no-op functions.
|
// No patching detected. Create no-op functions.
|
||||||
window[patchMethod] = window[restoreMethod] = function() {};
|
window[patchMethod] = window[restoreMethod] = function() {};
|
||||||
} else {
|
} else {
|
||||||
var patchTarget = patchTargets[prop];
|
var patchTarget = patchTargets[prop];
|
||||||
var originalDescriptor = originalDescriptors[prop];
|
var originalDescriptor = originalDescriptors[prop];
|
||||||
var patchedDescriptor =
|
var patchedDescriptor = Object.getOwnPropertyDescriptor(patchTarget, prop);
|
||||||
Object.getOwnPropertyDescriptor(patchTarget, prop);
|
|
||||||
|
|
||||||
window[patchMethod] = function() {
|
window[patchMethod] = function() {
|
||||||
Object.defineProperty(patchTarget, prop, patchedDescriptor);
|
Object.defineProperty(patchTarget, prop, patchedDescriptor);
|
||||||
};
|
};
|
||||||
window[restoreMethod] = function() {
|
window[restoreMethod] = function() {
|
||||||
Object.defineProperty(patchTarget, prop, originalDescriptor);
|
Object.defineProperty(patchTarget, prop, originalDescriptor);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Restore `prop`. The patch will be manually applied only during the
|
// Restore `prop`. The patch will be manually applied only during the
|
||||||
// `@angular/elements` tests that need it.
|
// `@angular/elements` tests that need it.
|
||||||
window[restoreMethod]();
|
window[restoreMethod]();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return loadedPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onlySpecFiles(path) {
|
function onlySpecFiles(path) {
|
||||||
|
|
|
@ -9178,11 +9178,6 @@ multimatch@*, multimatch@^5.0.0:
|
||||||
arrify "^2.0.1"
|
arrify "^2.0.1"
|
||||||
minimatch "^3.0.4"
|
minimatch "^3.0.4"
|
||||||
|
|
||||||
mutation-observer@^1.0.3:
|
|
||||||
version "1.0.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/mutation-observer/-/mutation-observer-1.0.3.tgz#42e9222b101bca82e5ba9d5a7acf4a14c0f263d0"
|
|
||||||
integrity sha512-M/O/4rF2h776hV7qGMZUH3utZLO/jK7p8rnNgGkjKUw8zCGjRQPxB8z6+5l8+VjRUQ3dNYu4vjqXYLr+U8ZVNA==
|
|
||||||
|
|
||||||
mute-stdout@^1.0.0:
|
mute-stdout@^1.0.0:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/mute-stdout/-/mute-stdout-1.0.1.tgz#acb0300eb4de23a7ddeec014e3e96044b3472331"
|
resolved "https://registry.yarnpkg.com/mute-stdout/-/mute-stdout-1.0.1.tgz#acb0300eb4de23a7ddeec014e3e96044b3472331"
|
||||||
|
|
Loading…
Reference in New Issue