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 name: Starting Saucelabs tunnel service
command: ./tools/saucelabs/sauce-service.sh run command: ./tools/saucelabs/sauce-service.sh run
background: true background: true
- run: yarn tsc -p packages # add module umd tsc compile option so the test can work
- run: yarn tsc -p modules # 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 - run: yarn bazel build //packages/zone.js:npm_package
# Build test fixtures for a test that rely on Bazel-generated fixtures. Note that disabling # 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 # 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 _getOwnPropertyDescriptor: any;
let _create: any; let _create: any;
let unconfigurablesKey: any; let unconfigurablesKey: any;
const registerElementsCallbacks =
['createdCallback', 'attachedCallback', 'detachedCallback', 'attributeChangedCallback'];
export function propertyPatch() { export function propertyPatch() {
zoneSymbol = Zone.__symbol__; zoneSymbol = Zone.__symbol__;
@ -105,9 +103,11 @@ function _tryDefineProperty(obj: any, prop: string, desc: any, originalConfigura
return _defineProperty(obj, prop, desc); return _defineProperty(obj, prop, desc);
} catch (error) { } catch (error) {
let swallowError = false; let swallowError = false;
if (typeof document !== 'undefined' && obj === document && if (prop === 'createdCallback' || prop === 'attachedCallback' ||
registerElementsCallbacks.find(c => c === prop)) { prop === 'detachedCallback' || prop === 'attributeChangedCallback') {
// We only swallow the error in registerElement patch // We only swallow the error in registerElement patch
// this is the work around since some applications
// fail if we throw the error
swallowError = true; swallowError = true;
} }
if (!swallowError) { if (!swallowError) {