angular-builders icon indicating copy to clipboard operation
angular-builders copied to clipboard

Performance regression on jest tests after upgrading to Angular 19

Open Abreuvoir opened this issue 11 months ago • 2 comments

Describe the Bug

Since we upgraded to Angular 19, with @angular-builders/jest 19 too, we have a huge performance regression. Locally and in our CI of our project, tests went from around 2 minutes of execution time to 15 minutes.

Minimal Reproduction

Example of a test that now takes between 8-10s to execute:

import { createComponentFactory, Spectator } from '@ngneat/spectator/jest';

import { BreadcrumbItemComponent } from './breadcrumb-item.component';

describe(BreadcrumbItemComponent.name, () => {
  let spectator: Spectator<BreadcrumbItemComponent>;

  const createComponent = createComponentFactory({
    component: BreadcrumbItemComponent,
    declareComponent: false
  });

  beforeEach(() => {
    spectator = createComponent();

    spectator.detectChanges();
  });

  it('should create', () => {
    expect(spectator.component).toBeTruthy();
  });
});
import {
  ChangeDetectionStrategy,
  Component,
  ViewEncapsulation
} from '@angular/core';

@Component({
  selector: 'breadcrumb-item',
  template: `<ng-content />`,
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None
})
export class BreadcrumbItemComponent {}

But the issue is noticeable on a scale, however i am not sure what to give more here without having to share company code.

Expected Behavior

Same performance as before

Screenshots

image

Environment


Libs
- @angular/core version: 19.0.5
- @angular-devkit/build-angular version: 19.0.6
- @angular-builders/jest version: 19.0.0

For Tooling issues:
- Node version: 22.11.0
- Platform:  Windows, and Jenkins on Openshift
Others:
We are using @ngneat/[email protected] 

Abreuvoir avatar Jan 15 '25 16:01 Abreuvoir

Found a solution that restores the performance from previous versions; just add the option isolatedModules: true to the CommonJS preset in jest.config.ts (also available for ESM) - here's the minimal file (see also this chapter in jest-preset-angular docs):

import type { Config } from 'jest';
import presets from 'jest-preset-angular/presets';

export default {
  ...presets.createCjsPreset({ isolatedModules: true }),
} satisfies Config;

My source was to check and compare the Angular 19 example presets.

akornet avatar Jan 31 '25 19:01 akornet

@akornet Thank you. Our execution time went back to around 1 min with this.

Should this configuration be made available more cleanly through the builder ?

Abreuvoir avatar Feb 05 '25 15:02 Abreuvoir