Skip to content

Commit 40096be

Browse files
JiaLiPassionatscott
authored andcommitted
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
1 parent 45a73dd commit 40096be

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

.circleci/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,10 @@ jobs:
653653
name: Starting Saucelabs tunnel service
654654
command: ./tools/saucelabs/sauce-service.sh run
655655
background: true
656-
- run: yarn tsc -p packages
657-
- run: yarn tsc -p modules
656+
# add module umd tsc compile option so the test can work
657+
# properly in the legacy browsers
658+
- run: yarn tsc -p packages --module UMD
659+
- run: yarn tsc -p modules --module UMD
658660
- run: yarn bazel build //packages/zone.js:npm_package
659661
# Build test fixtures for a test that rely on Bazel-generated fixtures. Note that disabling
660662
# specific tests which are reliant on such generated fixtures is not an option as SystemJS

packages/zone.js/lib/browser/define-property.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ let _defineProperty: any;
1616
let _getOwnPropertyDescriptor: any;
1717
let _create: any;
1818
let unconfigurablesKey: any;
19-
const registerElementsCallbacks =
20-
['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
2119

2220
export function propertyPatch() {
2321
zoneSymbol = Zone.__symbol__;
@@ -105,9 +103,11 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
105103
return _defineProperty(obj, prop, desc);
106104
} catch (error) {
107105
let swallowError = false;
108-
if (typeof document !== 'undefined' && obj === document &&
109-
registerElementsCallbacks.find(c => c === prop)) {
106+
if (prop === 'createdCallback' || prop === 'attachedCallback' ||
107+
prop === 'detachedCallback' || prop === 'attributeChangedCallback') {
110108
// We only swallow the error in registerElement patch
109+
// this is the work around since some applications
110+
// fail if we throw the error
111111
swallowError = true;
112112
}
113113
if (!swallowError) {

0 commit comments

Comments
 (0)