From 8398fa4000d22b5f6ef25cc977de12438cfc60c7 Mon Sep 17 00:00:00 2001 From: jennifersp <44716627+jennifersp@users.noreply.github.com> Date: Wed, 16 Nov 2022 10:06:48 -0800 Subject: [PATCH] add smoketest for MikroORM (#4804) --- .../orm-tests/mikro-orm/README.md | 9 ++++ .../orm-tests/mikro-orm/package.json | 21 +++++++++ .../orm-tests/mikro-orm/src/entity/User.ts | 22 ++++++++++ .../orm-tests/mikro-orm/src/index.ts | 43 +++++++++++++++++++ .../orm-tests/mikro-orm/tsconfig.json | 14 ++++++ integration-tests/orm-tests/orm-tests.bats | 12 +++++- 6 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 integration-tests/orm-tests/mikro-orm/README.md create mode 100644 integration-tests/orm-tests/mikro-orm/package.json create mode 100644 integration-tests/orm-tests/mikro-orm/src/entity/User.ts create mode 100644 integration-tests/orm-tests/mikro-orm/src/index.ts create mode 100644 integration-tests/orm-tests/mikro-orm/tsconfig.json diff --git a/integration-tests/orm-tests/mikro-orm/README.md b/integration-tests/orm-tests/mikro-orm/README.md new file mode 100644 index 0000000000..03e266de86 --- /dev/null +++ b/integration-tests/orm-tests/mikro-orm/README.md @@ -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 diff --git a/integration-tests/orm-tests/mikro-orm/package.json b/integration-tests/orm-tests/mikro-orm/package.json new file mode 100644 index 0000000000..d8150ea522 --- /dev/null +++ b/integration-tests/orm-tests/mikro-orm/package.json @@ -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" + } +} + diff --git a/integration-tests/orm-tests/mikro-orm/src/entity/User.ts b/integration-tests/orm-tests/mikro-orm/src/entity/User.ts new file mode 100644 index 0000000000..b7d99cfb59 --- /dev/null +++ b/integration-tests/orm-tests/mikro-orm/src/entity/User.ts @@ -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; + } +} diff --git a/integration-tests/orm-tests/mikro-orm/src/index.ts b/integration-tests/orm-tests/mikro-orm/src/index.ts new file mode 100644 index 0000000000..83387db06f --- /dev/null +++ b/integration-tests/orm-tests/mikro-orm/src/index.ts @@ -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({ + 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) +}); diff --git a/integration-tests/orm-tests/mikro-orm/tsconfig.json b/integration-tests/orm-tests/mikro-orm/tsconfig.json new file mode 100644 index 0000000000..5d8d9786e8 --- /dev/null +++ b/integration-tests/orm-tests/mikro-orm/tsconfig.json @@ -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, + } +} diff --git a/integration-tests/orm-tests/orm-tests.bats b/integration-tests/orm-tests/orm-tests.bats index 6ef0cecc81..e4b3c17ab5 100644 --- a/integration-tests/orm-tests/orm-tests.bats +++ b/integration-tests/orm-tests/orm-tests.bats @@ -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" {