Skip to content

[20.0.0-next.6] new library Karma tests fail under preserveSymlinks #30131

Closed
@alexeagle

Description

@alexeagle

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Follow-up to #30113 - setting preserveSymlinks=false makes the TestBed setup fail, and can only be fixed by manual fixes to the test code, something like:

import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

...

describe('MyLib', () => {
  beforeEach(async () => {
    TestBed.initTestEnvironment(
      BrowserDynamicTestingModule,
      platformBrowserDynamicTesting()
    );

Minimal Reproduction

% npx @angular/cli@20.0.0-next.6 new angular --create-application=false --skip-install
% cd angular
% npx @angular/cli@20.0.0-next.6 generate library my-lib --skip-install
% npx pnpm@8 install
# set the preserveSymlinks option
% jq '.projects["my-lib"].architect.test.options.preserveSymlinks = true' angular.json > tmp.json && mv tmp.json angular.json
% ./node_modules/.bin/ng test my-lib

Exception or Error

Chrome 135.0.0.0 (Mac OS 10.15.7) MyLib should create FAILED
	Error: Need to call TestBed.initTestEnvironment() first
	    at _TestBedImpl.get compiler [as compiler] (node_modules/@angular/core/fesm2022/testing.mjs:2081:19)
	    at _TestBedImpl.configureTestingModule (node_modules/@angular/core/fesm2022/testing.mjs:1993:14)
	    at _TestBedImpl.configureTestingModule (node_modules/@angular/core/fesm2022/testing.mjs:1812:37)
	    at Object.<anonymous> (projects/my-lib/src/lib/my-lib.spec.ts:10:19)
	    at Generator.next (<anonymous>)
	    at chunk-TTULUY32.js:48:61
	    at new ZoneAwarePromise (node_modules/zone.js/fesm2015/zone.js:2702:25)
	    at __async (chunk-TTULUY32.js:32:10)
	    at UserContext.<anonymous> (projects/my-lib/src/lib/my-lib.spec.ts:9:25)
	    at _ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:369:28)

Your Environment

MacOS

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions