nrwl / nx

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

ng g jest (6.4.0-beta.1) #776

Closed arturhun closed 6 years ago

arturhun commented 6 years ago

Below follows a transcript of a session against the new 6.4.0-beta.1 according to instructions provided in #764.

Not sure what went wrong. Not sure where I should have run ng generate jest-project (as per https://blog.nrwl.io/nrwl-nx-6-3-faster-testing-with-jest-20a8ddb5064).

Most probably, before the thing gets stable, we would need a 100% working transcript provided somewhere in the readme.

Owners-MacBook-Pro:Code owner$ yarn global list
yarn global v1.9.4
info "@angular/cli@6.2.3" has binaries:
   - ng
info "@nrwl/schematics@6.4.0-beta.1" has binaries:
   - create-nx-workspace
   - nx
info "jest@23.6.0" has binaries:
   - jest
✨  Done in 0.51s.
Owners-MacBook-Pro:Code owner$ create-nx-workspace myorg
Creating a sandbox with the CLI and Nx Schematics...
[fsevents] Success: "/private/var/folders/ys/6x5zv2ps6472fd9c0pt8mfmh0000gn/T/tmp-706663QjWadrTWkwq/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
added 424 packages from 260 contributors and audited 15229 packages in 6.394s
found 0 vulnerabilities

ng new "myorg" --collection=@nrwl/schematics 
CREATE myorg/.prettierrc (25 bytes)
CREATE myorg/README.md (1857 bytes)
CREATE myorg/.editorconfig (245 bytes)
CREATE myorg/.gitignore (503 bytes)
CREATE myorg/angular.json (283 bytes)
CREATE myorg/karma.conf.js (1013 bytes)
CREATE myorg/nx.json (196 bytes)
CREATE myorg/package.json (2477 bytes)
CREATE myorg/tsconfig.json (423 bytes)
CREATE myorg/tslint.json (2307 bytes)
CREATE myorg/apps/.gitkeep (1 bytes)
CREATE myorg/libs/.gitkeep (0 bytes)
CREATE myorg/tools/tsconfig.tools.json (254 bytes)
CREATE myorg/tools/schematics/.gitkeep (0 bytes)
warning karma > log4js > nodemailer@2.7.2: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
warning karma > log4js > loggly > request > node-uuid@1.4.8: Use uuid module instead
warning karma > log4js > nodemailer > socks@1.1.9: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
warning karma > log4js > nodemailer > mailcomposer@4.0.1: This project is unmaintained
warning karma > socket.io > engine.io > uws@9.14.0: stop using this version
warning karma > log4js > loggly > request > hawk > hoek@2.16.3: The major version is no longer supported. Please update to 4.x or newer
    Successfully initialized git.
Owners-MacBook-Pro:Code owner$ cd myorg
Owners-MacBook-Pro:myorg owner$ ng g jest
CREATE jest.config.js (312 bytes)
UPDATE package.json (2604 bytes)
[######################################################################################################################################################-----------------------------------------------------------------------------------------------------] 1510/2525
Owners-MacBook-Pro:myorg owner$ ng g app jest-app --unit-test-runner jest
CREATE apps/jest-app-e2e/protractor.conf.js (752 bytes)
CREATE apps/jest-app-e2e/tsconfig.e2e.json (239 bytes)
CREATE apps/jest-app-e2e/src/app.e2e-spec.ts (304 bytes)
CREATE apps/jest-app-e2e/src/app.po.ts (210 bytes)
CREATE apps/jest-app/browserslist (375 bytes)
CREATE apps/jest-app/tsconfig.app.json (225 bytes)
CREATE apps/jest-app/tslint.json (251 bytes)
CREATE apps/jest-app/src/favicon.ico (5430 bytes)
CREATE apps/jest-app/src/index.html (298 bytes)
CREATE apps/jest-app/src/main.ts (370 bytes)
CREATE apps/jest-app/src/polyfills.ts (3194 bytes)
CREATE apps/jest-app/src/styles.css (80 bytes)
CREATE apps/jest-app/src/assets/.gitkeep (0 bytes)
CREATE apps/jest-app/src/environments/environment.prod.ts (51 bytes)
CREATE apps/jest-app/src/environments/environment.ts (631 bytes)
CREATE apps/jest-app/src/app/app.module.ts (375 bytes)
CREATE apps/jest-app/src/app/app.component.css (0 bytes)
CREATE apps/jest-app/src/app/app.component.html (570 bytes)
CREATE apps/jest-app/src/app/app.component.spec.ts (1001 bytes)
CREATE apps/jest-app/src/app/app.component.ts (214 bytes)
CREATE apps/jest-app/jest.config.js (129 bytes)
CREATE apps/jest-app/tsconfig.spec.json (252 bytes)
CREATE apps/jest-app/src/test-setup.ts (30 bytes)
UPDATE angular.json (3717 bytes)
UPDATE package.json (2604 bytes)
UPDATE nx.json (286 bytes)
yarn run v1.9.4
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ ./node_modules/.bin/nx format:write --untracked --silent
apps/jest-app-e2e/src/app.e2e-spec.ts 283ms
apps/jest-app-e2e/src/app.po.ts 8ms
apps/jest-app/src/app/app.component.css 63ms
apps/jest-app/src/app/app.component.spec.ts 17ms
apps/jest-app/src/app/app.component.ts 7ms
apps/jest-app/src/app/app.module.ts 8ms
apps/jest-app/src/environments/environment.prod.ts 5ms
apps/jest-app/src/environments/environment.ts 8ms
apps/jest-app/src/main.ts 8ms
apps/jest-app/src/polyfills.ts 13ms
apps/jest-app/src/styles.css 11ms
apps/jest-app/src/test-setup.ts 4ms
✨  Done in 1.51s.
Owners-MacBook-Pro:myorg owner$ ng test jest-app
ts-jest[backports] (WARN) "[jest-config].globals.__TRANSFORM_HTML__" is deprecated, use "[jest-config].globals.ts-jest.stringifyContentPathRegex" instead.
ts-jest[backports] (WARN) "[jest-config].globals.ts-jest.tsConfigFile" is deprecated, use "[jest-config].globals.ts-jest.tsConfig" instead.
ts-jest[backports] (WARN) Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.
 FAIL  apps/jest-app/src/app/app.component.spec.ts
  ● Test suite failed to run

    File not found: tsconfig.spec.json (resolved as: /Users/owner/Code/myorg/tsconfig.spec.json)

      at ConfigSet.resolvePath (../../node_modules/ts-jest/dist/config/config-set.js:557:19)
      at ConfigSet.get (../../node_modules/ts-jest/dist/config/config-set.js:176:67)
      at ConfigSet.tsJest (../../node_modules/ts-jest/dist/util/memoize.js:43:24)
      at ConfigSet.get (../../node_modules/ts-jest/dist/config/config-set.js:418:50)
      at ConfigSet.shouldStringifyContent (../../node_modules/ts-jest/dist/util/memoize.js:43:24)
      at TsJestTransformer.process (../../node_modules/ts-jest/dist/ts-jest-transformer.js:85:33)
      at tsProcess (../../node_modules/ts-jest/dist/index.js:46:48)
      at Object.module.exports.process (../../node_modules/jest-preset-angular/preprocessor.js:13:10)

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.29s
Ran all test suites.
Owners-MacBook-Pro:myorg owner$ ng g jest-project jest-app
jest-app already has a test architect option.
Owners-MacBook-Pro:myorg owner$ 
FrozenPandaz commented 6 years ago

Please update jest-preset-angular to 6.0.1. There's a PR out to address this.

arturhun commented 6 years ago

Unfortunately, it does not help. I think for now I am gonna let the solution get stable and documented.

FrozenPandaz commented 6 years ago

@arturhun @jasedwards Can you provide more details about what did not work after updating jest-preset-angular?

Specifically, can you post result of npm ls ts-jest?

My result:

Jasons-MacBook-Pro:oldnxws jason$ npm ls ts-jest
oldnxws@0.0.0 /Users/jason/projects/temp/oldnxws
└─┬ jest-preset-angular@6.0.1
  └── ts-jest@23.1.4
arturhun commented 6 years ago

@FrozenPandaz Thanks for getting back to me. I don't really recall now what the error was, I would have to run it all over. But again, as I might have run wrong sequence, I think it would be best if we first agree on the sequence to run. So, given the following globals:

Owners-MacBook-Pro:Code owner$ yarn global list
yarn global v1.9.4
info "@angular/cli@6.2.3" has binaries:
   - ng
info "@nrwl/schematics@6.4.0-beta.1" has binaries:
   - create-nx-workspace
   - nx
info "jest@23.6.0" has binaries:
   - jest

I should run:

create-nx-workspace myorg
cd myorg
yarn add jest-preset-angular@6.0.1
ng g jest
ng g app jest-app --unit-test-runner jest

Is that correct?

And then, run tests:

ng test jest-app
FrozenPandaz commented 6 years ago

@arturhun Almost got it. ng g jest will reset the version of jest-preset-angular to 6.0.0.

create-nx-workspace myorg
cd myorg
ng g jest
yarn add jest-preset-angular@6.0.1
ng g app jest-app --unit-test-runner jest
ng test jest-app
arturhun commented 6 years ago

@FrozenPandaz Sorry, to have kept you waiting. So, this jest-preset-angular version was apparently the reason. The script above works perfectly OOTB for me! Thanks for your effort!

arturhun commented 6 years ago

Works also when I add a lib:

ng g lib jest-lib --unit-test-runner jest
ng test jest-lib

We can close this ticket. ...and work on updating the docs :)

FrozenPandaz commented 6 years ago

Glad your issue is resolved :)

Sorry for the lack of docs. We will work on updating the docs more rigorously.

FrozenPandaz commented 6 years ago

As a recap:

Fix

To fix this issue, install 6.0.1 of jest-preset-anguolar.

Cause

This issue is caused by a transitive dependency, ts-jest which has a lot of new features in a rewrite of the library. Unfortunately, they do not follow semver and jest-preset-angular brought in the latest version in Major version 23 which contained a rewrite and breaking changes as of 23.10.0 (https://github.com/thymikee/jest-preset-angular/issues/195).

Solution

We worked with jest-preset-angular to resolve the issue (https://github.com/thymikee/jest-preset-angular/pull/196) and a migration has been written to automatically migrate workspaces to jest-preset-angular@6.0.1 in the upcoming release of Nx (https://github.com/nrwl/nx/pull/779).

Stability

For any concerns about using jest within Nx, we have seen some substantial reductions in time required to do unit tests with some large projects. Aside from this issue, the feature is working and the current interface is stable and will only improve with upcoming additions of more options for running tests with jest.

jasedwards commented 6 years ago

@arturhun @jasedwards Can you provide more details about what did not work after updating jest-preset-angular?

Specifically, can you post result of npm ls ts-jest?

My result:

Jasons-MacBook-Pro:oldnxws jason$ npm ls ts-jest
oldnxws@0.0.0 /Users/jason/projects/temp/oldnxws
└─┬ jest-preset-angular@6.0.1
  └── ts-jest@23.1.4

Issue #782 still happened after updating. I did verify I had the correct version of preset. I had to back all of that out so I will need to start over setting it up. I will do that and run npm ls ts-jest when I have time

github-actions[bot] commented 1 year 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.