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

fix(serializer): fixes #2003 ivy enabled #2016

Merged
merged 1 commit into from
Mar 21, 2023
Merged
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
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