fix(zone.js): run tests in umd format (#37582)

Since the `defineProperty` not swallow error any longer, now the tests compile
source code in `commonjs` mode, and the code generated includes the code like this
```
Object.defineProperty(exports, "__esModule", {value: true});
```

And the `exports` is undefined in some browsers, but the error is swallowed before
this PR, and all tests run successfully, but it is not correct behavior. After this PR,
the code above failed. So we need to compile the source code in `umd` mode.

PR Close #37582
This commit is contained in:
JiaLiPassion 2020-09-01 08:26:55 +09:00 committed by atscott
parent 45a73dddfd
commit 40096bee00
2 changed files with 8 additions and 6 deletions

View File

@ -653,8 +653,10 @@ jobs:
name: Starting Saucelabs tunnel service
command: ./tools/saucelabs/sauce-service.sh run
background: true
- run: yarn tsc -p packages
- run: yarn tsc -p modules
# add module umd tsc compile option so the test can work
# properly in the legacy browsers
- run: yarn tsc -p packages --module UMD
- run: yarn tsc -p modules --module UMD
- run: yarn bazel build //packages/zone.js:npm_package
# Build test fixtures for a test that rely on Bazel-generated fixtures. Note that disabling
# specific tests which are reliant on such generated fixtures is not an option as SystemJS

View File

@ -16,8 +16,6 @@ let _defineProperty: any;
let _getOwnPropertyDescriptor: any;
let _create: any;
let unconfigurablesKey: any;
const registerElementsCallbacks =
['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
export function propertyPatch() {
zoneSymbol = Zone.__symbol__;
@ -105,9 +103,11 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
return _defineProperty(obj, prop, desc);
} catch (error) {
let swallowError = false;
if (typeof document !== 'undefined' && obj === document &&
registerElementsCallbacks.find(c => c === prop)) {
if (prop === 'createdCallback' || prop === 'attachedCallback' ||
prop === 'detachedCallback' || prop === 'attributeChangedCallback') {
// We only swallow the error in registerElement patch
// this is the work around since some applications
// fail if we throw the error
swallowError = true;
}
if (!swallowError) {