LimeChain / matchstick

🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️
MIT License
210 stars 18 forks source link

Add configuration options to graph cli testing #211

Closed ghardin1314 closed 2 years ago

ghardin1314 commented 3 years ago

Since the implementation of v0.2.0, Matchstick as implemented by the graph cli is very opinionated about the location of the test and schema files.

As of now, all tests files must be located under a tests directory. Since our project (and I imagine most that integrate matchstick) also have smart contracts that need to be tested, it would be nice to specify the location of this directory. For example:

tests/
└── subgraph
    └── example.test.ts
└── contracts
    └──  example.test.ts

We could specify that our matchstick tests were located in tests/subgraph.

It would also be nice to have a single command for running tests on all datasources rather than having to specify individual ones.

Finally, the subgraph.yaml allows you to specify the location of your schema.graphql file, but as far as I can tell, matchstick requires it to be located at the root of the project.

I am proposing the addition of a (potentially optional) configuration file similar to hardhat that will allow for these, along with future configuration options, to be specified.

Once again, thanks for the great work thus far! Let me know how I can be of assistance.

VIVelev commented 3 years ago

We could specify that our matchstick tests were located in tests/subgraph.

Maybe we can add a flag like --dir to specify a directory other than tests/? Or even better, we can make matchstick recursively search for tests, since as of now it is limited to a depth of 1 (a subdir). This would allow you to run, for example, matchstick subgraph/another_test.

In the meantime, if tests/subgraph is populated with *.test.ts files, you can actually run them by invoking matchstick subgraph.


It would also be nice to have a single command for running tests on all datasources rather than having to specify individual ones.

As of v0.2.0, there actually is! Just matchstick, without arguments, will run all your tests.


I am proposing the addition of a (potentially optional) configuration file similar to hardhat that will allow for these, along with future configuration options, to be specified.

It's a good idea, but adding a config file might add unnecessary complexity. Regarding the schema.graphql file, if its location is specified in subgraph.yaml we should definitely take it from there rather than searching for it in the root - a mistake on our part.

When it comes to additional configs, I think a better implementation would be to have them in subgraph.yaml. For example, about the location of the tests, have something like: testDir: tests/subgraph . What do you think? We would need to coordinate with the graph-cli team too.

cc @axiomatic-aardvark @georg-getz

ghardin1314 commented 3 years ago

In the meantime, if tests/subgraph is populated with *.test.ts files, you can actually run them by invoking matchstick subgraph.

This is actually how I am doing it now lol. It works but then you lose the multiple files per datasource option

As of v0.2.0, there actually is! Just matchstick, without arguments, will run all your tests.

Just saw that in the discord! Saw there was a small issue on the graph-cli for it so I will wait for that to get resolved

I also really like the idea of putting the configuration into the subgraph.yaml file if thats an option. The less config files I have to manage the better.