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

anchor test npm/mocha issues #942

Closed
space-cat-96 opened this issue Oct 27, 2021 · 4 comments
Closed

anchor test npm/mocha issues #942

space-cat-96 opened this issue Oct 27, 2021 · 4 comments

Comments

@space-cat-96
Copy link

I've been keeping up with updates on the project lately (e.g. the 18.2.0 update) but I am still getting some npm/node issues.

I went through the installation steps earlier with anchor-cli v0.18.2 but still got anchor test still failed with:

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

Trying to install ts-mocha globally helps, but then I need to also install typescript globally.

I'm not sure why the locally packages are not resolved correctly, but I wonder if it would help to run the tests using an npm script, e.g.

"scripts": {
    "test": "ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
}

And then in Anchor.toml run this script directly:

[scripts]
test = "yarn test"

If I make these changes in my local project, the tests run correctly without the globally installed modules. I think this would be helpful, to avoid globally installed modules.

I'm happy to make a PR with these changes, if this is an appropriate direction.

@fanatid
Copy link
Contributor

fanatid commented Oct 27, 2021

We used npx for something like this but removed in favour of [scripts.test] #550

@space-cat-96
Copy link
Author

I think the currently approach with [scripts.test] will still try to run ts-mocha as a globally module, rather than the module installed locally in the project, if I'm not wrong. I think using an npm script would produce more reproducible behavior and avoid globally installed modules, but will defer judgment to the main project maintainers.

@fanatid
Copy link
Contributor

fanatid commented Oct 27, 2021

Just put to [scripts.test]:
npx ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts
or
yarn ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts

@tomlinton
Copy link
Contributor

I think this behaviour makes sense. If you are using the globally installed anchor-cli the other modules you run in [scripts.test] should also be global. It's the same in your shell, you can only run global ts-mocha, otherwise you use yarn run for the local.

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

3 participants