Skip to content

Commit

Permalink
fix(serializer): replace ɵivyEnabled with workaround to detect Ivy …
Browse files Browse the repository at this point in the history
…mode (#2016)

fixes #2003
  • Loading branch information
rubiesonthesky authored Mar 21, 2023
1 parent dd1854b commit 44d3922
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/serializers/ng-snapshot.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<unknown>).ɵmod;
};

const print = (fixture: unknown, print: Printer, indent: Indent, opts: PluginOptions, colors: Colors): string => {
Expand Down

0 comments on commit 44d3922

Please sign in to comment.