Skip to content
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

Issues w/ anchor test #945

Closed
farzaa opened this issue Oct 27, 2021 · 24 comments
Closed

Issues w/ anchor test #945

farzaa opened this issue Oct 27, 2021 · 24 comments

Comments

@farzaa
Copy link

farzaa commented Oct 27, 2021

Hey there! On anchor-cli 0.18.0.

Trying to run anchor test but when I do so, I get hit with:

Failed to run test: ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts: No such file or directory (os error 2).

So, I then did npm install ts-mocha -g to see if that would change anything.

Running the test again, I get

node: --dns-result-order= is not allowed in NODE_OPTIONS.

Just running a boilerplate hello-world project from the docs via anchor init helloworld.

I also tried doing anchor init helloworld --javascript, then do anchor test, and still get: node: --dns-result-order= is not allowed in NODE_OPTIONS.

@tomlinton
Copy link
Contributor

Are you using the npm package? Install 0.18.2, see #928

@farzaa
Copy link
Author

farzaa commented Oct 28, 2021

Ah, I installed v0.18.0 via:

cargo install --git https://github.com/project-serum/anchor --tag v0.18.0 anchor-cli --locked

As done here.

BTW -- my node version: v16.0.0.

What's the path to installing v0.18.2 to test this out? Or, is the issue my version of node?

@tomlinton
Copy link
Contributor

tomlinton commented Oct 28, 2021

It looks like the version hasn't been bumped, so the same command without the --tag v0.18.0 and with --force:

cargo install --git https://github.com/project-serum/anchor anchor-cli --force

@farzaa
Copy link
Author

farzaa commented Oct 28, 2021

So, this gives me:

error: cannot find attribute `clap` in this scope
   --> cli/src/lib.rs:289:11
    |
289 |         #[clap(short, long)]
    |           ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error: cannot find attribute `clap` in this scope
   --> cli/src/lib.rs:297:11
    |
297 |         #[clap(short, long)]
    |           ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error: cannot determine resolution for the derive macro `Clap`
   --> cli/src/lib.rs:302:17
    |
302 | #[derive(Debug, Clap)]
    |                 ^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports

For more information about this error, try `rustc --explain E0432`.
error: could not compile `anchor-cli` due to 47 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `anchor-cli v0.18.0 (https://github.com/project-serum/anchor#ec269663)`, intermediate artifacts can be found at `/var/folders/1b/qv2kp9516ds36908hr45skj40000gn/T/cargo-installNxoOJh`

Caused by:
  build failed

Looks like it still tried to install v0.18.0 though!

As a sanity check, tried the installation command here and it worked out fine.

@armaniferrante
Copy link
Member

@farzaa can you try adding the --locked flag.

@farzaa
Copy link
Author

farzaa commented Oct 28, 2021

Hey! @armaniferrante -- tried both

cargo install --git https://github.com/project-serum/anchor anchor-cli --force --locked

and

cargo install --git https://github.com/project-serum/anchor anchor-cli --locked

But each time it starts installing v0.18.0.

@tomlinton
Copy link
Contributor

But each time it starts installing v0.18.0.

Yep that's fine, it is because the version hasn't been bumped in the repository yet. The installed version you end up with will have the fix.

@farzaa
Copy link
Author

farzaa commented Oct 28, 2021

This worked out for me :)

cargo install --git https://github.com/project-serum/anchor anchor-cli --locked
anchor init aproject --javascript
cd aproject
anchor test

As a side note -- I run and we're putting together a Solana + Anchor course. Should I tell people to use the install command above vs what's in the docs rn?

Ty :).

@ElvisWong
Copy link

Got the same issue with @farzaa. I'm a newbie to anchor and just encounter the same issue with #925. I'm running this command

cargo install --git https://github.com/project-serum/anchor --tag v0.18.2 anchor-cli --locked

    Updating git repository `https://github.com/project-serum/anchor`
error: failed to find tag `v0.18.2`

@tomlinton
Copy link
Contributor

Run cargo install --git https://github.com/project-serum/anchor anchor-cli --locked

@dahifi
Copy link
Contributor

dahifi commented Oct 28, 2021

If you installed Anchor CLI from npm and create a project, you'll need to edit package.json "@project-serum/anchor": "^0.18.0",

Otherwise use the Rust CLI.

@itsbek
Copy link

itsbek commented Oct 30, 2021

hey there!
I followed these instructions step by step but cargo build failed and tried the possible solutions listed above but it still keeps failing

My PC is running on Ubuntu 20.04

Edit1: there was also these on terminal:

$HOST = x86_64-unknown-linux-gnu
$TARGET = x86_64-unknown-linux-gnu
openssl-sys = 0.9.66

Edit2[SOLVED]: for some unknown reasons my OpenSSL folder got removed/deleted and had to reinstall the dev package with
$ apt install pkg-config libssl-dev and that did fix the build error.
hope this helps someone like me

@AllanAi
Copy link

AllanAi commented Nov 3, 2021

npm install -g ts-mocha typescript works for me. #942

@fanatid
Copy link
Contributor

fanatid commented Nov 3, 2021

--dns-result-order is fixed in #928

@Eliascm17
Copy link

Eliascm17 commented Nov 4, 2021

Got Failed to run test: mocha -t 1000000 tests: no such file or directory (os error 2) when running anchor test and running npm i -g mocha fixed it for me.

@katopz
Copy link

katopz commented Nov 5, 2021

modify Anchor.toml to use npx fixed it for me

[scripts]
test = "npx ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

@pano-skylakis
Copy link

modify Anchor.toml to use npx fixed it for me

[scripts]
test = "npx ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

Using yarn works as well :)

[scripts]
test = "yarn ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

@ali-ahari-hashemi
Copy link

cargo install --git https://github.com/project-serum/anchor anchor-cli --locked
anchor init aproject --javascript
cd aproject
anchor test

This fixed it for me

@YuheiNakasaka
Copy link

YuheiNakasaka commented Nov 9, 2021

In case of using --javascript option, I changed mocha command in Anchor.toml tonode_modules/mocha/bin/mocha and it worked.

[scripts]
test = "node_modules/mocha/bin/mocha -t 1000000 tests/"

@fanatid
Copy link
Contributor

fanatid commented Nov 9, 2021

@YuheiNakasaka please read about npx. https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b

@fanatid fanatid closed this as completed Nov 9, 2021
@baijifeilong
Copy link

npm install -g ts-mocha typescript works for me. #942

npm install -g ts-mocha typescript mocha

@dataXBT
Copy link

dataXBT commented Feb 8, 2022

npm install -g ts-mocha typescript works for me. #942

npm install -g ts-mocha typescript mocha

worked for me after previously having faulty connection issues with node as well

@richiehydra
Copy link

Even after using Anchor docs command for installing anchor i havent got the solution
please rectify:
warning: build failed, waiting for other jobs to finish...
error: failed to compile anchor-cli v0.25.0 (https://github.com/project-serum/anchor#fd467df9), intermediate artifacts can be found at /tmp/cargo-installOeao69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests