allenhwkim / ngentest

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

Invalid typescript file - have tried the solutions in the closed issue #52

Closed jamanda2000 closed 1 year ago

jamanda2000 commented 3 years ago

Hi,

I've installed gentest and created ngentest.config.js file.

Have tried running ngentest task-form.components.js in the file folder using the terminal in Visual Studio, using gitbash, using ./task-form.components.js, using the full path, using -c ngentest.config.js at the end of the command. Seems whatever I try I get an error

$ ngentest task-form.components.ts -c ../ngentest.config.js Error. invalid typescript file. e.g., Usage $0 [options]

Any ideas of what to try next please?

Thanks, Amanda

jamanda2000 commented 3 years ago

It may be the type of file. Tried a different file and get the following error:

ngentest d:/work/projects/bondi/sonata/workflow/workflow-web/src/app/workflow/workspace/workspace.model.ts TypeError: Cannot read property 'toLowerCase' of undefined at new InjectableTestGen (C:\Users\ajackson\AppData\Roaming\npm\node_modules\ngentest\src\injectable\injectable-test-gen.js:21:65) at getTestGenerator (C:\Users\ajackson\AppData\Roaming\npm\node_modules\ngentest\index.js:90:33) at run (C:\Users\ajackson\AppData\Roaming\npm\node_modules\ngentest\index.js:127:27) at Object. (C:\Users\ajackson\AppData\Roaming\npm\node_modules\ngentest\index.js:228:3) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12) at node:internal/main/run_main_module:17:47

allenhwkim commented 3 years ago

Thanks for trying it.

  1. workspace.model.ts is not a Angular one, component, directive, service, etc. So it does not generate test for model.
  2. plz run with a absolute path like the following or use a relative path for your file name ngentest c:/full/path/task-form.components.ts
jamanda2000 commented 3 years ago

Hi, Thanks for replying.

I've found some files that seem to want to work, and I've tried with absolute path. Now getting this error:

ReferenceError: klassTemplate is not defined at Object. (D:\Work\Projects\bondi\sonata\workflow\workflow-web\ngentest.config.js:4:11) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:94:18) at loadConfig (C:\Users\ajackson\AppData\Roaming\npm\node_modules\ngentest\index.js:60:22) at Object. (C:\Users\ajackson\AppData\Roaming\npm\node_modules\ngentest\index.js:51:3) at Module._compile (node:internal/modules/cjs/loader:1101:14)

I've tried updated the config file, but don't think I'm doing it right. // when convert to JS, some codes need to be replaced to work replacements: [ // some 3rd party module causes an error { from: 'require\("html-custom-element"\)', to: '{}'}, { from: 'require\("cjs"\)', to: '{}'}, { from: '^\S+\.define\(.*\);', to: ''} // some commands causes error ],

allenhwkim commented 3 years ago

It seems your NodeJs running environment is not usual or your config file has an invalid template location. klassTemplate is located under node_modules/ngentest/... and it is only overridable by your config file

jamanda2000 commented 3 years ago

Thanks for the info. I'll do some investigating to see if I can resolve this. Will let you know how it goes, though it may be a week before I can look at this again (client release pressure at the moment so I have to stop playing with getting our unit tests expanded)

jamanda2000 commented 3 years ago

Okay, it's getting there. Running them from the ngentest folder has helped, and also doing a full pat to the config file. Now we're just missing all the types. Have tried created a types.d.ts file but it's not working.

This is the error when running from within the node_modules/ngentest folder

/d/Work/Projects/Trunk/sonata/workflow/workflow-web (issue/master/newAngula rBranch) $ ngentest d:/work/projects/bondi/sonata/workflow/workflow-web/src/app/work flow/workspace/workspace.service.ts -c D:/work/projects/trunk/sonata/workfl ow/workflow-web/node_modules/ngentest/ngentest.config.js Error: Cannot find module '@shared' Require stack:

If I look in the index.js file, none of the declaration files for modules are being found - so tried forcing that with types.d.ts file but no luck. image

jamanda2000 commented 3 years ago

PS: Sorry to be such a pain with this. I'm a java dev and very new to angular (learning it on the fly) so there's probably some things that I need to do that are obvious to others but I don't know about yet.

allenhwkim commented 1 year ago

Closing by inactivity.