From 44d3922632b4f513d43d5b92a176554ecafb1de1 Mon Sep 17 00:00:00 2001 From: rubiesonthesky <2591240+rubiesonthesky@users.noreply.github.com> Date: Tue, 21 Mar 2023 16:54:43 +0200 Subject: [PATCH] =?UTF-8?q?fix(serializer):=20replace=20`=C9=B5ivyEnabled`?= =?UTF-8?q?=20with=20workaround=20to=20detect=20Ivy=20mode=20=20(#2016)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #2003 --- src/serializers/ng-snapshot.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/serializers/ng-snapshot.ts b/src/serializers/ng-snapshot.ts index d6066a6fdc..93875f2a02 100644 --- a/src/serializers/ng-snapshot.ts +++ b/src/serializers/ng-snapshot.ts @@ -1,4 +1,4 @@ -import type { ComponentRef, DebugNode, Type, ɵCssSelectorList } from '@angular/core'; +import type { ComponentRef, DebugNode, Type, ɵCssSelectorList, ɵNgModuleType } from '@angular/core'; import type { ComponentFixture } from '@angular/core/testing'; import type { Colors } from 'pretty-format'; @@ -40,12 +40,14 @@ type Printer = (elementToSerialize: unknown) => string; const attributesToRemovePatterns = ['__ngContext__']; const ivyEnabled = (): boolean => { - // Should be required lazily, since it will throw an exception - // `Cannot resolve parameters...`. - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires - const { ɵivyEnabled } = require('@angular/core'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { NgModule }: typeof import('@angular/core') = require('@angular/core'); - return ɵivyEnabled; + class IvyModule {} + NgModule()(IvyModule); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return !!(IvyModule as ɵNgModuleType).ɵmod; }; const print = (fixture: unknown, print: Printer, indent: Indent, opts: PluginOptions, colors: Colors): string => {