angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.77k stars 11.98k forks source link

Unit Test fails after upgrading to angular8 #16545

Closed kalpesh-b closed 4 years ago

kalpesh-b commented 4 years ago

I upgraded the project from Angular7 to Angular8. (for now, I haven't upgraded Nx, the current version used is "@nrwl/nx": "7.8.7",)

After upgrade, my application runs successfully (without any issues in build or deploy), unit test executes successfully when I run it module wise, but when I run the test cases it for an app it fails and throws below error

script used

"test:appone": "ng test --project=app-one --no-watch",

Log

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'test:one' ]
2 info using npm@6.4.1
3 info using node@v10.15.3
4 verbose run-script [ 'pretest:one', 'test:one', 'posttest:one' ]
5 info lifecycle proj-micro-apps@1.1.0~pretest:one: proj-micro-apps@1.1.0
6 info lifecycle proj-micro-apps@1.1.0~test:one: proj-micro-apps@1.1.0
7 verbose lifecycle proj-micro-apps@1.1.0~test:one: unsafe-perm in lifecycle true
8 verbose lifecycle proj-micro-apps@1.1.0~test:one: PATH: C:\Users\KBharambe\AppData\Roaming\nvm\v10.15.3\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\NX8New\proj-micro-apps\node_modules\.bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\1E\NomadBranch\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\WINDOWS\System32\OpenSSH\;C:\Users\KBharambe\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Users\KBharambe\scoop\apps\maven\current\bin;C:\Users\KBharambe\scoop\shims;C:\Users\KBharambe\.windows-build-tools\python27\;C:\Users\KBharambe\AppData\Local\Continuum\anaconda3;C:\Users\KBharambe\AppData\Local\Continuum\anaconda3\Library\mingw-w64\bin;C:\Users\KBharambe\AppData\Local\Continuum\anaconda3\Library\usr\bin;C:\Users\KBharambe\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\KBharambe\AppData\Local\Continuum\anaconda3\Scripts;C:\Users\KBharambe\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\KBharambe\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\KBharambe\AppData\Roaming\npm;C:\Users\KBharambe\AppData\Roaming\nvm;C:\Program Files\nodejs
9 verbose lifecycle proj-micro-apps@1.1.0~test:one: CWD: D:\NX8New\proj-micro-apps
10 silly lifecycle proj-micro-apps@1.1.0~test:one: Args: [ '/d /s /c',
10 silly lifecycle   'ng test --project=app-one  --no-watch' ]
11 silly lifecycle proj-micro-apps@1.1.0~test:one: Returned: code: 1  signal: null
12 info lifecycle proj-micro-apps@1.1.0~test:one: Failed to exec test:one script
13 verbose stack Error: proj-micro-apps@1.1.0 test:one: `ng test --project=app-one  --no-watch`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\KBharambe\AppData\Roaming\nvm\v10.15.3\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\KBharambe\AppData\Roaming\nvm\v10.15.3\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid proj-micro-apps@1.1.0
15 verbose cwd D:\NX8New\proj-micro-apps
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test:one"
18 verbose node v10.15.3
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error proj-micro-apps@1.1.0 test:one: `ng test --project=app-one  --no-watch`
22 error Exit status 1
23 error Failed at the proj-micro-apps@1.1.0 test:one script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I'm using karma jasmine for the same

    "karma": "4.4.1",
    "@types/jasmine": "3.5.0",
    "@types/jasminewd2": "2.0.8",
    "karma-jasmine": "2.0.1",
    "karma-jasmine-html-reporter": "1.4.2",
    "jasmine-core": "3.5.0",
    "jasmine-marbles": "0.6.0",
    "jasmine-reporters": "2.3.2",
    "jasmine-spec-reporter": "4.2.1",
    "karma-chrome-launcher": "3.1.0",
    "karma-cli": "2.0.0",
    "karma-coverage": "2.0.1",
    "karma-coverage-istanbul-reporter": "2.1.1",
    "karma-jasmine": "2.0.1",
    "karma-jasmine-html-reporter": "1.4.2",
    "karma-junit-reporter": "2.0.1",

ng --version

Angular CLI: 8.3.20
Node: 10.15.3
OS: win32 x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.803.20
@angular-devkit/build-angular      0.803.21
@angular-devkit/build-ng-packagr   0.803.20
@angular-devkit/build-optimizer    0.803.21
@angular-devkit/build-webpack      0.803.21
@angular-devkit/core               8.3.20
@angular-devkit/schematics         8.3.20
@angular/cdk                       8.2.3
@angular/cli                       8.3.20
@angular/flex-layout               8.0.0-beta.27
@angular/material                  8.2.3
@angular/material-moment-adapter   8.2.3
@ngtools/json-schema               1.1.0
@ngtools/webpack                   8.3.21
@schematics/angular                8.3.20
@schematics/update                 0.803.20
ng-packagr                         5.0.0
rxjs                               6.5.3
typescript                         3.4.5
webpack                            4.39.2

I tried it with multiple node versions but still same.

Can you please let me know what can be the issue?

Thanks in advance.

AndrewKushnir commented 4 years ago

Hi @kalpesh-b, it looks like this issue might be related to Angular CLI, so I'm transferring this ticket to CLI repo. Thank you.

alan-agius4 commented 4 years ago

@kalpesh-b, have you tried remove the node_modules and install them again? Also as testing builder you are using @angular-devkit/build-angular:karma?

kalpesh-b commented 4 years ago

@alan-agius4, Yes tried removing node_modules, doing npm cache clean --force as well. I also tried downgrading node from 12.13.1 to 11.14.0 and then to 10.15.3. I have also tried AngularCli 8.2.14 & 8.2.0

Yes test "builder": "@angular-devkit/build-angular:karma",

kalpesh-b commented 4 years ago

One thing I have noticed is that I get this error only when I use "codeCoverage": true in angular.json or --code-coverage=true in script.

If I remove "codeCoverage" flag the test cases executes without any errors but I won't get any coverage.

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================

In both cases, all the test cases execute successfully.

alan-agius4 commented 4 years ago

What I am thinking is that karma-coverage might be conflicting with karma-coverage-istanbul-reporter.

In your karma.config.js do you have coverage set as reporter? If that's the case, can you try to remove it.

Internally we add coverage-Istanbul to the reporters when code coverage us enabled.

If the problem persist please share your karma.config.js.

kalpesh-b commented 4 years ago

@alan-agius4 Actually removing karma-junit-reporter fixed the issue. Thanks for your help :)

angular-automatic-lock-bot[bot] commented 4 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.