Skip to content

Commit

Permalink
fix: jest setup and teardown sqlite adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
pmstss committed Sep 4, 2024
1 parent c9142a3 commit 46956e5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 66 deletions.
43 changes: 0 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"detect-port": "^1.6.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jest": "^28.8.2",
"husky": "^9.1.5",
"is-ci": "~3.0.1",
"is-port-reachable": "^4.0.0",
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
Expand Down
14 changes: 13 additions & 1 deletion src/migrations/Migration20240903144600.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ export class Migration20240903144600 extends Migration {
'create table `user` (`id` integer not null primary key autoincrement, `first_name` text not null, `last_name` text not null, `is_active` integer not null default true);'
);
this.addSql(
`insert into "user" ("first_name", "last_name") values ('Matti', 'Karttunen');`
`insert into user (id, first_name, last_name) values (1, 'Brynna', 'Lapping');`
);
this.addSql(
`insert into user (id, first_name, last_name) values (2, 'Ginnie', 'Denisard');`
);
this.addSql(
`insert into user (id, first_name, last_name) values (3, 'Emelita', 'Engley');`
);
this.addSql(
`insert into user (id, first_name, last_name) values (4, 'Bryanty', 'Craigmyle');`
);
this.addSql(
`insert into user (id, first_name, last_name) values (5, 'Nolan', 'Portchmouth');`
);
}

Expand Down
12 changes: 4 additions & 8 deletions test/global-setup.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const detectPort = require('detect-port');
const { config } = require('dotenv');
const { join } = require('path');
const { promisify } = require('util');
const { exec } = require('child_process');

module.exports = async () => {
const port = 5432;
const freePort = await promisify(detectPort)(port);
const cwd = join(__dirname, '..');

config();

if (freePort === port) {
await promisify(exec)('npm run migration:up', { cwd });
}
await promisify(exec)('npm run migration:up', {
cwd: join(__dirname, '..'),
stdio: 'inherit'
});
};
21 changes: 9 additions & 12 deletions test/global-teardown.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
const { default: config } = require('../src/mikro-orm.config');
const isCi = require('is-ci');
const { MikroORM } = require('@mikro-orm/core');
const { join } = require('path');

module.exports = async () => {
const cwd = join(__dirname, '..');
if (isCi) {
return;
}

if (!isCi) {
let orm;
try {
orm = await MikroORM.init(config);
let orm;
try {
orm = await MikroORM.init(config);

await orm.em
.getConnection()
.execute('delete from "user" where "id" != 1;');
} finally {
await orm?.close();
}
await orm.em.getConnection().execute('delete from "user" where "id" > 5;');
} finally {
await orm?.close();
}
};

0 comments on commit 46956e5

Please sign in to comment.