[英]`anchor test` error: Failed to run test: yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts: No such file or directory (os error 2)
I just initialized a solana dapp with anchor init
.我刚刚用
anchor init
初始化了一个 solana dapp。 Then I built successfully with anchor build
.然后我使用
anchor build
成功构建。 I tried to test anchor test
command too but it fails and I have not added any code yet.我也尝试测试
anchor test
命令,但它失败了,我还没有添加任何代码。 This is still untouched initialized code and this is the error message:这仍然是未修改的初始化代码,这是错误消息:
Failed to run test: yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts: No such file or directory (os error 2)
It says there is not file inside tests
directory but there is mydapp.ts
with this code它说
tests
目录中没有文件但是有mydapp.ts
和这段代码
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { Mydapp } from "../target/types/mycalculatordapp";
describe("mydapp", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
const program = anchor.workspace.Mydapp as Program<Mydapp>;
it("Is initialized!", async () => {
// Add your test here.
const tx = await program.rpc.initialize({});
console.log("Your transaction signature", tx);
});
});
I had to install yarn globally since I did not have it on my system我必须在全球范围内安装纱线,因为我的系统上没有它
sudo npm i -g yarn
Then I got ts-mocha
command not found even though it was on package.json
.然后我得到了
ts-mocha
command not found 即使它在package.json
上。 so I run npm install
to install all dependencies.所以我运行
npm install
来安装所有依赖项。 Then I got ts node
error然后我得到了
ts node
错误
sudo npm i -g ts-node
Finally it works终于成功了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.