Coder Social home page Coder Social logo

egg-typeorm's Introduction

Hi, I am hackycy! 👋

Want to be a full stack developer

  • 😄 Welcome to visit my open source projects.

🛠  Tech Stack

JavaScript TypeScript Vue Node.js Git Docker

🤝🏻  Contact with Me

Email

egg-typeorm's People

Contributors

hackycy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

egg-typeorm's Issues

建议 config 文件除了yaml, 也支持 json

egg 程序运行时必须要配置 config.typeorm
项目中使用 typeorm 迁移时, 又必须配置 ormconfig.yaml
这两个重复了, 建议同时支持 ormconfig.json, 这样方便直接导入到 config.typeorm 中使用

this.ctx 上并没有repo(运行时)

declare module 'egg' {
interface Context {
entity: {
AdminInfo: typeof EntityAdminInfo
}
repo: {
AdminInfo: Repository
}
}
}

这是自动生成的,代码在VS code中,没有任何错误,正常启动后,连接数据库正常。但是在service中,this.ctx 上没有 repo

好像ci无法跑过,求指教

按照文档配好之后,可以在dev环境下正常启动,但是在跑ci的时候会报错导致跑不过。
报错如下:

2021-08-12 15:36:53,219 ERROR 73 nodejs.Error: please config typeorm in config file
  1) "before all" hook in "{root}"
    at new AppBootHook (/github/workspace/node_modules/@hackycy/egg-typeorm/app.js:13:13)

    at /github/workspace/node_modules/egg-core/lib/lifecycle.js:102:45
    at Array.map (<anonymous>)
    at Lifecycle.init (/github/workspace/node_modules/egg-core/lib/lifecycle.js:102:36)
    at AppWorkerLoader.[Loader#loadBootHook] (/github/workspace/node_modules/egg-core/lib/loader/mixin/custom.js:74:20)
    at AppWorkerLoader.loadCustomApp (/github/workspace/node_modules/egg-core/lib/loader/mixin/custom.js:36:25)
    at AppWorkerLoader.load (/github/workspace/node_modules/egg/lib/loader/app_worker_loader.js:35:10)
    at new Application (/github/workspace/node_modules/egg/lib/application.js:66:19)
    at new MessengerApplication (/github/workspace/node_modules/egg-mock/lib/app.js:256:7)
    at MockApplication.[init] (/github/workspace/node_modules/egg-mock/lib/app.js:90:29)
    at Generator.next (<anonymous>)
    at onFulfilled (/github/workspace/node_modules/co/index.js:65:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

pid: 73
hostname: f856c6ed2e3c

  0 passing (2s)
  1 failing

  1) "before all" hook in "{root}":
     Error: please config typeorm in config file
      at new AppBootHook (node_modules/@hackycy/egg-typeorm/app.js:13:13)
      at /github/workspace/node_modules/egg-core/lib/lifecycle.js:102:45
      at Array.map (<anonymous>)
      at Lifecycle.init (node_modules/egg-core/lib/lifecycle.js:102:36)
      at AppWorkerLoader.[Loader#loadBootHook] (node_modules/egg-core/lib/loader/mixin/custom.js:74:20)
      at AppWorkerLoader.loadCustomApp (node_modules/egg-core/lib/loader/mixin/custom.js:36:25)
      at AppWorkerLoader.load (node_modules/egg/lib/loader/app_worker_loader.js:35:10)
      at new Application (node_modules/egg/lib/application.js:66:19)
      at new MessengerApplication (node_modules/egg-mock/lib/app.js:256:7)
      at MockApplication.[init] (node_modules/egg-mock/lib/app.js:90:29)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      [use `--full-trace` to display the full stack trace]

我没有ignore掉config文件,所以说跑github action插件启动的时候config应该是有值的,但还是报错
本机跑ci也会这样...求指教

请问下单元测试测试 service怎么写的?

如标题所示,下面是一个简单的代码展示

依赖如下:

"@hackycy/egg-typeorm": "^0.3.8",
"egg": "^2.6.1",
"egg-scripts": "^2.6.0",
"mysql2": "^2.2.5"

"egg-bin": "^4.11.0",

entity

@Entity('sys_app_config')
class SysAppConfig  {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  appName: string;

  @Column({ nullable: true })
  appIcon: string;

  @Column()
  appStatus: number;

  @Column({ nullable: true })
  remark: string;
}

service

import { Service } from 'egg';

export default class SysAppConfigService extends Service {

  async save(appConfig) {
    await this.ctx.repo.SysAppConfig.save(appConfig);
  }
}

service-test

import { app, assert } from 'egg-mock/bootstrap';

describe('test/app/service/SysAppConfig.test.js', () => {

  // afterEach(mock.restore);

  it('SysAppConfig create', async () => {
    const ctx = app.mockContext();
    // console.log('ctx :>> ', ctx);
    const result = await ctx.service.sysAppConfig.save({ appName: 'test', appStatus: 1 });
    assert(result);
  });
});

#运行结果

yarn run v1.22.5
$ egg-bin test


  test/app/service/SysAppConfig.test.js
    1) SysAppConfig create


  0 passing (555ms)
  1 failing

  1) test/app/service/SysAppConfig.test.js
       SysAppConfig create:
     TypeError: Cannot read property 'save' of undefined
      at SysAppConfigService.save (app/service/sysAppConfig.ts:6:38)
      at Context.<anonymous> (test/app/service/sysAppConfig.test.ts:10:51)
      at processImmediate (internal/timers.js:456:21)
      [use `--full-trace` to display the full stack trace]

请大佬告知!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.