sand4rt / playwright-ct-angular

Playwright Angular component testing.
https://www.npmjs.com/package/@sand4rt/experimental-ct-angular
MIT License
48 stars 4 forks source link

Testbed fails to compile #51

Closed chronospatian closed 4 months ago

chronospatian commented 4 months ago

Version: 1.41.2

Tests that use beforeMount to configure TestBed fail to run.

npm run test-ct

> web-component-harness@0.0.0 test-ct
> playwright test -c playwright-ct.config.ts

JIT compilation failed for injectable [class PlatformLocation]
Error: The injectable 'PlatformLocation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.

The injectable is part of a library that has been partially compiled.
However, the Angular Linker has not processed the library such that JIT compilation is used as fallback.

Ideally, the library is processed using the Angular Linker to become fully AOT compiled.
Alternatively, the JIT compiler should be loaded by bootstrapping using '@angular/platform-browser-dynamic' or '@angular/platform-server',
or manually provide the compiler with 'import "@angular/compiler";' before bootstrapping.

    at getCompilerFacade (<omitted>/packages/core/src/compiler/compiler_facade.ts:52:11)
    at Module.ɵɵngDeclareFactory (<omitted>/packages/core/src/render3/jit/partial.ts:58:20)
    at Function.<static_initializer> (<omitted>/node_modules/@angular/common/fesm2022/common.mjs:64:29)
    at <omitted>/packages/common/src/dom_tokens.ts:18:25

Minimal reproduction

import {test} from "@sand4rt/experimental-ct-angular";
import {beforeMount} from "@sand4rt/experimental-ct-angular/hooks";
import {NoopAnimationsModule} from "@angular/platform-browser/animations";

test.describe('harness', () => {
  beforeMount(async ({ TestBed }) => {
    TestBed.configureTestingModule({
      imports: [NoopAnimationsModule]
    })
  })
})
chronospatian commented 4 months ago

Adding @analogjs/vite-plugin-angular to playwright config fixed this for me. Copied from https://github.com/sand4rt/playwright/blob/hello-angular-ct/tests/components/ct-angular/playwright.config.mts