allenhwkim / ngentest

Angular6+ Unit Test Generator For Components, Directive, Services, and Pipes
https://ngentest.github.io
MIT License
144 stars 60 forks source link

How to user karma? #37

Closed tomaszs closed 4 years ago

tomaszs commented 4 years ago

Hello,

I have some questions:

  1. Where to place the config file? I have tried in project root and src folder and it didnt work
  2. What should be the format of the file? Just JSON? Or module exports? None of these work
  3. How to set up karma? In readme there should be framework: 'karma' but it does not work.
Rudgey84 commented 4 years ago

@tomaszs Yes same questions from me. I have created my config and specified framework: karma, however I am getting jest.fn references in the spec.ts output file.

minux84 commented 4 years ago

Found a solution, you can use parameter on command line: ngentest auth.service.ts -s --framework=karma

tomaszs commented 4 years ago

@minux84 yes, it works.

allenhwkim commented 4 years ago

You also can use config file https://github.com/allenhwkim/ngentest#config

if config file does not work for karma, please let me know the detail with example. I am not using Karma, preferring Jest, so I need error detail or full repo. example.

tomaszs commented 4 years ago

@allenhwkim I think it's more about the documentation. Where the file should go, what should be format to that file, and if it needs to be declared in any place.

jacobmcgowan commented 4 years ago

@allenhwkim I don't think the config file is working as we are expecting it to. The documentation says

You can override configuration by creating a file named as ngentest.config.js in your application directory.

which leaves me to believe that I should be able to add the file to the root of my project and run ngentest from there; however, ngentest is actually looking for the config file in the root of the directory it is installed in.

const appRoot = require('app-root-path');
if (fs.existsSync(path.join(appRoot.path, 'ngentest.config.js'))) {

Making changes to the config file there appears to work. I think this logic should be changed to allow the user to specify the config file to use as an argument (maybe --config), check the working directory if --config is not set, and maybe use the one in ngentest's root directory as a backup. Let me know what you think; I have some free time so I can help work on this issue.

allenhwkim commented 4 years ago

@jacobmcgowan plz make a PR for it