From 3fd3c2ac4c12b052f3503ced07d8b34f3bb62c6a Mon Sep 17 00:00:00 2001 From: Vikram Subramanian Date: Fri, 25 May 2018 13:52:58 -0700 Subject: [PATCH] test(animations): fix Node.js detection in animation tests (#24139) PR Close #24139 --- packages/animations/browser/test/dsl/animation_spec.ts | 2 +- .../animations/browser/test/dsl/animation_trigger_spec.ts | 2 +- .../test/render/css_keyframes/css_keyframes_driver_spec.ts | 4 +--- .../test/render/css_keyframes/direct_style_player_spec.ts | 2 +- .../css_keyframes/element_animation_style_handler_spec.ts | 4 +--- .../browser/test/render/timeline_animation_engine_spec.ts | 2 +- .../browser/test/render/transition_animation_engine_spec.ts | 2 +- .../test/render/web_animations/web_animations_driver_spec.ts | 2 +- packages/core/test/animation/animation_integration_spec.ts | 2 +- .../core/test/animation/animation_query_integration_spec.ts | 2 +- .../core/test/animation/animation_router_integration_spec.ts | 2 +- ...imations_with_css_keyframes_animations_integration_spec.ts | 2 +- .../animations_with_web_animations_integration_spec.ts | 2 +- .../test/animation/animation_renderer_spec.ts | 2 +- 14 files changed, 14 insertions(+), 18 deletions(-) diff --git a/packages/animations/browser/test/dsl/animation_spec.ts b/packages/animations/browser/test/dsl/animation_spec.ts index 2104968b8f..21071dec8f 100644 --- a/packages/animations/browser/test/dsl/animation_spec.ts +++ b/packages/animations/browser/test/dsl/animation_spec.ts @@ -20,7 +20,7 @@ function createDiv() { { describe('Animation', () => { // these tests are only mean't to be run within the DOM (for now) - if (typeof Element == 'undefined') return; + if (isNode) return; let rootElement: any; let subElement1: any; diff --git a/packages/animations/browser/test/dsl/animation_trigger_spec.ts b/packages/animations/browser/test/dsl/animation_trigger_spec.ts index a702a1ddb9..5482075fc6 100644 --- a/packages/animations/browser/test/dsl/animation_trigger_spec.ts +++ b/packages/animations/browser/test/dsl/animation_trigger_spec.ts @@ -17,7 +17,7 @@ import {makeTrigger} from '../shared'; { describe('AnimationTrigger', () => { // these tests are only mean't to be run within the DOM (for now) - if (typeof Element == 'undefined') return; + if (isNode) return; let element: any; beforeEach(() => { diff --git a/packages/animations/browser/test/render/css_keyframes/css_keyframes_driver_spec.ts b/packages/animations/browser/test/render/css_keyframes/css_keyframes_driver_spec.ts index 00adf6e8ee..747a389575 100644 --- a/packages/animations/browser/test/render/css_keyframes/css_keyframes_driver_spec.ts +++ b/packages/animations/browser/test/render/css_keyframes/css_keyframes_driver_spec.ts @@ -16,9 +16,7 @@ import {assertElementExistsInDom, createElement, findKeyframeDefinition, forceRe const CSS_KEYFRAME_RULE_TYPE = 7; describe('CssKeyframesDriver tests', () => { - if (typeof Element == 'undefined' || typeof document == 'undefined' || - typeof(window as any)['AnimationEvent'] == 'undefined') - return; + if (isNode || typeof(window as any)['AnimationEvent'] == 'undefined') return; describe('building keyframes', () => { it('should build CSS keyframe style object containing the keyframe styles', () => { diff --git a/packages/animations/browser/test/render/css_keyframes/direct_style_player_spec.ts b/packages/animations/browser/test/render/css_keyframes/direct_style_player_spec.ts index f11ad293d0..c04ae07783 100644 --- a/packages/animations/browser/test/render/css_keyframes/direct_style_player_spec.ts +++ b/packages/animations/browser/test/render/css_keyframes/direct_style_player_spec.ts @@ -14,7 +14,7 @@ import {assertStyle, createElement} from './shared'; const CSS_KEYFRAME_RULE_TYPE = 7; describe('DirectStylePlayer tests', () => { - if (typeof Element == 'undefined' || typeof document == 'undefined') return; + if (isNode) return; it('should apply the styling to the given element when the animation starts and remove when destroyed', () => { diff --git a/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts b/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts index 76d5a6e5d4..d5b64b5758 100644 --- a/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts +++ b/packages/animations/browser/test/render/css_keyframes/element_animation_style_handler_spec.ts @@ -13,9 +13,7 @@ import {assertStyle, createElement, makeAnimationEvent, supportsAnimationEventCr const EMPTY_FN = () => {}; { describe('ElementAnimationStyleHandler', () => { - if (typeof Element == 'undefined' || typeof document == 'undefined' || - typeof(window as any)['AnimationEvent'] == 'undefined') - return; + if (isNode || typeof(window as any)['AnimationEvent'] == 'undefined') return; it('should add and remove an animation on to an element\'s styling', () => { const element = createElement(); diff --git a/packages/animations/browser/test/render/timeline_animation_engine_spec.ts b/packages/animations/browser/test/render/timeline_animation_engine_spec.ts index 5842fae27f..a7c188133c 100644 --- a/packages/animations/browser/test/render/timeline_animation_engine_spec.ts +++ b/packages/animations/browser/test/render/timeline_animation_engine_spec.ts @@ -21,7 +21,7 @@ import {MockAnimationDriver, MockAnimationPlayer} from '../../testing/src/mock_a } // these tests are only mean't to be run within the DOM - if (typeof Element == 'undefined') return; + if (isNode) return; describe('TimelineAnimationEngine', () => { let element: any; diff --git a/packages/animations/browser/test/render/transition_animation_engine_spec.ts b/packages/animations/browser/test/render/transition_animation_engine_spec.ts index 5a122e9bd5..a76398d2e2 100644 --- a/packages/animations/browser/test/render/transition_animation_engine_spec.ts +++ b/packages/animations/browser/test/render/transition_animation_engine_spec.ts @@ -20,7 +20,7 @@ const DEFAULT_NAMESPACE_ID = 'id'; const driver = new MockAnimationDriver(); // these tests are only mean't to be run within the DOM - if (typeof Element == 'undefined') return; + if (isNode) return; describe('TransitionAnimationEngine', () => { let element: any; diff --git a/packages/animations/browser/test/render/web_animations/web_animations_driver_spec.ts b/packages/animations/browser/test/render/web_animations/web_animations_driver_spec.ts index 49bb118f13..f66043f58b 100644 --- a/packages/animations/browser/test/render/web_animations/web_animations_driver_spec.ts +++ b/packages/animations/browser/test/render/web_animations/web_animations_driver_spec.ts @@ -12,7 +12,7 @@ import {WebAnimationsPlayer} from '../../../src/render/web_animations/web_animat { describe('WebAnimationsDriver', () => { - if (typeof Element == 'undefined' || typeof document == 'undefined') return; + if (isNode) return; describe('when web-animations are not supported natively', () => { it('should return an instance of a CssKeyframePlayer if scrubbing is not requested', () => { diff --git a/packages/core/test/animation/animation_integration_spec.ts b/packages/core/test/animation/animation_integration_spec.ts index 4980722a36..a1dcb50b60 100644 --- a/packages/core/test/animation/animation_integration_spec.ts +++ b/packages/core/test/animation/animation_integration_spec.ts @@ -20,7 +20,7 @@ const DEFAULT_COMPONENT_ID = '1'; (function() { // these tests are only mean't to be run within the DOM (for now) - if (typeof Element == 'undefined') return; + if (isNode) return; describe('animation tests', function() { function getLog(): MockAnimationPlayer[] { diff --git a/packages/core/test/animation/animation_query_integration_spec.ts b/packages/core/test/animation/animation_query_integration_spec.ts index 3f14f78b7a..14278b3f81 100644 --- a/packages/core/test/animation/animation_query_integration_spec.ts +++ b/packages/core/test/animation/animation_query_integration_spec.ts @@ -21,7 +21,7 @@ import {fakeAsync, flushMicrotasks} from '../../testing/src/fake_async'; (function() { // these tests are only mean't to be run within the DOM (for now) - if (typeof Element == 'undefined') return; + if (isNode) return; describe('animation query tests', function() { function getLog(): MockAnimationPlayer[] { diff --git a/packages/core/test/animation/animation_router_integration_spec.ts b/packages/core/test/animation/animation_router_integration_spec.ts index 012adb3a55..3225a8727f 100644 --- a/packages/core/test/animation/animation_router_integration_spec.ts +++ b/packages/core/test/animation/animation_router_integration_spec.ts @@ -16,7 +16,7 @@ import {RouterTestingModule} from '@angular/router/testing'; (function() { // these tests are only mean't to be run within the DOM (for now) - if (typeof Element == 'undefined') return; + if (isNode) return; describe('Animation Router Tests', function() { function getLog(): MockAnimationPlayer[] { diff --git a/packages/core/test/animation/animations_with_css_keyframes_animations_integration_spec.ts b/packages/core/test/animation/animations_with_css_keyframes_animations_integration_spec.ts index 4b9201d811..22c1c498c5 100644 --- a/packages/core/test/animation/animations_with_css_keyframes_animations_integration_spec.ts +++ b/packages/core/test/animation/animations_with_css_keyframes_animations_integration_spec.ts @@ -17,7 +17,7 @@ import {TestBed} from '../../testing'; (function() { // these tests are only mean't to be run within the DOM (for now) // Buggy in Chromium 39, see https://github.com/angular/angular/issues/15793 - if (typeof Element == 'undefined') return; + if (isNode) return; describe('animation integration tests using css keyframe animations', function() { diff --git a/packages/core/test/animation/animations_with_web_animations_integration_spec.ts b/packages/core/test/animation/animations_with_web_animations_integration_spec.ts index c5b00adce8..6067815255 100644 --- a/packages/core/test/animation/animations_with_web_animations_integration_spec.ts +++ b/packages/core/test/animation/animations_with_web_animations_integration_spec.ts @@ -18,7 +18,7 @@ import {TestBed} from '../../testing'; (function() { // these tests are only mean't to be run within the DOM (for now) // Buggy in Chromium 39, see https://github.com/angular/angular/issues/15793 - if (typeof Element == 'undefined' || !ɵsupportsWebAnimations()) return; + if (isNode || !ɵsupportsWebAnimations()) return; describe('animation integration tests using web animations', function() { diff --git a/packages/platform-browser/test/animation/animation_renderer_spec.ts b/packages/platform-browser/test/animation/animation_renderer_spec.ts index 05a0c0d8e9..8373cb1e93 100644 --- a/packages/platform-browser/test/animation/animation_renderer_spec.ts +++ b/packages/platform-browser/test/animation/animation_renderer_spec.ts @@ -117,7 +117,7 @@ import {el} from '../../testing/src/browser_util'; describe('flushing animations', () => { // these tests are only mean't to be run within the DOM - if (typeof Element == 'undefined') return; + if (isNode) return; it('should flush and fire callbacks when the zone becomes stable', (async) => { @Component({