Open AuroraLantean opened 2 years ago
in your Anchor.toml file:
[scripts]
test1 = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/test1.ts"
test2 = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/test2.ts"
test3 = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/test3.ts"
To run test1:
$ anchor run test1
Note: You MUST Keep your Solana local network running before issuing this command!
This error came back in 2023 after the previous post here from 2022 August.
anchor run test1
now gave me Error: failed to get recent blockhash: TypeError: fetch failed
!!??
That is because it does not run a local network then deploy my programs... So that is new in Anchor 0.29.0
Then I ran solana-test-validator --reset
in another terminal, I got this error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist
Okay. Following the Deployment
instructions here
I can run specific tests using anchor run test1
, but that is WAY TOO COMPLICATED!
My Anchor.toml
[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
test1 = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/zero-copy.ts"
anchor test -h
gave me --run <RUN> Run the test suites under the specified path
When I ran anchor test --run ./tests/zero-copy.ts
, Anchor still ran all tests!!??
Workaround: change the Anchor.toml test path:
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/zero-copy.ts"
But this is a workaround, not the best solution...
How can I add multiple tests in [script]
then run one of the tests?
From this post
One workaround is to run anchor localnet
to perform the build, start-validator, and deploy before running anchor run test1
.
That is close, but can it be even easier with only one command?
Also, can this one command build ONE specific program, start validator, deploy that program, then run ONE specific test tile?
2024 and this is still an issue
why can't I just do anchor test --file tests/some_test.ts
??
I see in Anchor.toml we can specify which test file to run, or to run all of them at once.
But how can I specify which test file to run from yarn script like
yarn test1
yarn test2
?