Skip to content

Commit

Permalink
fix(zone.js): run tests in umd format (#37582)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JiaLiPassion authored and atscott committed Sep 8, 2020
1 parent 45a73dd commit 40096be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/zone.js/lib/browser/define-property.ts
Expand Up @@ -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__;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 40096be

Please sign in to comment.