Closed Sweetdevil144 closed 4 months ago
If you take a look at the top level package.json you will see
"test": "npm run test --workspaces",
This runs all the tests in all the packages. If you look at caliper-core package you will see
"test": "npm run lint && npm run nyc"
the npn run nyc
runs the tests and also determines code coverage.
So it's possible to run all the tests for the whole of caliper or individual package tests.
The reason that you don't see this in caliper-cli and some of the other packages is because those packages don't have any tests so there is no point adding the entry to the test
property.
As caliper doesn't do any pre-processing or transpiling of the code, it make sense to include linting as part of the test stage to ensure that the code is actually ok before running the tests.
So there isn't anything wrong with the implementation as it is except for the fact that caliper is severely lacking in it's test suite and there is a mentorship project at hyperledger this year to address this so the hope is that this will advance the test suite and as tests are added to packages that have no tests then package.json 'test' property will be updated to reflect this.
Maybe we can change the required script for linting
to mpn run lint
and add a command for test. That way, it will be much more clear and refracted. As goes for the LFX, I am applying too for the Caliper project. I'll prepare and submit a doc specifying the needs for the same.
@Sweetdevil144 Sorry, not sure I agree with this. WIth a non compiled, non transpiled application such as caliper, it makes sense to combine linting with testing.No point running any tests if the linting fails. You can of course run npm run lint
already and it will just do linting. Sorry but I don't see any value in changing what is already there.
Yeah, Testing without Linting is not beneficial. I'll agree with it. Let's keep this issue in store here and later on discuss what needs to be done once our caliper
repository is equipped with test-suites
of its own and matches the requirements needed to do so.
Hey @davidkel , I think this issue would be good if it was closed now. This resolves all confusion I had for the scripts.
Which Caliper version are you using?
latest
Which Node.JS version are you using?
v21.7.2
Which operating system are you using?
MacOS arm64
Please provide some context for your error. For example, when did the error occur? What were you trying to achieve, and how?
I was working on setting up the testing environment for the Hyperledger Caliper project. I noticed an issue in the
package.json
file where thetest
script was set to run the linting command ("test": "npm run lint"
). This occurred while I was reviewing the project setup and preparing to write and run tests.My goal was to run the project's test suite using the
npm test
command, which is a standard practice in Node.js projects. However, due to the current script setup, runningnpm test
only lints the code and does not run any tests.I believe separating the linting and testing commands would be more beneficial and align with common practices, allowing developers to lint their code and run tests independently. This change would also make it clearer what each npm script is doing.
What was the observed incorrect behavior?
When I ran the
npm test
command, instead of executing the test suite as expected, it was running the linting command. This is not the typical behavior for a test script in a Node.js project.Please provide the error logs and their surroundings.
Please provide any additional information you deem relevant to the error.
This is not a typical setup for a Node.js project. Usually, the
test
script is used to run the project's test suite, and linting is handled by a separate script.This setup could lead to confusion for developers who are accustomed to running npm test to execute the test suite. It could also potentially hinder the testing process, as developers might run
npm test
expecting to see test results, but instead, they would only see linting results.