mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix unit test
This commit is contained in:
1 parent
5faa54c7ca
commit
49ec3c216f
6 files changed
+61
-69
No files matched your search
@@ -1,28 +1,21 @@
|
||||
import 'hydrooj';
|
||||
import 'hydrooj/src/loader';
|
||||
jest.mock('hydrooj/src/service/db');
|
||||
|
||||
export async function connect() {
|
||||
await new Promise((resolve) => {
|
||||
const db = require('hydrooj/src/service/db');
|
||||
db.bus.once('connect', resolve);
|
||||
});
|
||||
const modelSystem = require('hydrooj/src/model/system');
|
||||
const scripts = require('hydrooj/src/upgrade');
|
||||
let dbVer = (await modelSystem.get('db.ver')) || 0;
|
||||
const db = require('hydrooj/src/service/db');
|
||||
await db.start({});
|
||||
const scripts = require('hydrooj/src/upgrade').default;
|
||||
let dbVer = 0;
|
||||
const expected = scripts.length;
|
||||
while (dbVer < expected) {
|
||||
await scripts[dbVer]();
|
||||
const func = scripts[dbVer];
|
||||
dbVer++;
|
||||
await modelSystem.set('db.ver', dbVer);
|
||||
if (func.toString().includes('_FRESH_INSTALL_IGNORE')) continue;
|
||||
await func();
|
||||
}
|
||||
}
|
||||
|
||||
export async function dispose() {
|
||||
const db = require('hydrooj/src/service/db');
|
||||
await Promise.all([
|
||||
db.getClient().close(),
|
||||
db.getClient2().close(),
|
||||
db.getDb().close(),
|
||||
db.getDb2().close(),
|
||||
]);
|
||||
await db.stop();
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'hydrooj';
|
||||
import 'hydrooj/src/utils';
|
||||
import 'hydrooj/src/loader';
|
||||
import { md5, sha1 } from 'hydrooj/src/lib/crypto';
|
||||
import pwhash from 'hydrooj/src/lib/hash.hydro';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'hydrooj';
|
||||
import 'hydrooj/src/loader';
|
||||
import * as validator from 'hydrooj/src/lib/validator';
|
||||
|
||||
describe('Validator', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'hydrooj';
|
||||
import 'hydrooj/src/loader';
|
||||
import { connect, dispose } from './db';
|
||||
|
||||
const DOMAIN_ID = 'system';
|
||||
@@ -8,11 +8,11 @@ const UID = 22;
|
||||
const PNAME = 'aaa';
|
||||
|
||||
describe('Model.Problem', () => {
|
||||
let problem: typeof import('hydrooj/src/model/problem');
|
||||
let problem: typeof import('hydrooj/src/model/problem').default;
|
||||
|
||||
beforeAll(async () => {
|
||||
await connect();
|
||||
problem = require('hydrooj/src/model/problem');
|
||||
problem = require('hydrooj/src/model/problem').default;
|
||||
});
|
||||
|
||||
test('add_get', async () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'hydrooj';
|
||||
import * as utils from 'hydrooj/src/utils';
|
||||
import 'hydrooj/src/loader';
|
||||
import * as utils from 'hydrooj/dist/utils';
|
||||
|
||||
describe('Utils', () => {
|
||||
test('Array.isDiff', () => {
|
||||
|
||||
Reference in new issue
Block a user