mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-09 01:56:30 -05:00
add smoketest for MikroORM (#4804)
This commit is contained in:
9
integration-tests/orm-tests/mikro-orm/README.md
Normal file
9
integration-tests/orm-tests/mikro-orm/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Mikro-ORM Smoke Test
|
||||
|
||||
The `index.ts` file is the main entry point and will insert a new record into the database, then load it, print
|
||||
success, and exit with a zero exit code. If any errors are encountered, they are logged, and the process exits with a
|
||||
non-zero exit code.
|
||||
|
||||
To run this smoke test project:
|
||||
1. Run `npm install` command
|
||||
2. Run `npm start` command
|
||||
21
integration-tests/orm-tests/mikro-orm/package.json
Normal file
21
integration-tests/orm-tests/mikro-orm/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "mikro-orm-smoketest",
|
||||
"version": "0.0.1",
|
||||
"description": "DoltDB smoke test for Mikro-ORM integration",
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
"start": "ts-node src/index.ts",
|
||||
"mikro-orm": "mikro-orm-ts-node-commonjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ts-node": "^10.7.0",
|
||||
"@types/node": "^16.11.10",
|
||||
"typescript": "^4.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mikro-orm/core": "^5.0.3",
|
||||
"@mikro-orm/mysql": "^5.0.3",
|
||||
"mysql": "^2.14.1"
|
||||
}
|
||||
}
|
||||
|
||||
22
integration-tests/orm-tests/mikro-orm/src/entity/User.ts
Normal file
22
integration-tests/orm-tests/mikro-orm/src/entity/User.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Entity, PrimaryKey, Property } from "@mikro-orm/core";
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryKey()
|
||||
id!: number;
|
||||
|
||||
@Property()
|
||||
firstName!: string;
|
||||
|
||||
@Property()
|
||||
lastName!: string;
|
||||
|
||||
@Property()
|
||||
age!: number;
|
||||
|
||||
constructor(firstName: string, lastName: string, age: number) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
43
integration-tests/orm-tests/mikro-orm/src/index.ts
Normal file
43
integration-tests/orm-tests/mikro-orm/src/index.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { MikroORM } from "@mikro-orm/core";
|
||||
import { MySqlDriver } from '@mikro-orm/mysql';
|
||||
import { User } from "./entity/User";
|
||||
|
||||
async function connectAndGetOrm() {
|
||||
const orm = await MikroORM.init<MySqlDriver>({
|
||||
entities: [User],
|
||||
type: "mysql",
|
||||
clientUrl: "mysql://localhost:3306",
|
||||
dbName: "dolt",
|
||||
user: "dolt",
|
||||
password: "",
|
||||
persistOnCreate: true,
|
||||
});
|
||||
|
||||
return orm;
|
||||
}
|
||||
|
||||
connectAndGetOrm().then(async orm => {
|
||||
console.log("Connected");
|
||||
const em = orm.em.fork();
|
||||
|
||||
// this creates the tables if not exist
|
||||
const generator = orm.getSchemaGenerator();
|
||||
await generator.updateSchema();
|
||||
|
||||
console.log("Inserting a new user into the database...")
|
||||
const user = new User("Timber", "Saw", 25)
|
||||
await em.persistAndFlush(user)
|
||||
console.log("Saved a new user with id: " + user.id)
|
||||
|
||||
console.log("Loading users from the database...")
|
||||
const users = await em.findOne(User, 1)
|
||||
console.log("Loaded users: ", users)
|
||||
|
||||
orm.close();
|
||||
console.log("Smoke test passed!")
|
||||
process.exit(0)
|
||||
}).catch(error => {
|
||||
console.log(error)
|
||||
console.log("Smoke test failed!")
|
||||
process.exit(1)
|
||||
});
|
||||
14
integration-tests/orm-tests/mikro-orm/tsconfig.json
Normal file
14
integration-tests/orm-tests/mikro-orm/tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"target": "es2017",
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./src",
|
||||
"incremental": true,
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ teardown() {
|
||||
npx -c "prisma migrate dev --name init"
|
||||
}
|
||||
|
||||
# Prisma is an ORM for Node/TypeScript applications. This test checks out the Peewee test suite
|
||||
# Prisma is an ORM for Node/TypeScript applications. This test checks out the Prisma test suite
|
||||
# and runs it against Dolt.
|
||||
@test "Prisma ORM test suite" {
|
||||
skip "Not implemented yet"
|
||||
@@ -77,6 +77,16 @@ teardown() {
|
||||
npm start
|
||||
}
|
||||
|
||||
# MikroORM is an ORM for Node/TypeScript applications. This is a simple smoke test to make sure
|
||||
# Dolt can support the most basic MikroORM operations.
|
||||
@test "MikroORM smoke test" {
|
||||
mysql --protocol TCP -u dolt -e "create database dolt;"
|
||||
|
||||
cd mikro-orm
|
||||
npm install
|
||||
npm start
|
||||
}
|
||||
|
||||
# Turn this test on to prevent the container from exiting if you need to exec a shell into
|
||||
# the container to debug failed tests.
|
||||
#@test "Pause container for an hour to debug failures" {
|
||||
|
||||
Reference in New Issue
Block a user