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/[email protected]" has binaries:
- ng
info "@nrwl/[email protected]" has binaries:
- create-nx-workspace
- nx
info "[email protected]" 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 > [email protected]: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
warning karma > log4js > loggly > request > [email protected]: Use uuid module instead
warning karma > log4js > nodemailer > [email protected]: 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 > [email protected]: This project is unmaintained
warning karma > socket.io > engine.io > [email protected]: stop using this version
warning karma > log4js > loggly > request > hawk > [email protected]: 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$
Please update jest-preset-angular to 6.0.1. There's a PR out to address this.
Unfortunately, it does not help. I think for now I am gonna let the solution get stable and documented.
@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
[email protected] /Users/jason/projects/temp/oldnxws
└─┬ [email protected]
└── [email protected]
@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/[email protected]" has binaries:
- ng
info "@nrwl/[email protected]" has binaries:
- create-nx-workspace
- nx
info "[email protected]" has binaries:
- jest
I should run:
create-nx-workspace myorg
cd myorg
yarn add [email protected]
ng g jest
ng g app jest-app --unit-test-runner jest
Is that correct?
And then, run tests:
ng test jest-app
@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 [email protected]
ng g app jest-app --unit-test-runner jest
ng test jest-app
@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!
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 :)
Glad your issue is resolved :)
Sorry for the lack of docs. We will work on updating the docs more rigorously.
As a recap:
To fix this issue, install 6.0.1 of jest-preset-anguolar.
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).
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 [email protected] in the upcoming release of Nx (https://github.com/nrwl/nx/pull/779).
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.
@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 [email protected] /Users/jason/projects/temp/oldnxws └─┬ [email protected] └── [email protected]
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