You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to integrate typeorm-seeding in my NestJS application to use it for test data seeding. My NestJS structure does not use an ormconfig file, it defines the config at runtime, like the following:
I've done like that to use environment variables and isolate that usage only to my ConfigService.
Anyway, I've added all required configs, following the how-to in the README docs, and ended up with something like this in a test file:
import{Test,TestingModule}from'@nestjs/testing'import{TypeOrmModule}from'@nestjs/typeorm'import{getRepository}from'typeorm'import{setConnectionOptions,useSeeding,tearDownDatabase,factory}from'typeorm-seeding'importdatabaseConfigfrom'src/config/database/config'importDomainCycleRepositoryfrom'src/domain/cycle/repository'importDomainTeamModulefrom'src/domain/team'import{User}from'src/domain/user/entities'importDomainCycleServicefrom'./service'constbuildTestModule=()=>Test.createTestingModule({imports: [TypeOrmModule.forRoot(databaseConfig),TypeOrmModule.forFeature([DomainCycleRepository]),DomainTeamModule,],providers: [DomainCycleService],})describe('DomainCycleService',()=>{letmodule: TestingModuleletdomainCycleService: DomainCycleServicebeforeAll(async()=>{module=awaitbuildTestModule().compile()domainCycleService=module.get<DomainCycleService>(DomainCycleService)setConnectionOptions({type: 'sqlite',database: ':memory:',entities: [User],})awaituseSeeding()})afterAll(async()=>{awaitmodule.close()awaittearDownDatabase()})describe('get a single cycle',()=>{it('can get a single company cycle, constrained to company',async()=>{constcreatedUser=awaitfactory(User)().create()constfakeUsers=awaitgetRepository(User).find({})console.log(fakeUsers,createdUser)expect(true).toEqual(false)})})})
And I get two errors:
● DomainCycleService › get a single cycle › can get a single company cycle, constrained to company
No connection options were found in any orm configuration files.
at ConnectionOptionsReader.<anonymous> (src/connection/ConnectionOptionsReader.ts:42:19)
at step (node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
at Object.next (node_modules/typeorm/node_modules/tslib/tslib.js:122:57)
at fulfilled (node_modules/typeorm/node_modules/tslib/tslib.js:112:62)
And:
● DomainCycleService › get a single cycle › can get a single company cycle, constrained to company
TypeError: Cannot read property 'factory' of undefined
44 | describe('get a single cycle', () => {
45 | it('can get a single company cycle, constrained to company', async () => {
> 46 | const createdUser = await factory(User)().create()
| ^
47 | const fakeUsers = await getRepository(User).find({})
48 |
49 | console.log(fakeUsers, createdUser)
at node_modules/typeorm-seeding/src/typeorm-seeding.ts:40:79
at Object.<anonymous> (src/domain/cycle/cycle.spec.ts:46:46)
Any updates on this issue guys? I'm also trying to seed a in memory DB without having the orm config file, but i have the configuration in the test module, and i have the same error.
Hi!
I'm trying to integrate
typeorm-seeding
in my NestJS application to use it for test data seeding. My NestJS structure does not use anormconfig
file, it defines the config at runtime, like the following:I've done like that to use environment variables and isolate that usage only to my ConfigService.
Anyway, I've added all required configs, following the how-to in the
README
docs, and ended up with something like this in a test file:And I get two errors:
And:
Also, here is my
testConfig
file:My factory:
And my seed:
Anyone know what should I do to make it work?
The text was updated successfully, but these errors were encountered: