0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rest connectorの通信をnockでmocking

Last updated at Posted at 2019-08-24

loopback4でapiをつくってるんですが、さらに開発中のcakephp3でつくているapiを呼んでいます。
cake側のapiは開発が後回しになっているので、lb4での開発中はスタブを呼ぶことにしました。
とりあえず、お客さんにapiの仕様だけを見せないといけないので。
※swagger uiを見せる予定。

rubyのfaraday+webmockみたいなのを目指しました。

いまいちだった方法

http-caching-proxyを使う

テキストファイルにレスポンスがキャッシュされるということで無理やりコントローラ
あたりに埋め込みました。
ですが、なんかうまく動かないし、そもそもキャッシュファイルはあらかじめ用意したいですが、
ファイル名が長い暗号みたいな文字列なので、作成の仕方もわからないのでやめました。

ということでnockを使う

https://github.com/nock/nock
lb4に組み込まれている機能はあてにせずにnockを使うことにしました。

src/index.tsに埋め込んで、期待通りの事ができました。
これ、その上の階層のindex.tsでもいい気がしてきました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?