From 40096bee004943024303ffa709ea324946da8dec Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Tue, 1 Sep 2020 08:26:55 +0900 Subject: [PATCH] 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 --- .circleci/config.yml | 6 ++++-- packages/zone.js/lib/browser/define-property.ts | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7da0ae353667b..77c82697202a6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/packages/zone.js/lib/browser/define-property.ts b/packages/zone.js/lib/browser/define-property.ts index 3fb59766529f3..a053487aac41d 100644 --- a/packages/zone.js/lib/browser/define-property.ts +++ b/packages/zone.js/lib/browser/define-property.ts @@ -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) {