From 9defc00b144ec2e18199af40e3f2a4aaaa0fa4d5 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 21 Feb 2019 14:22:06 -0800 Subject: [PATCH] build(bazel): cleanup the jasmine bootstrap code (#28906) PR Close #28906 --- tools/testing/init_node_no_angular_spec.ts | 16 ---------------- tools/testing/init_node_spec.ts | 22 +++++++--------------- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/tools/testing/init_node_no_angular_spec.ts b/tools/testing/init_node_no_angular_spec.ts index f2df6682df..f8ef05cc1d 100644 --- a/tools/testing/init_node_no_angular_spec.ts +++ b/tools/testing/init_node_no_angular_spec.ts @@ -6,21 +6,5 @@ * found in the LICENSE file at https://angular.io/license */ -// This hack is needed to get jasmine, node and zone working inside bazel. -// 1) we load `jasmine-core` which contains the ENV: it, describe etc... -const jasmineCore: any = require('jasmine-core'); -// 2) We create an instance of `jasmine` ENV. -const patchedJasmine = jasmineCore.boot(jasmineCore); -// 3) Save the `jasmine` into global so that `zone.js/dist/jasmine-patch.js` can get a hold of it to -// patch it. -(global as any)['jasmine'] = patchedJasmine; -// 4) Change the `jasmine-core` to make sure that all subsequent jasmine's have the same ENV, -// otherwise the patch will not work. -// This is needed since Bazel creates a new instance of jasmine and it's ENV and we want to make -// sure it gets the same one. -jasmineCore.boot = function() { - return patchedJasmine; -}; - (global as any).isNode = true; (global as any).isBrowser = false; diff --git a/tools/testing/init_node_spec.ts b/tools/testing/init_node_spec.ts index 78a29fdcea..d9f256f830 100644 --- a/tools/testing/init_node_spec.ts +++ b/tools/testing/init_node_spec.ts @@ -15,22 +15,14 @@ import 'zone.js/dist/fake-async-test.js'; import 'zone.js/dist/task-tracking.js'; import 'reflect-metadata/Reflect'; -// This hack is needed to get jasmine, node and zone working inside bazel. -// 1) we load `jasmine-core` which contains the ENV: it, describe etc... +// We must first initialize jasmine-core before calling +// requiring `zone.js/dist/jasmine-patch.js` which patches +// jasmine ENV with code which understands ProxyZone. +// jasmine_node_test under Bazel will check if `jasmineCore.boot(jasmineCore)` +// has been called and re-use the env if it has. +// See https://github.com/bazelbuild/rules_nodejs/pull/539 const jasmineCore: any = require('jasmine-core'); -// 2) We create an instance of `jasmine` ENV. -const patchedJasmine = jasmineCore.boot(jasmineCore); -// 3) Save the `jasmine` into global so that `zone.js/dist/jasmine-patch.js` can get a hold of it to -// patch it. -(global as any)['jasmine'] = patchedJasmine; -// 4) Change the `jasmine-core` to make sure that all subsequent jasmine's have the same ENV, -// otherwise the patch will not work. -// This is needed since Bazel creates a new instance of jasmine and it's ENV and we want to make -// sure it gets the same one. -jasmineCore.boot = function() { - return patchedJasmine; -}; -// 5) Patch jasmine ENV with code which understands ProxyZone. +jasmineCore.boot(jasmineCore); import 'zone.js/dist/jasmine-patch.js'; (global as any).isNode = true;