jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.48k stars 4.02k forks source link

Stand alone blueprint throws error during unit testing #25454

Closed dwarakaprasad closed 6 months ago

dwarakaprasad commented 6 months ago
Overview of the issue

A stand alone blueprint throws the following error during unit testing,

 FAIL  generators/stand-alone/generator.spec.js > SubGenerator stand-alone of stdalone JHipster blueprint > run
TypeError: You don't seem to have a generator with the name “generator-jhipster-stdalone” installed.
But help is on the way:

You can see available generators via npm search yeoman-generator or via http://yeoman.io/generators/. 
Install them with npm install generator-jhipster-stdalone.

To see all your installed generators run yo --generators. Adding the --help option will also show subgenerators. 

If yo cannot find the generator, run yo doctor to troubleshoot your system.
 ❯ checkGenerator ../../generator-jhipster/node_modules/yeoman-environment/dist/environment-base.js:212:23
 ❯ FullEnvironment.create ../../generator-jhipster/node_modules/yeoman-environment/dist/environment-base.js:254:33
 ❯ JHipsterRunContext.build ../../generator-jhipster/node_modules/yeoman-test/dist/run-context.js:548:26
 ❯ JHipsterRunContext.run ../../generator-jhipster/node_modules/yeoman-test/dist/run-context.js:82:13
 ❯ JHipsterRunContext.run ../../generator-jhipster/dist/testing/helpers.js:181:27

 ❯ generators/stand-alone/generator.spec.js:11:7

The above error occurs when using generator-jhipster main. Everything seems ok with release 8.1.0 version.

Motivation for or Use Case

It should be possible to create and successfully run a stand alone blueprint.

Reproduce the error

Create a blueprint using the attached .yo-rc.json

Related issues

None.

Suggest a Fix

Triage still in progress.

@mshima this part is returning undefined, which was changed as part of this pr. Prior to this change, the store.meta seem to have loaded jhipster-blueprint: & jhipster: name spaces which was why the blueprint was discover-able (based on my limited knowledge). Currently I only see that jhipster:** name space only being loaded and hence the findMeta method return undefined.

Can you please provide some insight and I can try to fix this... Thanks...

JHipster Version(s)

main branch

JHipster configuration
.yo-rc.json file
{
  "generator-jhipster": {
    "additionalSubGenerators": "stand-alone",
    "baseName": "stdalone",
    "cli": true,
    "entities": [],
    "generators": {
      "stand-alone": {
        "command": false,
        "priorities": [
          "initializing",
          "prompting",
          "configuring",
          "composing",
          "writing",
          "writingEntities",
          "postWriting"
        ],
        "sbs": null,
        "written": true
      }
    },
    "jhipsterVersion": "8.1.0",
    "localBlueprint": false,
    "sampleWritten": true,
    "subGenerators": []
  }
}
Environment and Tools

openjdk version "17.0.8" 2023-07-18 OpenJDK Runtime Environment Temurin-17.0.8+7 (build 17.0.8+7) OpenJDK 64-Bit Server VM Temurin-17.0.8+7 (build 17.0.8+7, mixed mode, sharing)

git version 2.34.1

node: v20.11.1 npm: 10.2.4

Docker version 25.0.3, build 4debf41

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
mshima commented 6 months ago

I'd say that is related to linking the generator-jhipster dependency instead of installing. Blueprint lookup uses relative path: https://github.com/jhipster/generator-jhipster/blob/595adc94fc657050a3a69d35940f019987ce5644/testing/helpers.ts#L176

So lookup won’t find the generator. Not stand alone generators have lookup done at runtime too, so they work.

mshima commented 6 months ago

You can try installing from git: npm install jhipster/generator-jhipster

dwarakaprasad commented 6 months ago

You can try installing from git: npm install jhipster/generator-jhipster

Doing this is causing,

 FAIL  generators/license/generator.spec.js [ generators/license/generator.spec.js ]
Error: Cannot find package 'fs-extra' imported from /home/dwarka/develop/jhipster/testing/generator-jhipster-stand/node_modules/generator-jhipster/dist/testing/support/check-enforcements.js
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_MODULE_NOT_FOUND' }

I think, for this issue we will have to move both fs-extra & esmocha from devDependencies to dependencies. Adding these 2 dependencies makes the original issue go away (thank you :-)). Do you want me to create a separate issue for this change or can I push it as part of this issue.

mshima commented 6 months ago

I think, for this issue we will have to move both fs-extra & esmocha from devDependencies to dependencies.

Blueprints uses vitest so we should not export mocha. https://github.com/jhipster/generator-jhipster/blob/main/testing/support/check-enforcements.ts should be moved back to test/support and not exported.

dwarakaprasad commented 6 months ago

Blueprints uses vitest so we should not export mocha.

Yeah that's right, it was my bad. I will push it back to test/support and raise a pr.

mshima commented 6 months ago

No problem, the original error could be fixed by passing the blueprint folder to lookup. Since the error only happens with linked generator-jhipster not sure we should do something about this.