mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17: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
@@ -20,7 +20,7 @@ jobs:
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
node-version: 18.x
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
|
||||
+2
-4
@@ -15,8 +15,8 @@
|
||||
"build:ui:dev": "node packages/ui-default/build --gulp && node --trace-deprecation packages/ui-default/build --dev",
|
||||
"build:ui:production": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node packages/ui-default/build --gulp && node packages/ui-default/build --production",
|
||||
"build:ui:production:webpack": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node packages/ui-default/build --production",
|
||||
"test": "mocha",
|
||||
"benchmark": "cross-env BENCHMARK=true mocha",
|
||||
"test": "node test/entry.js",
|
||||
"benchmark": "cross-env BENCHMARK=true node test/entry.js",
|
||||
"lint": "eslint packages plugins --ext ts --fix",
|
||||
"lint:ci": "eslint packages plugins --ext ts",
|
||||
"lint:ui": "yarn workspace @hydrooj/ui-default lint --ext .js,.ts,.jsx,.tsx . --fix",
|
||||
@@ -30,7 +30,6 @@
|
||||
"devDependencies": {
|
||||
"@types/autocannon": "^7.9.0",
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/semver": "^7.3.13",
|
||||
"@types/supertest": "^2.0.12",
|
||||
@@ -60,7 +59,6 @@
|
||||
"globby": "13.1.3",
|
||||
"latest-version": "7.0.0",
|
||||
"mini-css-extract-plugin": "^2.7.2",
|
||||
"mocha": "^10.2.0",
|
||||
"monaco-editor-webpack-plugin": "^7.0.1",
|
||||
"mongodb": "^3.7.3",
|
||||
"mongodb-memory-server": "^8.10.2",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ESNext",
|
||||
"baseUrl": ".",
|
||||
"module": "ESNext",
|
||||
"lib": [
|
||||
"ES2020"
|
||||
],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable logical-assignment-operators */
|
||||
const map = {};
|
||||
require('source-map-support').install({
|
||||
handleUncaughtExceptions: false,
|
||||
@@ -17,7 +18,8 @@ const vm = require('vm');
|
||||
const fs = require('fs-extra');
|
||||
const esbuild = require('esbuild');
|
||||
|
||||
process.env.NODE_APP_INSTANCE ||= '0';
|
||||
// Node14 doesn't support ||= syntax
|
||||
process.env.NODE_APP_INSTANCE = process.env.NODE_APP_INSTANCE || '0';
|
||||
const major = +process.version.split('.')[0].split('v')[1];
|
||||
const minor = +process.version.split('.')[1];
|
||||
|
||||
@@ -86,4 +88,4 @@ if (argv.options.debug) {
|
||||
console.log('Debug mode enabled');
|
||||
process.env.NODE_ENV = 'development';
|
||||
process.env.DEV = 'on';
|
||||
} else process.env.NODE_ENV ||= 'production';
|
||||
} else process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
||||
@@ -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