mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
workspace: use node:test to replace mocha
This commit is contained in:
1 parent
188a8c6ed0
commit
e5de4f101b
6 files changed
+27
-20
No files matched your search
@@ -1,3 +1,6 @@
|
||||
process.env.CI = true;
|
||||
const version = process.versions.node.split('.');
|
||||
version.pop();
|
||||
if (+version.join('.') < 18.8) throw new Error('Tests only available in NodeJS>=18.8');
|
||||
require('hydrooj/bin/hydrooj');
|
||||
require('./main');
|
||||
+16
-13
@@ -1,6 +1,9 @@
|
||||
import assert from 'assert';
|
||||
import { writeFileSync } from 'fs';
|
||||
import autocannon from 'autocannon';
|
||||
import { writeFileSync } from 'fs-extra';
|
||||
import {
|
||||
after, before, describe, it,
|
||||
} from 'node:test';
|
||||
import * as supertest from 'supertest';
|
||||
|
||||
const Root = {
|
||||
@@ -11,8 +14,7 @@ const Root = {
|
||||
|
||||
describe('App', () => {
|
||||
let agent: supertest.SuperAgentTest;
|
||||
before('init', function init(done) {
|
||||
this.timeout(30000);
|
||||
before((done) => {
|
||||
let timeout;
|
||||
const resolve = () => setTimeout(() => {
|
||||
clearTimeout(timeout);
|
||||
@@ -24,7 +26,7 @@ describe('App', () => {
|
||||
return send?.(data) || false;
|
||||
})(process.send);
|
||||
timeout = setTimeout(resolve, 20000);
|
||||
});
|
||||
}, { timeout: 30000 });
|
||||
|
||||
const routes = ['/', '/api', '/p', '/contest', '/homework', '/user/1', '/training'];
|
||||
routes.forEach((route) => it(`GET ${route}`, () => agent.get(route).expect(200)));
|
||||
@@ -58,10 +60,9 @@ describe('App', () => {
|
||||
|
||||
// TODO add more tests
|
||||
|
||||
const results: Record<string, autocannon.Result> = {};
|
||||
if (process.env.BENCHMARK) {
|
||||
routes.forEach((route) => it(`Performance test ${route}`, async function test() {
|
||||
this.timeout(60000);
|
||||
const results: Record<string, autocannon.Result> = {};
|
||||
routes.forEach((route) => it(`Performance test ${route}`, { timeout: 60000 }, async () => {
|
||||
await global.Hydro.model.system.set('limit.global', 99999);
|
||||
const result = await autocannon({ url: `http://localhost:8888${route}` });
|
||||
assert(result.errors === 0, `test ${route} returns errors`);
|
||||
@@ -70,12 +71,14 @@ describe('App', () => {
|
||||
}
|
||||
|
||||
after(() => {
|
||||
const metrics = Object.entries(([k, v]) => ({
|
||||
name: `Benchmark - ${k} - Req/sec`,
|
||||
unit: 'Req/sec',
|
||||
value: v.requests.average,
|
||||
}));
|
||||
writeFileSync('./benchmark.json', JSON.stringify(metrics, null, 2));
|
||||
if (process.env.BENCHMARK) {
|
||||
const metrics = Object.entries(([k, v]) => ({
|
||||
name: `Benchmark - ${k} - Req/sec`,
|
||||
unit: 'Req/sec',
|
||||
value: v.requests.average,
|
||||
}));
|
||||
writeFileSync('./benchmark.json', JSON.stringify(metrics, null, 2));
|
||||
}
|
||||
setTimeout(() => process.exit(0), 1000);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user