Loopback 4 test configurations are not picked up

十年热恋 提交于 2019-12-13 16:51:17

问题


I followed Loopback4 datasources documentation and placed sample.datasource.json and sample.test.datasource.json files under src/datasources. Whenever I run npm run test my repository is injected with original datasource but not the test datasource.

My datasource configuration file sample.datasource.json is

{
  "name": "sample",
  "connector": "postgresql",
  "url": "postgres://postgres:user@localhost:5432/somedb",
  "host": "localhost",
  "port": 5432,
  "user": "postgres",
  "password": "****",
  "database": "somedb"
}

and my test configuration file sample.test.datasource.json is

{
  "name": "sample",
  "connector": "memory",
  "localStorage": "sample-test",
  "debug": true
}

Here is my repository file sample.repository.ts placed under src/repositories.

export class SampleRepository extends DefaultCrudRepository<SomeModel,string> {
  constructor(
    @inject('datasources.sample') dataSource: SomeDataSource,
  ) {
    super(SomeModel, dataSource);
  }
}

I exported NODE_ENV to "test" and tried to run npm run test.


回答1:


Hello from the LoopBack team :)

LoopBack 4 does not support environment specific configuration yet. We are discussing this feature in the GitHub issue #1464, there is also a discussion about modifying datasource configuration specifically for tests - see issue #1396.

There are workaround possible, see the following resources for inspiration:

  • https://loopback.io/doc/en/lb4/Deploying-to-IBM-Cloud.html#updating-application
  • https://itnext.io/loopback-4-database-configuration-8f085399268


来源:https://stackoverflow.com/questions/53364273/loopback-4-test-configurations-are-not-picked-up

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!