mirror of
https://github.com/certd/certd.git
synced 2026-05-16 13:17:29 +08:00
chore: 补充单元测试
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
"build": "npm run before-build && tsc --skipLibCheck",
|
||||
"dev-build": "npm run build",
|
||||
"test": "midway-bin test --ts -V",
|
||||
"test:unit": "mocha --no-config --node-option no-warnings --node-option loader=ts-node/esm \"src/**/*.test.ts\"",
|
||||
"test1": "midway-bin test --ts -V -f test/blank.test.ts -t 'hash-check'",
|
||||
"cov": "midway-bin cov --ts",
|
||||
"lint": "mwts check",
|
||||
@@ -52,14 +53,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "^18",
|
||||
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
||||
"@typescript-eslint/parser": "^8.26.1",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"mocha": "^10.2.0",
|
||||
"prettier": "^2.8.8",
|
||||
"rimraf": "^5.0.5",
|
||||
"ts-node": "^10.9.2",
|
||||
"tslib": "^2.8.1",
|
||||
"typeorm": "^0.3.11",
|
||||
"typescript": "^5.4.2"
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/// <reference types="mocha" />
|
||||
/// <reference types="node" />
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { Constants } from "./constants.js";
|
||||
import { ParamException } from "./exception/param-exception.js";
|
||||
import { Result } from "./result.js";
|
||||
|
||||
describe("lib-server basic helpers", () => {
|
||||
it("builds success and error results", () => {
|
||||
const success = Result.success("ok", { id: 1 });
|
||||
assert.ok(success instanceof Result);
|
||||
assert.equal(success.code, 0);
|
||||
assert.equal(success.message, "ok");
|
||||
assert.deepEqual(success.data, { id: 1 });
|
||||
|
||||
const error = Result.error(400, "bad request");
|
||||
assert.ok(error instanceof Result);
|
||||
assert.equal(error.code, 400);
|
||||
assert.equal(error.message, "bad request");
|
||||
assert.equal(error.data, undefined);
|
||||
});
|
||||
|
||||
it("uses default param exception metadata", () => {
|
||||
const error = new ParamException(undefined);
|
||||
|
||||
assert.equal(error.name, "ParamException");
|
||||
assert.equal(error.code, Constants.res.param.code);
|
||||
assert.equal(error.message, Constants.res.param.message);
|
||||
});
|
||||
});
|
||||
@@ -8,7 +8,7 @@
|
||||
"isolatedModules": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"inlineSourceMap":false,
|
||||
"inlineSourceMap": false,
|
||||
"sourceMap": false,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
@@ -17,25 +17,15 @@
|
||||
"pretty": true,
|
||||
"declaration": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"typeRoots": [ "./typings", "./node_modules/@types"],
|
||||
"typeRoots": ["./typings", "./node_modules/@types"],
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"composite": false,
|
||||
"useDefineForClassFields": true,
|
||||
"strict": false,
|
||||
"resolveJsonModule": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"lib": ["ESNext", "DOM"]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.d.ts",
|
||||
"src/**/*.json"
|
||||
],
|
||||
"exclude": [
|
||||
"*.js",
|
||||
"*.ts",
|
||||
"dist",
|
||||
"node_modules",
|
||||
"test"
|
||||
],
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.json"],
|
||||
"exclude": ["*.js", "*.ts", "dist", "node_modules", "src/**/*.test.ts", "test"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user