Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ivy): add onlyInIvy perf counter expectations #30339

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/test/acceptance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ts_library(
"//packages/compiler",
"//packages/compiler/testing",
"//packages/core",
"//packages/core/src/util",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
Expand Down
12 changes: 12 additions & 0 deletions packages/core/test/acceptance/styling_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Component, Directive, ElementRef} from '@angular/core';
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
import {TestBed} from '@angular/core/testing';
import {DomSanitizer, SafeStyle} from '@angular/platform-browser';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {onlyInIvy} from '@angular/private/testing';

describe('styling', () => {
beforeEach(ngDevModeResetPerfCounters);

it('should render inline style and class attribute values on the element before a directive is instantiated',
() => {
@Component({
Expand Down Expand Up @@ -147,5 +151,13 @@ describe('styling', () => {

const div = fixture.nativeElement.querySelector('div') as HTMLDivElement;
expect(div.style.backgroundImage).toBe('url("#test")');

onlyInIvy('perf counters').expectPerfCounters({
stylingApply: 2,
stylingApplyCacheMiss: 1,
stylingProp: 2,
stylingPropCacheMiss: 1,
tNode: 3,
});
});
});
34 changes: 30 additions & 4 deletions packages/private/testing/src/ivy_test_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,49 @@ export interface JasmineMethods {
fit: typeof fit;
describe: typeof describe;
fdescribe: typeof fdescribe;

/**
* Runs jasmine expectations against the provided keys for `ngDevMode`.
*
* Will not perform expectations for keys that are not provided.
*
* ```ts
* // Expect that `ngDevMode.styleMap` is `1`, and `ngDevMode.tNode` is `3`, but we don't care
* // about the other values.
* onlyInIvy('perf counters').expectPerfCounters({
* stylingMap: 1,
* tNode: 3,
* })
* ```
*/
expectPerfCounters: (expectedCounters: Partial<NgDevModePerfCounters>) => void;
isEnabled: boolean;
}

const PASSTHROUGH: JasmineMethods = {
it: it,
fit: fit,
describe: describe,
fdescribe: fdescribe,
it,
fit,
describe,
fdescribe,
expectPerfCounters,
isEnabled: true,
};

function noop() {}

function expectPerfCounters(expectedCounters: Partial<NgDevModePerfCounters>) {
Object.keys(expectedCounters).forEach(key => {
const expected = (expectedCounters as any)[key];
const actual = (ngDevMode as any)[key];
expect(actual).toBe(expected, `ngDevMode.${key}`);
});
}

const IGNORE: JasmineMethods = {
it: noop,
fit: noop,
describe: noop,
fdescribe: noop,
expectPerfCounters: noop,
isEnabled: false,
};