cyriacbr / mikro-resources Goto Github PK
View Code? Open in Web Editor NEWA set of packages for better DX and fast development with Mikro-ORM.
A set of packages for better DX and fast development with Mikro-ORM.
Hi,
as I am further planning on migrating my projects from TypeORM to MikroORM I noticed another issue I am having right now with seeding:
Before I was using typeorm-seeding (https://github.com/w3tecch/typeorm-seeding) which has a build in CLI to start seeding the DB, which is great for usage in CI/CD pipelines to set up a test database for e2e tests.
Is this somehow possible with this package? I want to keep migrations, seeds and tests seperated as much as possible from the main code.
Given these two extra test cases for factory.test.ts
:
describe(`Factory`, () => {
let orm: MikroORM;
let factory: FixtureFactory;
beforeAll(async () => {
orm = await MikroORM.init(ormConfig as any);
await orm.getSchemaGenerator().dropSchema();
await orm.getSchemaGenerator().createSchema();
factory = new FixtureFactory(orm);
});
afterAll(() => orm.close());
it(`make().with().oneAndPersist()`, async () => {
const result = factory.make(Author).with({ age: 30 });
expect(result.oneAndPersist).toBeInstanceOf(Function);
});
it(`make().with().manyAndPersist()`, async () => {
const result = factory.make(Author).with({ age: 30 });
expect(result.manyAndPersist).toBeInstanceOf(Function);
});
})
Results in the following output:
● Factory › make().with().oneAndPersist()
expect(received).toBeInstanceOf(expected)
Expected constructor: Function
Received value has no prototype
Received value: undefined
58 | it(`make().with().oneAndPersist()`, async () => {
59 | const result = factory.make(Author).with({ age: 30 });
> 60 | expect(result.oneAndPersist).toBeInstanceOf(Function);
| ^
61 | })
62 |
at test/factory.test.ts:60:34
at step (node_modules/tslib/tslib.js:143:27)
at Object.next (node_modules/tslib/tslib.js:124:57)
at node_modules/tslib/tslib.js:117:75
at Object.__awaiter (node_modules/tslib/tslib.js:113:16)
at Object.<anonymous> (test/factory.test.ts:58:39)
● Factory › make().with().manyAndPersist()
expect(received).toBeInstanceOf(expected)
Expected constructor: Function
Received value has no prototype
Received value: undefined
79 | it(`make().with().manyAndPersist()`, async () => {
80 | const result = factory.make(Author).with({ age: 30 });
> 81 | expect(result.manyAndPersist).toBeInstanceOf(Function);
| ^
82 | })
83 |
at test/factory.test.ts:81:35
at step (node_modules/tslib/tslib.js:143:27)
at Object.next (node_modules/tslib/tslib.js:124:57)
at node_modules/tslib/tslib.js:117:75
at Object.__awaiter (node_modules/tslib/tslib.js:113:16)
at Object.<anonymous> (test/factory.test.ts:79:40)
This package is exactly what I'm looking for, but sadly this pattern does not work. I'm trying to use it for creating seeds.
I want to use a seeder with mikro-orm similar to typeorm-seeder. However, I don't want to pollute my entities with decorators as the seeding is only needed for e2e tests and I want to keep my entities and code base clean of code used for testing purposes.
I also need to be able to generate e.g. 10 Entities with specifically set fields from faker
like firstName
but without using said decorators in the entities. Is it possible to do e.g. factory.make(Author).with({ firstName: faker.name.firstName() }).manyAndPersist(10);
or can the with()
mehtod only be used for creating one author?
Currently this is a type error:
@Property({
type: () => ArrayType<string>,
nullable: true,
})
@Fixture((faker) => [
faker.lorem.word(),
faker.lorem.word(),
faker.lorem.word(),
])
keywords: string[] = [];
It would be nice if it didn't error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.