thymikee / jest-preset-angular

Jest configuration preset for Angular projects.
https://thymikee.github.io/jest-preset-angular/
MIT License
883 stars 304 forks source link

jest refuses to accept "./login.component' import inside immediate directory #1697

Closed nhhockeyplayer closed 2 months ago

nhhockeyplayer commented 2 years ago

Version

27.5.1

Steps to reproduce

this occurs to all spec files in codebase that attempt to operate on their local files in their local directory

import { LoginComponent } from './login.component';

so fundamental and cant do it

have to operate the path in tsconfig taking the scenic route thru the tsconfig path and barrel file import {LoginComponent} from '@meanstacknh/shared-feature-auth' which may not even be valid I feel

Expected behavior

should be able to import right on the immediate operating working directory

this is widespread impact to large codebases and not fun consuming alot of time to re-work

Actual behavior

nx run shared-feature-auth:test

 FAIL   shared-feature-auth  libs/shared/feature/auth/src/lib/components/login/login.component.spec.ts
  ● Test suite failed to run

    ReferenceError: TextEncoder is not defined

    > 1 | import {
        | ^
      2 |     DocumentType,
      3 |     getModelForClass,
      4 |     modelOptions,

Additional context

immediate relative imports are safe imports preventing unnecessary parsing searching thru paths and barrel files and take precedence to avoid circular dependencies

and this error is forcing us to do the latter with unknown forecasted ramifications

please prioritize immediate relative imports

Environment

nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : darwin x64
   yarn : 1.22.18

   nx : 14.4.3
   @nrwl/angular : 14.4.3
   @nrwl/cypress : 14.4.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.4.3
   @nrwl/eslint-plugin-nx : 14.4.3
   @nrwl/express : 14.4.3
   @nrwl/jest : 14.4.3
   @nrwl/js : 14.4.3
   @nrwl/linter : 14.4.3
   @nrwl/nest : 14.4.3
   @nrwl/next : Not Found
   @nrwl/node : 14.4.3
   @nrwl/nx-cloud : 14.2.0
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : 8.12.11
   @nrwl/storybook : 14.4.3
   @nrwl/web : 14.4.3
   @nrwl/workspace : 14.4.3
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:
     @fortawesome/angular-fontawesome: 0.11.1
     @ionic/angular: 6.1.14
     @ngrx/component: 14.0.2
     @ngrx/component-store: 14.0.2
     @ngrx/effects: 14.0.2
     @ngrx/entity: 14.0.2
     @ngrx/router-store: 14.0.2
     @ngrx/store: 14.0.2
     @nxtend/capacitor: 13.0.0
     @nxtend/ionic-angular: 13.1.0
     @storybook/angular: 6.5.9
     angular-builder-custom-terser-options: 1.0.1
     @compodoc/compodoc: 1.1.19
     @ngrx/schematics: 14.0.2
     @ngrx/store-devtools: 14.0.2
     ngx-build-plus: 14.0.0
ahnpnl commented 2 years ago

Please provide your reproduce scenario with https://github.com/thymikee/jest-preset-angular/tree/main/examples

ahnpnl commented 2 years ago

Sure that also works for me

nhhockeyplayer commented 2 years ago

Sure that also works for me

Okay your all set just run the following after clone

https://github.com/nhhockeyplayer/meanstacknh


- yarn install
- nx build shared-feature-auth
- nx run shared-feature-auth:test

the general issue... imports are a general problem for TEST locally and outside the module. when none of this should be happening the main build runs and completes fine lso, I sense somewhere someone is inducing the usage of the package.json "type": "module" somewhere possibly within the mix and jarring other build tasks and configurations...

looking forward to your feedback

this repo is a good unit test

Thanks

ahnpnl commented 2 months ago

I will close this issue since original context is related to TextEncoder which has been fixed in https://github.com/thymikee/jest-preset-angular/pull/2535

Feel free to create a different issue if you see different stack trace