Problems faced in Karma testing of hybrid app.

106 views
Skip to first unread message

Yash Jipkate

unread,
Jun 25, 2019, 4:59:58 AM6/25/19
to Angular and AngularJS discussion

Hi,


I am currently in a project where I have to migrate a large codebase from AngularJS 1.5 to Angular 8. I have used the downgradeModule feature of the ngUpgrade. Here are the specific steps I took (note that the app currently has a single module named “oppia”, and the directives/services are registered as oppia.directive(...), oppia.factory(...), etc.):


  1. I have a main bootstrap file with the Angular and AngularJS module. The bootstrapping is done in a similar way as described in the Angular docs here

  2. I exported the hybridized AngularJS module using exports.moduleName = oppia and imported this module in every file that requires it, using var oppia = require('AppInit.ts').moduleName; 

  3. In the karma.conf, I removed the compiled JS form of the bootstrap file which was earlier compiled to JS and then used in all the files.


I did not change the AngularJS spec files (example). For reference, here is the full diff of the above changes. (The main files to look at in this diff are AppInit.ts and karma.conf.ts.)


After these changes, I am facing OOM issues while running the existing Karma tests. It runs fine with a few tests but runs out of memory when more tests are included. I have tried to run a small number of tests (using fdescribe) and they seem to pass which means that the code is alright regarding functionality and that the issues are likely due to the hybridization.


I am unable to understand what is going wrong here. Here are some things I tried / thoughts I have:

  1. I had earlier tried using upgradeModule instead of downgradeModule, but the OOM was still there along with some additional problems.

  2. There might be too many services/directives attached to the main AngularJS module and maybe Karma is mocking the whole module again and again in the tests. 

  3. I might be doing the Karma testing incorrectly, in which case some additions to the karma spec files must be missing. 


I would really appreciate any advice on how to resolve the above issues. In particular, do hypotheses (2) and (3) above hold, and if so, is there a way to resolve them? Also, is there any set of “best practices” that the Angular team would suggest while carrying out Karma tests in a hybrid App? This has been blocking my work for a long time, so any help would be greatly appreciated.


Thanks,

Yash


P.S. You can check out the branch here if you like. Follow these steps to reproduce:

  • After cloning the branch run bash scripts/install_prerequisites.sh (on Debian/Ubuntu)

  • Fire up the local server by bash scripts/start.sh. After that, the script will open up the browser window for the site. (If it hangs after webpack compilation, press Ctrl+C in the terminal and run  bash scripts/start.sh again -- this is a known issue.)

  • Run bash scripts/run_frontend_tests.sh

  • See the OOM error.



Reply all
Reply to author
Forward
0 new messages