In my project, we have classes for most of the elements that need to be targeted by the E2E tests:
<div class="just-an-item" [e2e] [e2e-class]="button-to-trigger-something">...</div>
Which gets compiled into
<div class="just-an-item e2e-button-to-trigger-something">...</div>
Thanks to this directive
@Directive({
selector: '[e2e]'
})
export class E2eClassDirective implements OnInit {
@HostBinding('class')
public classes: string;
@Input('e2e-class')
public readonly className: string;
constructor (
private host: ElementRef,
private renderer: Renderer2
) {
}
public ngOnInit (): void {
this.renderer.addClass(
this.host.nativeElement,'e2e-' + this.className // <-------
);
}
}
And of course I have a module
@NgModule({
...
declarations: [ ... ... E2eClassDirective ],
...
})
export class MainModule {}
I would like to disable this on compilation time, not on execution time.
In other words, I do not want this:
public ngOnInit (): void {
if( !environment.production ) {
this.renderer.addClass(
this.host.nativeElement,'e2e-' + this.className // <-------
);
}
}
Because this still means the text will be in the compiled version, and the logic will be executed. Instead, I would like to be able to "disable" it if we are building the app in production mode, so that it doesn't make it to the /dist
.
Is that possible?