我们推荐使用 VS Code 开发 ASCH 智能合约,原因有三:
- 配合 TSLint 插件,TypeScript 开发体验极佳
- 众多的插件
- 断点调试方便
下面列举三种调试方法。
方法一
-
编写 test.ts,引入 mock.ts 和 SimpleContract.ts
-
设置 .vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Test Contract", "args": [ "-r", "${workspaceFolder}/node_modules/ts-node/register", "${workspaceFolder}/test.ts" ] } ] }
-
在 SimpleContract.ts 添加断点
-
启动调试
方法二
-
引入 ts-jest
npm i ts-jest --save
-
配置 jest 的 transform 为 ts-jest
-
"jest": { "transform": { "^.+\\.ts$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.ts$", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] }
-
-
在 __tests__ 目录下编写 xxx.test.ts 测试文件
方法三
基于方法二。
- VS Code 安装 Jest Runner 插件
- 在 __tests__/xxx.test.ts 某个 it 测试里添加断点,右键选择「Debug Jest」调试单个 it