From 43f6c73c8f20159d68d48ef415acdcee0ec64975 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 5 Jan 2023 22:52:37 +0800 Subject: [PATCH 1/4] refactor: upgrade tegg deps (#120) --- .autod.conf.js | 23 --------- .eslintignore | 10 ---- .eslintrc | 6 --- .github/workflows/ci.yml | 18 +++++++ .travis.yml | 21 -------- assets-with-roadhog/.autod.conf.js | 26 ---------- assets-with-roadhog/package.json | 8 +-- bin/autod.js | 20 -------- hello-tegg/.eslintignore | 1 + hello-tegg/.eslintrc | 1 + hello-tegg/.gitignore | 2 + hello-tegg/app/controller/HelloController.ts | 4 +- hello-tegg/package.json | 51 ++++++++++---------- hello-tegg/tsconfig.json | 5 +- package.json | 23 +++------ 15 files changed, 61 insertions(+), 158 deletions(-) delete mode 100644 .autod.conf.js delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml delete mode 100644 assets-with-roadhog/.autod.conf.js delete mode 100644 bin/autod.js create mode 100644 hello-tegg/.eslintignore diff --git a/.autod.conf.js b/.autod.conf.js deleted file mode 100644 index 5b635ec1..00000000 --- a/.autod.conf.js +++ /dev/null @@ -1,23 +0,0 @@ -'ues strict'; - -module.exports = { - write: true, - plugin: 'autod-egg', - prefix: '^', - devprefix: '^', - exclude: [ - 'test/fixtures', - 'examples', - 'docs', - 'run', - ], - devdep: [ - 'egg-bin', - ], - dep: [ - 'egg', - ], - semver: [ - ], - test: 'scripts', -}; diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 02b0cd13..00000000 --- a/.eslintignore +++ /dev/null @@ -1,10 +0,0 @@ -test/fixtures -**/app/public -node_modules -logs -run -coverage -hackernews-async-ts/**/*.js -assets-with-roadhog/app/assets/**/*.js -**/app/assets -zookeeper-3.4.6/ diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 5b4124c7..00000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "egg", - "env": { - "jest": true - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..18a0657a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI + +on: + push: + branches: [ master ] + + pull_request: + branches: [ master ] + + workflow_dispatch: {} + +jobs: + Job: + name: Node.js + uses: artusjs/github-actions/.github/workflows/node-test.yml@master + with: + os: 'ubuntu-latest' + version: '14, 16, 18' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0cef5f90..00000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -sudo: false -language: node_js -node_js: - - '10' - - '12' -services: - - mysql -before_install: - - npm i npminstall -g - - 'wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz' - - 'tar xf zookeeper-3.4.6.tar.gz' - - 'mv zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg' - - './zookeeper-3.4.6/bin/zkServer.sh start' - - mysql -e 'CREATE DATABASE IF NOT EXISTS `egg-sequelize-example-unittest`;' - - mysql -e 'CREATE DATABASE IF NOT EXISTS `egg-sequelize-ts-unittest`;' -install: - - npminstall -script: - - npm run ci -after_script: - - npminstall codecov && codecov diff --git a/assets-with-roadhog/.autod.conf.js b/assets-with-roadhog/.autod.conf.js deleted file mode 100644 index 5da0d96b..00000000 --- a/assets-with-roadhog/.autod.conf.js +++ /dev/null @@ -1,26 +0,0 @@ -'ues strict'; - -module.exports = { - write: true, - plugin: 'autod-egg', - prefix: '^', - devprefix: '^', - exclude: [ - 'test/fixtures', - 'examples', - 'docs', - 'run', - ], - devdep: [ - 'egg-bin', - 'eslint', - 'eslint-config-egg', - ], - dep: [ - 'egg', - 'egg-scripts', - ], - semver: [ - ], - test: 'scripts', -}; diff --git a/assets-with-roadhog/package.json b/assets-with-roadhog/package.json index 8327f02f..79fbc25f 100644 --- a/assets-with-roadhog/package.json +++ b/assets-with-roadhog/package.json @@ -16,8 +16,6 @@ "react": "^16.2.0" }, "devDependencies": { - "autod": "^3.0.1", - "autod-egg": "^1.0.0", "babel-plugin-dva-hmr": "^0.4.0", "babel-plugin-import": "^1.1.0", "egg-bin": "^4.3.7", @@ -25,8 +23,7 @@ "eslint": "^4.18.2", "eslint-config-egg": "^7.0.0", "redbox-react": "^1.5.0", - "roadhog": "^2.3.0", - "webstorm-disable-index": "^1.2.0" + "roadhog": "^2.3.0" }, "engines": { "node": ">=8.9.0" @@ -40,8 +37,7 @@ "test": "egg-bin test", "cov": "egg-bin cov", "lint": "eslint .", - "ci": "npm run lint && npm run cov", - "autod": "autod" + "ci": "npm run lint && npm run cov" }, "ci": { "version": "8" diff --git a/bin/autod.js b/bin/autod.js deleted file mode 100644 index 6f019a8b..00000000 --- a/bin/autod.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -const Command = require('./base'); - -class Autod extends Command { - - async run() { - const dirs = await this.getExamples(); - for (const dir of dirs) { - try { - await this.runscript(`autod -p ${dir}`); - } catch (_) { - // nothing - } - } - } - -} - -module.exports = Autod; diff --git a/hello-tegg/.eslintignore b/hello-tegg/.eslintignore new file mode 100644 index 00000000..a2fafbf0 --- /dev/null +++ b/hello-tegg/.eslintignore @@ -0,0 +1 @@ +typings/ diff --git a/hello-tegg/.eslintrc b/hello-tegg/.eslintrc index 114c3441..e5c25c0f 100644 --- a/hello-tegg/.eslintrc +++ b/hello-tegg/.eslintrc @@ -1,3 +1,4 @@ { + "root": true, "extends": "eslint-config-egg/typescript" } diff --git a/hello-tegg/.gitignore b/hello-tegg/.gitignore index 2b2b3e2c..2ba77726 100644 --- a/hello-tegg/.gitignore +++ b/hello-tegg/.gitignore @@ -17,3 +17,5 @@ config/**/*.js app/**/*.map test/**/*.map config/**/*.map +*.d.ts +*.tsbuildinfo diff --git a/hello-tegg/app/controller/HelloController.ts b/hello-tegg/app/controller/HelloController.ts index e2e27ffe..963088ff 100644 --- a/hello-tegg/app/controller/HelloController.ts +++ b/hello-tegg/app/controller/HelloController.ts @@ -9,8 +9,8 @@ import { Inject, } from '@eggjs/tegg'; import { EggLogger } from 'egg'; -import { traceMethod } from '../middleware/trace_method'; -import { HelloService } from '../biz/HelloService'; +import { traceMethod } from 'app/middleware/trace_method'; +import { HelloService } from 'app/biz/HelloService'; @HTTPController() @Middleware(traceMethod) diff --git a/hello-tegg/package.json b/hello-tegg/package.json index 7ff8bd66..28ca1383 100644 --- a/hello-tegg/package.json +++ b/hello-tegg/package.json @@ -1,43 +1,42 @@ { "name": "hello-tegg", - "version": "1.0.0", - "description": "", - "main": "index.js", + "private": true, + "description": "tegg application example", "scripts": { "start": "egg-scripts start", - "dev": "egg-bin dev -r egg-ts-helper/register", - "debug": "egg-bin debug -r egg-ts-helper/register", - "test-local": "egg-bin test -r egg-ts-helper/register", + "stop": "egg-scripts stop", + "dev": "ets && egg-bin dev", + "debug": "ets && egg-bin debug", + "test-local": "ets && egg-bin test", "test": "npm run lint -- --fix && npm run test-local", - "cov": "egg-bin cov -r egg-ts-helper/register", + "cov": "ets && egg-bin cov", "tsc": "tsc -p tsconfig.json", "ci": "npm run lint && npm run cov && npm run tsc", - "autod": "autod", "lint": "eslint .", "clean": "tsc -b --clean" }, "egg": { "typescript": true }, - "author": "", - "license": "ISC", + "license": "MIT", "dependencies": { - "@eggjs/tegg": "^0.1.1", - "@eggjs/tegg-config": "^0.1.0", - "@eggjs/tegg-controller-plugin": "^0.1.1", - "@eggjs/tegg-eventbus-plugin": "^0.1.1", - "@eggjs/tegg-plugin": "^0.1.1", - "egg": "^2.29.4" + "@eggjs/tegg": "^1.6.4", + "@eggjs/tegg-config": "^1.3.3", + "@eggjs/tegg-controller-plugin": "^1.7.5", + "@eggjs/tegg-eventbus-plugin": "^1.5.5", + "@eggjs/tegg-plugin": "^1.5.5", + "egg": "^3.9.1", + "egg-scripts": "^2.17.0" }, "devDependencies": { - "@eggjs/tsconfig": "^1.0.0", - "@types/mocha": "^8.2.3", - "@types/node": "^16.4.0", - "egg-bin": "^4.16.4", - "egg-mock": "^3.26.0", - "egg-ts-helper": "^1.25.9", - "eslint": "^7.31.0", - "eslint-config-egg": "^9.0.0", - "typescript": "^4.3.5" - } + "@eggjs/tsconfig": "^1.2.0", + "@types/mocha": "^10.0.1", + "@types/node": "^16.18.10", + "egg-bin": "^5.10.0", + "egg-mock": "^5.4.0", + "eslint": "^8.30.0", + "eslint-config-egg": "^12.1.0", + "typescript": "^4.9.4" + }, + "repository": "git@github.com:eggjs/examples.git" } diff --git a/hello-tegg/tsconfig.json b/hello-tegg/tsconfig.json index 376b9024..65fddc82 100644 --- a/hello-tegg/tsconfig.json +++ b/hello-tegg/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "@eggjs/tsconfig" + "extends": "@eggjs/tsconfig", + "compilerOptions": { + "baseUrl": "./" + } } diff --git a/package.json b/package.json index 3aef2c1a..aa3954a9 100644 --- a/package.json +++ b/package.json @@ -7,22 +7,18 @@ "egg" ], "devDependencies": { - "autod": "^2.7.1", - "autod-egg": "^1.0.0", "chalk": "^1.1.3", - "eslint": "^5.6.1", - "eslint-config-egg": "^7.1.0", - "npminstall": "3", - "semver": "^5.3.0", "common-bin": "^2.7.1", - "globby": "^6.1.0" + "globby": "^6.1.0", + "npminstall": "^6.6.2", + "runscript": "^1.5.3", + "semver": "^5.3.0" }, "scripts": { - "lint": "eslint .", + "lint": "echo 'ignore'", "test": "./example.js test", "test-cn": "./example.js test -c", "ci": "npm run lint && npm test", - "autod": "./example.js autod", "list": "./example.js list" }, "homepage": "https://github.com/eggjs/examples", @@ -34,14 +30,7 @@ "url": "https://github.com/eggjs/egg/issues" }, "engines": { - "node": ">= 8.0.0" - }, - "ci": { - "version": "8", - "license": { - "year": 2017 - }, - "afterScript": false + "node": ">= 14.17.0" }, "license": "MIT", "private": true From 598a191b6f5f11f393182b079f328f6933459ae6 Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Wed, 22 Feb 2023 13:47:50 +0800 Subject: [PATCH 2/4] chore: tegg v3 (#125) --- hello-tegg/app/biz/HelloService.ts | 4 ++-- hello-tegg/package.json | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hello-tegg/app/biz/HelloService.ts b/hello-tegg/app/biz/HelloService.ts index ca370fc6..bb53b964 100644 --- a/hello-tegg/app/biz/HelloService.ts +++ b/hello-tegg/app/biz/HelloService.ts @@ -1,9 +1,9 @@ import { - ContextProto, AccessLevel, + SingletonProto, } from '@eggjs/tegg'; -@ContextProto({ +@SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) export class HelloService { diff --git a/hello-tegg/package.json b/hello-tegg/package.json index 28ca1383..77890e7b 100644 --- a/hello-tegg/package.json +++ b/hello-tegg/package.json @@ -5,11 +5,11 @@ "scripts": { "start": "egg-scripts start", "stop": "egg-scripts stop", - "dev": "ets && egg-bin dev", - "debug": "ets && egg-bin debug", - "test-local": "ets && egg-bin test", + "dev": "egg-bin dev", + "debug": "egg-bin debug", + "test-local": "egg-bin test", "test": "npm run lint -- --fix && npm run test-local", - "cov": "ets && egg-bin cov", + "cov": "egg-bin cov", "tsc": "tsc -p tsconfig.json", "ci": "npm run lint && npm run cov && npm run tsc", "lint": "eslint .", @@ -20,19 +20,18 @@ }, "license": "MIT", "dependencies": { - "@eggjs/tegg": "^1.6.4", - "@eggjs/tegg-config": "^1.3.3", - "@eggjs/tegg-controller-plugin": "^1.7.5", - "@eggjs/tegg-eventbus-plugin": "^1.5.5", - "@eggjs/tegg-plugin": "^1.5.5", + "@eggjs/tegg": "^3.2.1", + "@eggjs/tegg-controller-plugin": "^3.2.1", + "@eggjs/tegg-plugin": "^3.2.1", + "@eggjs/tsconfig": "^1.2.0", + "@eggjs/tegg-config": "^3.1.0", "egg": "^3.9.1", "egg-scripts": "^2.17.0" }, "devDependencies": { - "@eggjs/tsconfig": "^1.2.0", "@types/mocha": "^10.0.1", "@types/node": "^16.18.10", - "egg-bin": "^5.10.0", + "egg-bin": "^6.0.0", "egg-mock": "^5.4.0", "eslint": "^8.30.0", "eslint-config-egg": "^12.1.0", From f94710fe967559aabbe6d37de976c1917c94b935 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 30 Jul 2023 22:19:44 +0800 Subject: [PATCH 3/4] test: use bootstrap to start tests (#97) --- .../__tests__/controller/home.test.js | 12 ++++++++++++ unittest-jest/__tests__/index.test.js | 18 +----------------- 2 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 unittest-jest/__tests__/controller/home.test.js diff --git a/unittest-jest/__tests__/controller/home.test.js b/unittest-jest/__tests__/controller/home.test.js new file mode 100644 index 00000000..18211664 --- /dev/null +++ b/unittest-jest/__tests__/controller/home.test.js @@ -0,0 +1,12 @@ +'use strict'; + +const { app } = require('egg-mock/bootstrap'); + +describe('__tests__/controller/home.test.js', () => { + it('should status 200 and get the body', () => { + return app.httpRequest() + .get('/') + .expect(200) + .expect('hello world'); + }); +}); diff --git a/unittest-jest/__tests__/index.test.js b/unittest-jest/__tests__/index.test.js index d208c3b9..5a634042 100644 --- a/unittest-jest/__tests__/index.test.js +++ b/unittest-jest/__tests__/index.test.js @@ -1,25 +1,9 @@ 'use strict'; -const mock = require('egg-mock'); +const { app } = require('egg-mock/bootstrap'); describe('__tests__/index.test.js', () => { - let app; - beforeAll(() => { - app = mock.app(); - return app.ready(); - }); - - afterEach(mock.restore); - afterAll(() => app.close()); - it('should app exist', () => { expect(app.test).toBe('123'); }); - - it('should status 200 and get the body', () => { - return app.httpRequest() - .get('/') - .expect(200) - .expect('hello world'); - }); }); From 5ea83ef36dede99ae057adfb6972c5086d8d2e4c Mon Sep 17 00:00:00 2001 From: placeintime Date: Mon, 25 Dec 2023 18:51:22 +0800 Subject: [PATCH 4/4] fix-sequelize-ts: SequelizeDatabaseError: Column 'id' in field list is ambiguous (#116) --- sequelize-ts/app/model/post.ts | 4 ++-- sequelize-ts/app/model/user.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sequelize-ts/app/model/post.ts b/sequelize-ts/app/model/post.ts index 4a1e9620..0b8fb663 100644 --- a/sequelize-ts/app/model/post.ts +++ b/sequelize-ts/app/model/post.ts @@ -5,7 +5,7 @@ import { Application } from 'egg'; export default function(app: Application) { const { STRING, INTEGER, DATE } = app.Sequelize; - const Post = app.model.define('post', { + const Model = app.model.define('post', { id: { type: INTEGER, primaryKey: true, @@ -18,7 +18,7 @@ export default function(app: Application) { updated_at: DATE(6), }); - return class extends Post { + return class Post extends Model { static associate() { app.model.Post.belongsTo(app.model.User, { as: 'user', foreignKey: 'user_id' }); } diff --git a/sequelize-ts/app/model/user.ts b/sequelize-ts/app/model/user.ts index 6f25412d..cee907ce 100644 --- a/sequelize-ts/app/model/user.ts +++ b/sequelize-ts/app/model/user.ts @@ -4,7 +4,7 @@ import { Application } from 'egg'; export default function(app: Application) { const { STRING, INTEGER, DATE } = app.Sequelize; - const User = app.model.define('user', { + const Model = app.model.define('user', { id: { type: INTEGER, primaryKey: true, @@ -16,7 +16,7 @@ export default function(app: Application) { updated_at: DATE(6), }); - return class extends User { + return class User extends Model { static associate() { app.model.User.hasMany(app.model.Post, { as: 'posts' }); }