nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.38k stars 2.33k forks source link

Jest test start failing when we add new library to angular-standalone app #22342

Closed tejaskatariya closed 5 months ago

tejaskatariya commented 6 months ago

Current Behavior

When we create a new nx angular-stanalone app and run command nx run test, everything works as expected. As soon as we add a new library, command start failing with below error

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

SyntaxError: /Users/tejaskatariya/Learning/angular/smarsh-cyber-webui/libs/shared/ui/src/lib/ui/ui.component.spec.ts: Missing semicolon. (5:15)

  3 |
  4 | describe('UiComponent', () => {
> 5 |   let component: UiComponent;
    |                ^
  6 |   let fixture: ComponentFixture<UiComponent>;
  7 |
  8 |   beforeEach(async () => {

  at constructor (node_modules/@babel/parser/src/parse-error.ts:74:19)
  at Parser.toParseError [as raise] (node_modules/@babel/parser/src/tokenizer/index.ts:1487:19)
  at Parser.raise [as semicolon] (node_modules/@babel/parser/src/parser/util.ts:141:10)
  at Parser.semicolon [as parseVarStatement] (node_modules/@babel/parser/src/parser/statement.ts:1194:10)
  at Parser.parseVarStatement [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:546:21)
  at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:417:17)
  at Parser.parseStatementLike [as parseStatementListItem] (node_modules/@babel/parser/src/parser/statement.ts:366:17)
  at Parser.parseStatementListItem [as parseBlockOrModuleBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1386:16)
  at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1359:10)
  at Parser.parseBlockBody [as parseBlock] (node_modules/@babel/parser/src/parser/statement.ts:1327:10)
  at Parser.parseBlock [as parseFunctionBody] (node_modules/@babel/parser/src/parser/expression.ts:2572:24)
  at Parser.parseFunctionBody [as parseArrowExpression] (node_modules/@babel/parser/src/parser/expression.ts:2515:10)
  at Parser.parseArrowExpression [as parseParenAndDistinguishExpression] (node_modules/@babel/parser/src/parser/expression.ts:1818:12)
  at Parser.parseParenAndDistinguishExpression [as parseExprAtom] (node_modules/@babel/parser/src/parser/expression.ts:1159:21)
  at Parser.parseExprAtom [as parseExprSubscripts] (node_modules/@babel/parser/src/parser/expression.ts:703:23)
  at Parser.parseExprSubscripts [as parseUpdate] (node_modules/@babel/parser/src/parser/expression.ts:680:21)
  at Parser.parseUpdate [as parseMaybeUnary] (node_modules/@babel/parser/src/parser/expression.ts:642:23)
  at Parser.parseMaybeUnary [as parseMaybeUnaryOrPrivate] (node_modules/@babel/parser/src/parser/expression.ts:385:14)
  at Parser.parseMaybeUnaryOrPrivate [as parseExprOps] (node_modules/@babel/parser/src/parser/expression.ts:397:23)
  at Parser.parseExprOps [as parseMaybeConditional] (node_modules/@babel/parser/src/parser/expression.ts:352:23)
  at Parser.parseMaybeConditional [as parseMaybeAssign] (node_modules/@babel/parser/src/parser/expression.ts:292:21)
  at parseMaybeAssign (node_modules/@babel/parser/src/parser/expression.ts:246:12)
  at Parser.callback [as allowInAnd] (node_modules/@babel/parser/src/parser/expression.ts:3112:12)
  at Parser.allowInAnd [as parseMaybeAssignAllowIn] (node_modules/@babel/parser/src/parser/expression.ts:245:17)
  at Parser.parseMaybeAssignAllowIn [as parseExprListItem] (node_modules/@babel/parser/src/parser/expression.ts:2735:18)
  at Parser.parseExprListItem [as parseCallExpressionArguments] (node_modules/@babel/parser/src/parser/expression.ts:1035:14)
  at Parser.parseCallExpressionArguments [as parseCoverCallAndAsyncArrowHead] (node_modules/@babel/parser/src/parser/expression.ts:877:29)
  at Parser.parseCoverCallAndAsyncArrowHead [as parseSubscript] (node_modules/@babel/parser/src/parser/expression.ts:766:19)
  at Parser.parseSubscript [as parseSubscripts] (node_modules/@babel/parser/src/parser/expression.ts:724:19)
  at Parser.parseSubscripts [as parseExprSubscripts] (node_modules/@babel/parser/src/parser/expression.ts:709:17)
  at Parser.parseExprSubscripts [as parseUpdate] (node_modules/@babel/parser/src/parser/expression.ts:680:21)
  at Parser.parseUpdate [as parseMaybeUnary] (node_modules/@babel/parser/src/parser/expression.ts:642:23)
  at Parser.parseMaybeUnary [as parseMaybeUnaryOrPrivate] (node_modules/@babel/parser/src/parser/expression.ts:385:14)
  at Parser.parseMaybeUnaryOrPrivate [as parseExprOps] (node_modules/@babel/parser/src/parser/expression.ts:397:23)
  at Parser.parseExprOps [as parseMaybeConditional] (node_modules/@babel/parser/src/parser/expression.ts:352:23)
  at Parser.parseMaybeConditional [as parseMaybeAssign] (node_modules/@babel/parser/src/parser/expression.ts:292:21)
  at Parser.parseMaybeAssign [as parseExpressionBase] (node_modules/@babel/parser/src/parser/expression.ts:215:23)
  at parseExpressionBase (node_modules/@babel/parser/src/parser/expression.ts:206:39)
  at Parser.callback [as allowInAnd] (node_modules/@babel/parser/src/parser/expression.ts:3107:16)
  at Parser.allowInAnd [as parseExpression] (node_modules/@babel/parser/src/parser/expression.ts:206:17)
  at Parser.parseExpression [as parseStatementContent] (node_modules/@babel/parser/src/parser/statement.ts:636:23)
  at Parser.parseStatementContent [as parseStatementLike] (node_modules/@babel/parser/src/parser/statement.ts:417:17)
  at Parser.parseStatementLike [as parseModuleItem] (node_modules/@babel/parser/src/parser/statement.ts:354:17)
  at Parser.parseModuleItem [as parseBlockOrModuleBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1385:16)
  at Parser.parseBlockOrModuleBlockBody [as parseBlockBody] (node_modules/@babel/parser/src/parser/statement.ts:1359:10)
  at Parser.parseBlockBody [as parseProgram] (node_modules/@babel/parser/src/parser/statement.ts:213:10)
  at Parser.parseProgram [as parseTopLevel] (node_modules/@babel/parser/src/parser/statement.ts:195:25)
  at Parser.parseTopLevel [as parse] (node_modules/@babel/parser/src/parser/index.ts:45:10)
  at parse (node_modules/@babel/parser/src/index.ts:66:38)
  at parser (node_modules/@babel/core/src/parser/index.ts:28:19)
      at parser.next (<anonymous>)
  at normalizeFile (node_modules/@babel/core/src/transformation/normalize-file.ts:50:24)
      at normalizeFile.next (<anonymous>)
  at run (node_modules/@babel/core/src/transformation/index.ts:39:36)
      at run.next (<anonymous>)
  at transform (node_modules/@babel/core/src/transform.ts:29:20)
      at transform.next (<anonymous>)
  at evaluateSync (node_modules/gensync/index.js:251:28)
  at sync (node_modules/gensync/index.js:89:14)
  at fn (node_modules/@babel/core/src/errors/rewrite-stack-trace.ts:99:14)
  at transformSync (node_modules/@babel/core/src/transform.ts:66:52)
  at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:726:19)

Expected Behavior

test should pass with having to add any extra configuration

GitHub Repo

No response

Steps to Reproduce

  1. Create a standalone angular app
  2. run command npm run test and check everything is working
  3. Now add new angular library at dir 'libs/shared/ui' and see the same command start failing
  4. tested with node version 18 and 21

Nx Report

Node   : 21.7.1
OS     : darwin-arm64
npm    : 10.5.0

nx                 : 18.0.8
@nx/js             : 18.0.8
@nx/jest           : 18.0.8
@nx/linter         : 18.0.8
@nx/eslint         : 18.0.8
@nx/workspace      : 18.0.8
@nx/angular        : 18.0.8
@nx/cypress        : 18.0.8
@nx/devkit         : 18.0.8
@nx/eslint-plugin  : 18.0.8
@nrwl/tao          : 18.0.8
@nx/web            : 18.0.8
@nx/webpack        : 18.0.8
typescript         : 5.3.3
---------------------------------------
Community plugins:
ng-zorro-antd : 17.3.0

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

Coly010 commented 6 months ago

I cna't reproduce this on latest Nx. Can you check if you still encounter this issue, and if so can you provide a reproduction repository that I can clone and see this happening in? https://www.loom.com/share/41a80f5ee776490099082af41ab22174?sid=f6381793-f186-4097-a6ec-b01969902be6

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] commented 4 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.