Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

autoLoad entities will not find entities after using a beforeEach loop #102

Closed
xenoterracide opened this issue Jan 9, 2023 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@xenoterracide
Copy link

xenoterracide commented Jan 9, 2023

Describe the bug
This is a duplicate of #17, but that's obviously not 100% fixed

here's the output logs, before the stacktrace. As you can see in the first pass it finds them, but on any subsequent beforeEach it does not. If using beforeAll instead, there is no problem. Unfortunately in one of our use cases we're using jest-cucumber and that doesn't seem to be giving me that option. I'm going to try using a closer there instead.

> nx run product:test-behavior --testFile=commands-for-product-catalogue/commands-for-product-catalogue

  console.log
    [info] MikroORM version: 5.6.3

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

  console.log
    [discovery] ORM entity discovery started, using ReflectMetadataProvider

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

  console.log
    [discovery] - entity discovery finished, found 0 entities, took 1 ms

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

  console.log
    [info] MikroORM successfully connected to database undefined on mongodb://127.0.0.1:63276/

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

  console.log
    [info] MikroORM version: 5.6.3

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

  console.log
    [discovery] ORM entity discovery started, using ReflectMetadataProvider

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

  console.log
    [discovery] - entity discovery finished, found 0 entities, took 1 ms

      at DefaultLogger.log (../../node_modules/@mikro-orm/core/logging/DefaultLogger.js:31:14)
          at async Promise.all (index 5)
          at async Promise.all (index 24)

Stack trace

after turning off discovery

    MetadataError: Metadata for entity StorefrontProductAggregate not found

      at Function.missingMetadata (../../node_modules/@mikro-orm/core/errors.js:166:16)
      at MetadataStorage.get (../../node_modules/@mikro-orm/core/metadata/MetadataStorage.js:54:42)
      at MongoEntityManager.getRepository (../../node_modules/@mikro-orm/core/EntityManager.js:64:40)
      at MongoEntityManager.getRepository (../../node_modules/@mikro-orm/mongodb/MongoEntityManager.js:23:22)
      at InstanceWrapper.useFactory [as metatype] (../../node_modules/@mikro-orm/nestjs/mikro-orm.providers.js:98:34)
      at TestingInjector.instantiateClass (../../node_modules/@nestjs/core/injector/injector.js:304:55)
      at callback (../../node_modules/@nestjs/core/injector/injector.js:48:41)
      at TestingInjector.resolveConstructorParams (../../node_modules/@nestjs/core/injector/injector.js:124:24)
      at TestingInjector.loadInstance (../../node_modules/@nestjs/core/injector/injector.js:52:9)

To Reproduce

import { Test, TestingModule } from '@nestjs/testing';import { FixtureService } from '@bb/app';import { ProductAppModule } from '../../../src/app/product-app.module';describe('first', () => {
  let module: TestingModule;
  beforeEach(async () => {
    module = await Test.createTestingModule({
      imports: [ProductAppModule.register({ appEnv: 'local' })],
    })
      .compile();
  });
  afterEach(async () => {
    await module.close();
  });
  it('test 1', async () => {
    return true
  });it('test 2', async () => {return true
  });
});

ProductAppModule imports

@Global()
@Module({
  providers: [MikroListener],
  imports: [
    MikroOrmModule.forRootAsync({
      imports: [CqrsModule],
      providers: [mongoMemoryServerProvider],
      inject: [MongoMemoryServer, EventPublisher],
      useFactory: (memserver: MongoMemoryServer, publisher: EventPublisher) => {
        return {
          clientUrl: memserver.getUri(),
          strict: true,
          tsNode: true,
          type: 'mongo',
          validate: true,
          validateRequired: true,
          verbose: true,
          debug: true,
          discovery: {
            warnWhenNoEntities: false,
          },
          subscribers: [
            new EmitEventsSubscriber(),
            new AttachPublisherSubscriber(publisher),
          ],
        };
      },
    }),
  ],
})
export class MikroOrmDevConfigModule {}

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Versions

❯ node --version && yarn why mikro-orm && yarn why jest && yarn why nestjs && yarn why mongodb && yarn why typescript && yarn why @mikro-orm/nestjs
v18.12.1
├─ @mikro-orm/core@npm:5.6.3
│  └─ mikro-orm@npm:5.6.3 (via npm:~5.6.3)
│
└─ @mikro-orm/core@npm:5.6.3 [8316d]
   └─ mikro-orm@npm:5.6.3 (via npm:~5.6.3)
├─ jest-cucumber@npm:2.0.12
│  └─ jest@npm:27.5.1 [8875a] (via npm:27.5.1 [8875a])
│
└─ services-core@workspace:.
   └─ jest@npm:27.5.1 [8875a] (via npm:27.5.1 [8875a])
├─ @mikro-orm/mongodb@npm:5.6.3
│  └─ mongodb@npm:4.13.0 (via npm:4.13.0)
│
├─ @mikro-orm/mongodb@npm:5.6.3 [8316d]
│  └─ mongodb@npm:4.13.0 (via npm:4.13.0)
│
├─ mongodb-memory-server-core@npm:8.0.4
│  └─ mongodb@npm:4.2.0 (via npm:^4.1.3)
│
└─ services-core@workspace:.
   └─ mongodb@npm:4.2.2 (via npm:~4.2.0)
├─ @ts-morph/common@npm:0.7.5
│  └─ typescript@patch:typescript@npm%3A4.1.6#~builtin<compat/typescript>::version=4.1.6&hash=bda367 (via patch:typescript@~4.1.3#~builtin<compat/typescript>)
│
├─ import-sort-parser-typescript@npm:6.0.0
│  └─ typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367 (via patch:typescript@^3.2.4#~builtin<compat/typescript>)
│
└─ services-core@workspace:.
   └─ typescript@patch:typescript@npm%3A4.7.3#~builtin<compat/typescript>::version=4.7.3&hash=bda367 (via patch:typescript@4.7.3#~builtin<compat/typescript>)
└─ services-core@workspace:.
   └─ @mikro-orm/nestjs@npm:5.1.5 [8316d] (via npm:^5.1.5 [8316d])
@xenoterracide xenoterracide added the bug Something isn't working label Jan 9, 2023
@mikro-orm mikro-orm locked and limited conversation to collaborators Jan 9, 2023
@B4nan B4nan converted this issue into discussion #103 Jan 9, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants