allenhwkim / ngentest

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

Explain how to deal with paths and modules #51

Closed santicalvo closed 1 year ago

santicalvo commented 3 years ago

I find hard to know how to run this.

Where do we need to run the command gentest?

How do we deal with modules and lazy loaded modules?

Ok, I didn't do a lot of research, I just created an app, a new component in folder and did this

ng new testing
cd testing
ng g c sample-test/sample

Now, I just don't know how to run the gentest command

Commands gentest sample-test/sample/sample.component.ts, gentest sample.component.ts :

internal/modules/cjs/loader.js:1033
  throw err;
  ^

Error: Cannot find module '/home/user/Desktop/testing/testing/sample-test/sample/sample.component.ts'
......

Command gentest src/app/sample-test/sample/sample.component.ts:

/home/user/Desktop/testing/testing/src/app/sample-test/sample/sample.component.ts:1
import { Component, OnInit } from '@angular/core';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1117:16)
    at Module._compile (internal/modules/cjs/loader.js:1165:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at testFile (/home/santi/.nvm/versions/node/v14.5.0/lib/node_modules/gentest/bin/gentest.js:46:3)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/santi/.nvm/versions/node/v14.5.0/lib/node_modules/gentest/bin/gentest.js:30:14)

Thanks, I get you don't have to answer me and I can try to solve myself. But I have lots of things to do so I ask to save time.

HangLoop commented 3 years ago

@santicalvo run gentest src/app/sample-test/sample/sample.component.ts under /home/user/Desktop/testing/testing/ should work.

allenhwkim commented 3 years ago

try

npx gentest src/app/sample-test/sample/sample.component.ts

gentest command must run under nodejs environment.