fix: improved help message of 'new' command
Description
- Improved the help message of 'new' command with examples
Related issue(s)
Fixes #162
@LakshyaSatpal looking good man! Please just add a unit test that validates if list of examples is rendered? I'm just pretty sure that in few months someone will say "why do we use sync function here, lemme refactor" 😆
in the test, please do not "hardcode" list of examples as the tests will be affected by changes in examples list. So in test also read examples dynamically
Hi @derberg ! I was going through oclif documentation for testing for commands. I'm finding it challenging to write a test to check if a file is rendered. I mean, I couldn't get what do I have to actually test, validate if the user entered the correct example name from available examples? or only check the working of loadExampleFile synchronous function that we wrote? Btw, this is the first time I am writing unit tests. Please bear with me 😅
@LakshyaSatpal no worries. Happy to help you if you need.
- you need to provide test for new functionality. New functionality is: much better help message with list of examples. We need to have a test, that will evaluate if the list of examples from
/assets/examplesis included in the help message that you just created. - have a look on existing tests https://github.com/asyncapi/cli/tree/master/test/commands for commands. See how we check if certain message appears in the console
I recommend, especially if it is your first time, first create a test, where you basically hardcode the expected message in the text, so you check if the message printed in terminal match the message that you hardcode in test (with list of examples).
Once ☝🏼 works, then work on making sure that the list of examples is not hardcoded, but you read in dynamically inside the test, from examples dir
@derberg I wrote this simple test in the new.test.ts file where I checked for help message to contain the first example which I hard coded.
test
.stdout()
.command(['new', '--help'])
.it('help includes available examples', (ctx, done) => {
expect(ctx.stdout).to.contain('- simple.yml');
done();
});
This shows me an error of AssertionError: expected '' to include '- simple.yml'. I believe, it is not getting that I'm checking for help flag command. Am I moving in the right direction?
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
@LakshyaSatpal hey, you need a hand? I was out on holidays, but now back 💪🏼
@LakshyaSatpal hey, you need a hand? I was out on holidays, but now back 💪🏼
Hi @derberg, still stuck now the same problem - not able to write a test with help flag 😥, discussed it with @Souvikns as well
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
@LakshyaSatpal I hope you are still interested with this one. It helps with DX and as you see it is ok that we drop testing part
@derberg Okay, I removed the test and addressed other feedbacks. Please see if we can merge now
@Souvikns ping 😉
@LakshyaSatpal hay can you fix linter issues please
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
I have no idea why tests are failing 😭
it is not random, it is always [ERR_INVALID_ARG_TYPE]: The "warning" argument must be of type string or an instance of Error. Received an instance of TypeError but why.......#$%
@LakshyaSatpal maybe you could switch to readFile that is already used in the same file, instead of importing readFileSync? or was sync selected because description: await getExamplesFlagDescription() was not possible?
@LakshyaSatpal not sure why but you are having a lot of linter issues. Do you want to continue with this PR?
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
@LakshyaSatpal can you specify if you plan to continue with this one, or should that be released to other contributors?
no reaction so closing, hope someone will pick it up from https://github.com/asyncapi/cli/issues/162
done with https://github.com/asyncapi/cli/pull/758