From 87ce4e997b6f49cdbcc1cb1de097ed8965d4bcdd Mon Sep 17 00:00:00 2001 From: JiaLiPassion Date: Fri, 19 Jul 2019 01:42:23 +0900 Subject: [PATCH] fix(zone.js): zone-mix should import correct browser module (#31628) Close #31626 PR Close #31628 --- .circleci/config.yml | 4 +++ packages/zone.js/lib/mix/rollup-mix.ts | 5 +--- packages/zone.js/package.json | 5 +++- packages/zone.js/test/extra/electron.js | 37 +++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 packages/zone.js/test/extra/electron.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 472aec31d9..7e4f6cc65e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -673,6 +673,10 @@ jobs: # Run zone.js tools tests - run: yarn --cwd packages/zone.js promisetest - run: yarn --cwd packages/zone.js promisefinallytest + - run: yarn bazel build //packages/zone.js:npm_package && + cp dist/bin/packages/zone.js/npm_package/dist/zone-mix.js ./packages/zone.js/test/extra/ && + cp dist/bin/packages/zone.js/npm_package/dist/zone-patch-electron.js ./packages/zone.js/test/extra/ && + yarn --cwd packages/zone.js electrontest workflows: version: 2 diff --git a/packages/zone.js/lib/mix/rollup-mix.ts b/packages/zone.js/lib/mix/rollup-mix.ts index 57e4877737..0569be4bc2 100644 --- a/packages/zone.js/lib/mix/rollup-mix.ts +++ b/packages/zone.js/lib/mix/rollup-mix.ts @@ -6,8 +6,5 @@ * found in the LICENSE file at https://angular.io/license */ -import '../zone'; -import '../common/promise'; -import '../common/to-string'; -import '../browser/browser'; +import '../browser/rollup-main'; import '../node/node'; diff --git a/packages/zone.js/package.json b/packages/zone.js/package.json index 139cfc4102..bdcbf79ba8 100644 --- a/packages/zone.js/package.json +++ b/packages/zone.js/package.json @@ -15,13 +15,16 @@ "test": "test" }, "devDependencies": { + "domino": "2.1.2", "mocha": "^3.1.2", + "mock-require": "3.0.3", "promises-aplus-tests": "^2.1.2", "typescript": "~3.4.2" }, "scripts": { "promisetest": "tsc -p . && node ./promise-test.js", - "promisefinallytest": "tsc -p . && mocha promise.finally.spec.js" + "promisefinallytest": "tsc -p . && mocha promise.finally.spec.js", + "electrontest": "cd test/extra && node electron.js" }, "repository": { "type": "git", diff --git a/packages/zone.js/test/extra/electron.js b/packages/zone.js/test/extra/electron.js new file mode 100644 index 0000000000..8f34d31d96 --- /dev/null +++ b/packages/zone.js/test/extra/electron.js @@ -0,0 +1,37 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +var domino = require('domino'); +var mockRequire = require('mock-require'); +var nativeTimeout = setTimeout; +require('./zone-mix'); +mockRequire('electron', { + desktopCapturer: {getSources: function(callback) { nativeTimeout(callback); }}, + shell: {openExternal: function(callback) { nativeTimeout(callback); }}, + ipcRenderer: {on: function(callback) { nativeTimeout(callback); }}, +}); +require('./zone-patch-electron'); +var electron = require('electron'); +var zone = Zone.current.fork({name: 'zone'}); +zone.run(function() { + electron.desktopCapturer.getSources(function() { + if (Zone.current.name !== 'zone') { + process.exit(1); + } + }); + electron.shell.openExternal(function() { + console.log('shell', Zone.current.name); + if (Zone.current.name !== 'zone') { + process.exit(1); + } + }); + electron.ipcRenderer.on(function() { + if (Zone.current.name !== 'zone') { + process.exit(1); + } + }); +});