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] - Awilix Fails to Autoload Modules in Vitest Tests with TypeScript Setup #359

Closed
eskylake opened this issue Apr 16, 2024 · 1 comment

Comments

@eskylake
Copy link

eskylake commented Apr 16, 2024

Hi, Tnx Awilix.

I know that this may not be an issue and its better to be asked in any stackoverflow-like media.
I already asked one.

I am using:

"typescript": "^5"
"vitest": "^1"
"awilix": "^8"

loadModules() doesn't load modules while creating container through my tests.
Due to my research & other issues which I read here, I couldn't find any proper solution to the problem.
I don't wanna use type: module in package.json & I can't load .ts files directly into the container.

This won't work:

  container.loadModules(
    [
      `${resolve(__dirname, '../Connection/*.ts')}`,
      `${resolve(__dirname, '../Connection/**/*.ts')}`,
    ],
    {
      resolverOptions: {
        lifetime: Lifetime.SINGLETON,
        register: asClass,
      },
    },
  );

I could fix it by including my test directory in both tsconfig.json and vitest.config files. But I'm not sure if this is correct.
Would you plz help me with this issue? Thanks in advance

@jeffijoe
Copy link
Owner

Awilix uses fast-glob to locate files. If this works outside vitest then I would suggest opening an issue there. I don’t use vitest so I’m not sure what it could be.

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