Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Is there a way to test generators written in typescript with yeoman-test? #105

Closed
aanno opened this issue May 8, 2020 · 4 comments

Comments

@aanno
Copy link

aanno commented May 8, 2020

Is there a way to test generators written in typescript with yeoman-test?

When I try something like

run(join(__dirname, '../generators/app'))

I've got an error:

Uncaught Error: You don't seem to have a generator with the name “jhipster-module-aanno:app” installed.

Hence it is perhaps better to pass the constructor there. But I don't know to do that, i.e. the following is wrong:

import {MyGenerator} from "../generators/app"
...
run(Generator)
@aanno
Copy link
Author

aanno commented May 8, 2020

And when I even try:

import {Constructor, run} from "yeoman-test"
import {Generator} from "yeoman-generator"
import {MyGenerator} from "../generators/app"

const generator: Constructor<Generator> = MyGenerator.new
run(generator, {resolved: true})

I ended up with

Uncaught TypeError: Cannot read property 'createGenerator' of undefined

@mshima
Copy link
Member

mshima commented May 8, 2020

Is there a way to test generators written in typescript with yeoman-test?

When I try something like

run(join(__dirname, '../generators/app'))

I've got an error:

Uncaught Error: You don't seem to have a generator with the name “jhipster-module-aanno:app” installed.

Make sure your generator folder is called generator-jhipster-module-aanno.

Otherwise you should register the namespace with the generator.

@aanno
Copy link
Author

aanno commented May 8, 2020

Well, the directory name is ok. I finally found 2 issues:

  • tsconfig.json target must be at least es6. See stackoverflow for the explanation.
  • Code should be like this
import {describe, beforeEach} from "mocha"
import {join} from "path"
import {copySync} from "fs-extra"
import {file} from "yeoman-assert"
import {Constructor, run} from "yeoman-test"
// import {Generator} from "yeoman-generator"
import {MyGenerator} from "../generators/app"

describe('JHipster generator aanno', () => {
  // const generator: Constructor<Generator> = MyGenerator.new
  describe('Test with Maven and AngularX', () => {
    beforeEach(done => {
      // run(join(__dirname, '../generators/app'))
      run(MyGenerator as any)
  ...

The as any seems to indicate that the type definition in @types/yeoman-test is wrong.

@mshima
Copy link
Member

mshima commented May 25, 2020

Looks like the problem is with yeoman-test type definition.
Closing.

@mshima mshima closed this as completed May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants