未获取环回4测试配置 [英] Loopback 4 test configurations are not picked up
问题描述
我遵循了 Loopback4数据源文档,并放置了 sample.datasource src/datasources 下的.json 和 sample.test.datasource.json 文件.每当我运行npm run test
时,我的存储库就会注入原始数据源,而不注入测试数据源.
我的数据源配置文件sample.datasource.json是
{
"name": "sample",
"connector": "postgresql",
"url": "postgres://postgres:user@localhost:5432/somedb",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "****",
"database": "somedb"
}
和我的测试配置文件sample.test.datasource.json是
{
"name": "sample",
"connector": "memory",
"localStorage": "sample-test",
"debug": true
}
这是我的存储库文件 sample.repository.ts ,位于src/repositories下.
export class SampleRepository extends DefaultCrudRepository<SomeModel,string> {
constructor(
@inject('datasources.sample') dataSource: SomeDataSource,
) {
super(SomeModel, dataSource);
}
}
我将NODE_ENV
导出到测试"并尝试运行npm run test
.
来自LoopBack团队的你好:)
LoopBack 4目前还不支持特定于环境的配置.我们正在GitHub issue#1464 中讨论此功能,还有一个有关专门针对测试修改数据源配置的讨论-请参见 issue#1396 .>
有可能的解决方法,请参见以下资源以获取灵感:
- https://loopback.io /doc/en/lb4/Deploying-to-IBM-Cloud.html#updating-application
- https://itnext.io/loopback-4-database-configuration-8f085399268
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
.
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
这篇关于未获取环回4测试配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!