-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BDD test #80
Add BDD test #80
Conversation
I've added integration tests, could you please review them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I commented two points.
@@ -9,7 +9,7 @@ | |||
"build": "tsc -p .", | |||
"watch": "tsc -w", | |||
"lint": "eslint --fix .", | |||
"test": "mocha -r ts-node/register test/*.ts", | |||
"test": "npm run build && mocha -r ts-node/register test/*.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ts-node
command to test CLI of typescript directly instead of building before every test?
There is a script command
in package.json as below.
Line 14 in c586c70
"command": "./node_modules/.bin/ts-node ./src/cli" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, it requires to change to ./node_modules/.bin/ts-node ./src/cli.ts
in package.json
src/cli/serve.ts
Outdated
@@ -17,10 +17,12 @@ program | |||
'--mapbox-access-token [mapboxAccessToken]', | |||
'Access Token for the Mapbox', | |||
) | |||
.option('--headless', 'serve your map without opening a browser') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the similar name of option with web pack?
Webpack has --open
and --no-open
option to avoid opening in browser. I think headless
is not intuitive name for users.
Thank you! I changed the option name to I also tried If there is any other advantage to using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naogify テストするたびに毎回ビルドしてdist以下を作らないといけないというのは微妙ですが、コマンドラインのテストをするという方が重要なので、今のままで良いです。
ちなみに私の環境で今の状態でテストをした場合、CLIのテスト部分でタイムアウトしてしまいます(ts-nodeを使っていなくても)。
src/cli/serve.ts
Outdated
@@ -17,12 +17,12 @@ program | |||
'--mapbox-access-token [mapboxAccessToken]', | |||
'Access Token for the Mapbox', | |||
) | |||
.option('--headless', 'serve your map without opening a browser') | |||
.option('--no-open', 'serve your map without opening a browser') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--no-open
というオプション名なのに、実際の変数名や挙動はopen
と正反対のものになっています。個人的には--open
というオプションをつけたらブラウザを起動するという動きにした方がわかりやすい気がします。デフォルトではブラウザは起動しない方が良いかと。Webpackでも他のツールでも、デフォルトではブラウザを起動しないというのが普通な気がするので特に違和感ないと思います。
--no-open
というオプション名を使うのであれば、それに合わせた変数名と実装に修正をお願いします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
フィードバックありがとうございます。
--no-openというオプション名なのに、実際の変数名や挙動はopenと正反対のものになっています。
こちらは commander js の仕様がそうなっているので、そうしています。
https://github.com/tj/commander.js/#other-option-types-negatable-boolean-and-booleanvalue
デフォルトではブラウザは起動しない方が良いかと。Webpackでも他のツールでも、デフォルトではブラウザを起動しないというのが普通な気がするので特に違和感ないと思います。
スタイルの変更をブラウザでプレビューする以外の用途で、charites serve
を実行するユースケースは思いつかないので、大半のユーザーにとってはデフォルトでブラウザを開く方が親切かと思うのですがどうでしょうか?
それと Webpackや他のツールでのデフォルトがブラウザを起動しないから、charites のデフォルトもそうすると言うのは理由になり得にくいと思いました。ツールごとにユースケースが異なるのでその目的に合わせて考える方が良いと思います。
こちらタイムアウトの時間を 10秒に設定しました。五十嵐さんの環境でタイムアウトしないかご確認お願いしてもよろしいでしょうか? |
@naogify $node -v
v16.13.0
$npm -v
8.1.0 $npm test
> @unvt/charites@0.1.2 test
> npm run build && mocha -r ts-node/register test/*.ts --timeout 10000
> @unvt/charites@0.1.2 build
> tsc -p .
Test for the `build-sprite.ts`.
✓ should create icon's json/png at specified path and name
Test for the `build.ts`.
✓ Should convert `data/style.yml` to JSON.
✓ Should minify `data/style.yml` to JSON.
✓ Should build command replace sprite url with the option `--sprite-url`.
✓ Should build icons with the option `--sprite-url`. Icon file name is set by spriteUrl
✓ Use sprite name that specified in style.json with no --sprite-url option
✓ Should not create sprite when input directory is not exist.
Test for the `charites build`
✓ charites build style.yml (837ms)
✓ charites build style.yml custom.json (925ms)
✓ charites build style.yml --compact-output (1121ms)
✓ charites build style.yml style.json --sprite-url http://localhost:8080/icons (752ms)
✓ charites build style.yml style.json --sprite-input icons --sprite-output . (756ms)
Test for the `charites convert`
✓ charites convert style.json style.yml (815ms)
Test for the `charites convert`
✓ charites init style.yml --tilejson-urls ${tileJsonUrl} (1122ms)
✓ charites init style.yml --metadatajson-urls ${metadataJsonUrl} (1069ms)
✓ charites init style.yml --tilejson-urls ${tileJsonUrl} --composite-layers (872ms)
Test for the `charites serve`
1) charites serve style.yml
2) charites serve style.yml --provider mapbox --mapbox-access-token xxxxxxx
Test for the `convert.ts`.
✓ Should convert `data/convert.json` to YAML.
✓ Should create layers directory.
Test for the `get-sprite-slug.ts`.
✓ should get sprite slug from style.json
✓ should return false with no icon's slug in url
Test for the `init.ts`.
✓ Should initialize default style.yml.
✓ Should initialize default composited style.yml from tilejson provided (81ms)
✓ Should produce composited style.yml without layers if tilejson without vector_layers is specified (98ms)
✓ Should initialize default decomposited style.yml from tilejson provided (59ms)
✓ Should initialize default decomposited style.yml from metadatajson provided (88ms)
Test for the `validate-style.ts`.
✓ should validate as expected.
Test for the `yaml-parser.ts`.
✓ should parse `data/example.yml`.
27 passing (29s)
2 failing
1) Test for the `charites serve`
charites serve style.yml:
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/j_igarashi/Documents/git/unvt/charites/test/command.serve.spec.ts)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
2) Test for the `charites serve`
charites serve style.yml --provider mapbox --mapbox-access-token xxxxxxx:
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/j_igarashi/Documents/git/unvt/charites/test/command.serve.spec.ts)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) |
serve 用のテスト内で setTimeout を使っているので、待ち時間を 1秒変更してみました。 |
@naogify ダメですね。serveのテストでまだ落ちます。
|
@naogify あとmainブランチから最新をマージして、serveに追加いただいたオプションをドキュメントに反映もお願いします。 以下のページが該当箇所と思います。ページの右上のEdit on Githubから編集対象のソースコードに飛べます。 |
@JinIgarashi |
@JinIgarashi
|
@naogify 何が原因か自分にはわかりません。 |
@JinIgarashi |
@naogify 一旦serveだけ外してマージしてもいいかも。その上で、serveコマンドだけテストのやり方を見直してみたらどうでしょうか? |
@naogify 今のserveコマンドみたいに一つの関数の中で全てを行うような実装の仕方だとテストを書くにくいコードになってるけれども、最低限サーバー起動部分とそうでない部分を切り離したソースコードにした上で、ユニットテストを書くといいかもしれません。下の記事はそんな感じになってる。 https://medium.com/@basavarajkn/integration-testing-websocket-server-in-node-js-2997d107414c 大体どの記事もユニットテストの中で、専用のサーバー立ち上げてテストみたいな動きになってますね。 |
@JinIgarashi |
I added integrated tests for commands below. What do you think?
Adding tests for I would be happy to review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks
@JinIgarashi |
@naogify I have approved again. However I can’t merge this PR now. I think I have no longer been permitted with the write access for charites. |
Close #54
Description
Sorry for the big pull request.
I have implemented the following features
--headless
option to testcharites serve
if you run
charites serve style.yml --headless
, charites will skip opening browser. I added this option because I didn't want to open the browser while the test was running. If there is a better way, please let me know.The implementation part is as follows
charites/src/commands/serve.ts
Lines 88 to 91 in 59dfa21
Type of Pull Request
Verify the followings
main
branchnpm run build
npm run lint
charites help
globallyRefer to CONTRIBUTING.MD for more details.