Babelã®åå¼·ã¨ç§°ãã¦muscle-assertãä½ã£ã¦ã¿ã
ç§ã¯åããªãã¨æ»ãã§ãã¾ãï¼ã³ã³ãã¤ã©ã¨ç¸è«ããªãã¨èæ ®æ¼ããå¤çºãã¦æ»ã¬ï¼ã®ã§ãJSç³»ã触ãå ´åã¯ä¸»ã«TypeScriptãªã®ã§ãããã¨ã¯ããæ¨ä»ã®äºæ çã«Babelãé£ããå«ãããã®ãªãâ¦ã¨æã£ãã®ã§ã©ã¤ãã©ãªã¨ããç¨ã®puluginãä½ã£ã¦ã¿ããã¨ã«ããã
åå¼·åã®ã¹ãã«
- Babelç³»ã®æ
å ±ã¯è¿½ã£ã¦ããã使ãã®ã¯ï¼ã»ã¼ï¼å§ãã¦
- æ¢ã«å¥ã®äººãæ§ç¯ãããã®ãã¡ããã£ã¨è§¦ã£ããã¨ãªããã
- TypeScriptã¯ä½¿ããï¼è©³ããããã§ã¯ãªãï¼
æ¹é
ããããã®ã¯å¼·ãæ¹ã ã®åãåããã«éãã
https://github.com/azu/power-assert-as-tool-demo
Babel pluginã®ç¥è㯠https://github.com/thejameskyle/babel-handbook ãæãèªã¿ãã¤ã¤ãhttps://github.com/power-assert-js ä¸ã«ããbabel pluginãèªã¿æ¼ã£ãã
ä½ãã¤ãã§ã«é¡ä¼¼åãã§ãã¯
Persimmon用アサーションライブラリMuscleAssertを作った - pocketberserkerの爆走
ãã®è¨äºã®è¨æ¶ãã¾ã èªåã®è³å ã«æ®ã£ã¦ãããã¡ã«ç§»æ¤ãã¦ã¿ããã£ãã®ã§ãä»åã¯ãããé¡æã«ããã ä¸å¿é¡ä¼¼åãç´¹ä»ãã¦ããã
https://www.npmjs.com/package/assert-diff
ãã£ã¦ãããã¨ã¯ã ãããåãã ããæ¨æºassertããã¼ã¹ã«ãããã£ãã®ã§èªä½ãããã¨ããå¿æã¡ã§ããã
ãã¨ãä¼¼ããããªdiff表示ã¯mocha
ã§ããã°è¡ã£ã¦ãããã
ã ããmochaã§ããã°å¿
è¦ãªãâ¦ã®ã ããeaterãªã©ã§ã¯ããããããã«ããããªãã¨æãã
ææç©ï¼
https://github.com/pocketberserker/muscle-assert https://github.com/pocketberserker/babel-plugin-muscle-assert https://github.com/pocketberserker/muscle-assert-demo
Babelåã§ä¸æ¥å°ã ã«ãã¦ã¯ç§çã«ã¯é å¼µã£ãã»ããããªãã§ããâ¦ã¾ããåèã«ã§ãããã®ããããã£ãããã ãããã©ã
muscle-assertã¯æ¨æºã®assert.deepStrictEqual
ã®ã¿ãç½®ãæããæ¹éã«ããã
ããããã»ããã·ã³ãã«ã ããããä»ã®ã©ã¤ãã©ãªã¨ãå¹²æ¸ããªããªãã ããã¨æã£ãã
ããããããã§Babel pluginå´ãæä½éã®ç½®ãæãã«ã¨ã©ãã¦ããã
使ãæ¹ã¯ãã¢ããã¸ã§ã¯ããã¿ãã°ãããã¯ãã 表示ãããã¼ãã®ã¯ãããã¿ã¤ããªã®ã§åå¼ãã¦ãã ããã ãã°ã£ã¦ããããã®ãã¡ç´ãã¾ãã
ããã¥ã¡ã³ãããªããããã®ã¯â¦æ¬æ°ã§å®è£ ããæ°åãèµ·ããã°æ¸ãã
課é¡
ãªãã¹ãpower-assertã¨å¹²æ¸ããªãããã«ä½ãããâ¦ã¨æã£ã¦ããã®ã ãã以ä¸ã®åé¡ã«ã¶ã¤ãã£ãã
@pocketberserker babel-plugin-espower 㯠Babel é»éè¡ã使ã£ã¦ä»ã®å ¨ã¦ã® plugin ã«å åããã¦åä½ããããã§ã
— Takuto Wada (@t_wada) 2016å¹´6æ6æ¥
babel-plugin-espowerãå
ã«å¤æ´ãã¦ãã¾ãã®ã§ãã¹ãããããããªãã
åé¿æ¹æ³ã¯ä»ã®ã¨ããbabel-plugin-espowerã®patterns
ã«assert.deepStrictEqual
ããããªãã¨ããå ´å½ããçãªãã®â¦ãªãã¨ãããããããªãã¨ãã§ããã®ããªãã
ã¨ããããã§ãä»ã®ã¨ããbabel-preset-power-assertã¨ã®å ±åã¯é£ããã®ã§ã¯ãªããã¨èãã¦ããã
ãããã«
Babelã¯å ¥éããã ããªããããªã«æéãããããªãããã ã power-assertã®å°å ¥ã¯è¨äºãä¹±ç«ãããã¦ãããå¤ãæ å ±ããã¤ãºã«ãªã£ã¦TypeScriptã®ã¨ãã¯ã¤ããæ°æã¡ã«ãªã£ã¦ããããBabelåæã ã¨babel-preset-power-assertããããããã£ã¦ãããã®ã§è¯ãã¨æãã ã¨ã¯ããã楽ã«ãªã£ãã®ã¯ããã¾ã§Babelãã³ã ããªã®ã§TypeScriptã®æã«ããå°ãã©ãã«ããªããªããèãã¦ã¿ãããããã
babel-plugin-espowerã®ããã¯ãããããã¨ãèããã¨ä»æ¹ããªãã®ã ã¨æãã ããããã®ã¯å¾çºã©ã¤ãã©ãªãé ãã²ããã°è¯ãåé¡ã ã¨æãã®ã§ãbabel-plugin-espwerããã¯ãã®ã¾ã¾ã®å¼·ãã§å± ã¦ã»ããã