From 67321cd46cf08ef015df997cacf2ab84fb6be626 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 29 Dec 2024 17:23:59 +0800 Subject: [PATCH] test on tegg v3 --- bin/test.sh | 16 +++++++++++----- hello-tegg/.gitignore | 1 + hello-tegg/app/middleware/trace_method.ts | 2 +- hello-tegg/config/config.default.ts | 5 +++-- hello-tegg/config/plugin.ts | 5 +++-- hello-tegg/package.json | 10 ++++++---- hello-tegg/test/biz/HelloService.test.ts | 9 +++++---- .../test/controller/HelloController.test.ts | 4 ++-- hello-tegg/tsconfig.json | 13 +++++++++++-- 9 files changed, 43 insertions(+), 22 deletions(-) diff --git a/bin/test.sh b/bin/test.sh index ec4c419..d14ce22 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -1,8 +1,14 @@ #!/usr/bin/env bash -cd helloworld -rm -rf node_modules package-lock.json -npm install --registry=https://registry.npmmirror.com -npm run ci -cd helloworld +test() { + echo "Test $1" + cd $1 + pwd + rm -rf node_modules package-lock.json + npm install --registry=https://registry.npmmirror.com + npm run ci + cd .. +} +test helloworld +test hello-tegg diff --git a/hello-tegg/.gitignore b/hello-tegg/.gitignore index 2ba7772..b2eeab3 100644 --- a/hello-tegg/.gitignore +++ b/hello-tegg/.gitignore @@ -19,3 +19,4 @@ test/**/*.map config/**/*.map *.d.ts *.tsbuildinfo +.egg/ diff --git a/hello-tegg/app/middleware/trace_method.ts b/hello-tegg/app/middleware/trace_method.ts index 6e49a2c..b5dd800 100644 --- a/hello-tegg/app/middleware/trace_method.ts +++ b/hello-tegg/app/middleware/trace_method.ts @@ -2,5 +2,5 @@ import { EggContext, Next } from '@eggjs/tegg'; export async function traceMethod(ctx: EggContext, next: Next) { await next(); - ctx.body.data.message += ` (${ctx.method})`; + (ctx.body as any).data.message += ` (${ctx.method})`; } diff --git a/hello-tegg/config/config.default.ts b/hello-tegg/config/config.default.ts index 208980f..c9f711d 100644 --- a/hello-tegg/config/config.default.ts +++ b/hello-tegg/config/config.default.ts @@ -1,7 +1,8 @@ -import { EggAppConfig, PowerPartial } from 'egg'; +import { EggAppConfig } from 'egg'; +// import { EggAppConfig, PowerPartial } from 'egg'; export default (appInfo: EggAppConfig) => { - const config = {} as PowerPartial; + const config = {} as EggAppConfig; // override config from framework / plugin config.keys = appInfo.name + '123456'; diff --git a/hello-tegg/config/plugin.ts b/hello-tegg/config/plugin.ts index f7493ab..b0aede1 100644 --- a/hello-tegg/config/plugin.ts +++ b/hello-tegg/config/plugin.ts @@ -1,6 +1,7 @@ -import { EggPlugin } from 'egg'; +// import { EggPlugin } from 'egg'; -const plugin: EggPlugin = { +// const plugin: EggPlugin = { +const plugin = { tegg: { enable: true, package: '@eggjs/tegg-plugin', diff --git a/hello-tegg/package.json b/hello-tegg/package.json index 26180bd..2d77b5a 100644 --- a/hello-tegg/package.json +++ b/hello-tegg/package.json @@ -7,10 +7,12 @@ "stop": "egg-scripts stop", "dev": "egg-bin dev", "test-local": "egg-bin test", - "test": "npm run lint -- --fix && npm run test-local", - "cov": "egg-bin cov", + "pretest": "npm run clean && npm run lint -- --fix", + "test": "egg-bin test", "tsc": "tsc -p tsconfig.json", - "ci": "npm run lint && npm run cov && npm run tsc", + "preci": "npm run lint", + "ci": "egg-bin cov", + "postci": "npm run tsc && npm run clean", "lint": "eslint .", "clean": "tsc -b --clean" }, @@ -30,7 +32,7 @@ "devDependencies": { "@types/mocha": "10", "@types/node": "22", - "@egg/bin": "7", + "@eggjs/bin": "7", "@eggjs/mock": "6", "eslint": "8", "eslint-config-egg": "14", diff --git a/hello-tegg/test/biz/HelloService.test.ts b/hello-tegg/test/biz/HelloService.test.ts index 6d77a41..706bfce 100644 --- a/hello-tegg/test/biz/HelloService.test.ts +++ b/hello-tegg/test/biz/HelloService.test.ts @@ -1,10 +1,11 @@ -import { Context } from 'egg'; -import assert from 'assert'; -import { app } from 'egg-mock/bootstrap'; +import { strict as assert } from 'node:assert'; +// import { EggContext } from 'egg'; +import { app } from '@eggjs/mock/bootstrap'; import { HelloService } from '../../app/biz/HelloService'; describe('test/biz/HelloService.test.ts', () => { - let ctx: Context; + let ctx: any; + // let ctx: EggContext; let helloService: HelloService; beforeEach(async () => { diff --git a/hello-tegg/test/controller/HelloController.test.ts b/hello-tegg/test/controller/HelloController.test.ts index d627e18..8ea27c7 100644 --- a/hello-tegg/test/controller/HelloController.test.ts +++ b/hello-tegg/test/controller/HelloController.test.ts @@ -1,5 +1,5 @@ -import { app } from 'egg-mock/bootstrap'; -import assert from 'assert'; +import { strict as assert } from 'node:assert'; +import { app } from '@eggjs/mock/bootstrap'; describe('test/controller/HelloController.test.ts', () => { it('should work', async () => { diff --git a/hello-tegg/tsconfig.json b/hello-tegg/tsconfig.json index 65fddc8..865b55a 100644 --- a/hello-tegg/tsconfig.json +++ b/hello-tegg/tsconfig.json @@ -1,6 +1,15 @@ { "extends": "@eggjs/tsconfig", "compilerOptions": { - "baseUrl": "./" - } + "baseUrl": ".", + "strict": true, + "noImplicitAny": true, + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "declaration": false + }, + "exclude": [ + "test" + ] }