Closed hot9cups closed 1 year ago
After having explored some of the options Javascript offers, I have found a solution to do this.
Could you elaborate on the solution you propose?
I'm cool with doing:
function testSolution1() { }
function testSolution2() { }
function testSolution3() { }
function test() {
testSolution1()
testSolution2()
testSolution3()
}
module.exports.test = test;
and then having a Test.js
file that calls all the tests
functions. If you have a solution to the hardcoding I would like to hear it. Thanks!
I'm on phone but I'll try to be elaborate.
So what you typed is kinda what we have already anyway, maybe with 1 degree of abstraction lesser where the code for both testSolution1 and testSolution2 for example is within the test method instead of being in separate functions, but either way this already exists. The problem is having to hardcode the method name to be test for instance instead of something more generic.
Again since this already exists, I thought your comment earlier was to help move to a state where we're allowed to have multiple functions with whatever names we'd like, have them all exported and run through the Tests.js file without having to hardcode the function names in Tests.js If this isn't what you intended to begin with, well then I suppose I misunderstood your comment and so this issue could be closed right away I guess.
Otherwise, the solution I have in mind is exporting all of the test methods in the test file. Then having these imported in the Tests.js file as an Object, and looping through the functions in this Object and calling them. This enables us to 'just call the function' without having to know any of their names. This should also help make debugging slightly easier as we'd get the exact method that failed right at the first layer of the stack trace.
oh I see what you mean. Yeah, running all the functions in the test file would be fantastic. We can use existing frameworks for that.
Cool, I plan to do it with vanilla JavaScript instead of introducing a framework. Let me know if that works with you.
Yes, that works for me
@ignacio-chiazzo Do you think we can close this issue now as we were able to achieve what we wanted?
Or do you have anything else in your mind that we could do to improve the test functionality?
This is in response to the comment from my last PR. I've been experimenting ever since, and I think there's a way it could be achieved.
What we want to do:
test
or in some casestest1
,test2
, etc) we have right now,test
function as can be seen here. We want to get rid of this hardcoding as well as be able to invoke varying number of tests per test file as opposed to being able to invoke just 1 test per test file currently.After having explored some of the options Javascript offers, I have found a solution to do this. I'll be happy to work on the PR if you'd like to assign the issue to me.