-
Notifications
You must be signed in to change notification settings - Fork 35
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
passing args to exercises #3
Comments
Use https://github.com/rvagg/workshopper-wrappedexec/ Call exercise.wrapModule() to give it a full path to a module to Set properties with exercise.wrapSet(key, value) and they get passed to the module if the module exports a function. There's serialisation that happens here but your module also gets to set properties back on that object and they are serialised back into the parent process so you can use them for validation. What I'd actually recommend though is that instead of serialising functions you just inject them with your wrappedexec module. Put them in a module and pull them in. |
that's all very cryptic, I understand, I'll try and do up an example for you if you can't figure it out. |
@rvagg hm, ok, can you do an example of how you might setup something like: |
This is pretty basic, doesn't require serialisation of anything at this point, but I'm not exactly clear on how I'd go about requiring their exported module to run tests on it. |
Don't even use the exec and comparestdout processors. You have the ful path to their moule in |
Yep. This is what I've got thus far, seems to work not bad. (Goal is to call their function and solution with some lorem, and compare outputs.) var lorem = require('lorem-ipsum')
var exercise = require('workshopper-exercise')()
var assert = require('assert')
var path = require('path')
exercise = exercise.use(require('workshopper-boilerplate'))
exercise.addBoilerplate(require.resolve('./boilerplate/hello_world.js'))
exercise.addSetup(function(mode, callback) {
this.submission = this.args[0]
if (!this.solution) this.solution = path.join(this.dir, './solution/index.js')
this.submissionModule = require(process.cwd() + '/' + this.submission)
this.solutionModule = require(this.solution)
this.inputs = lorem().split(' ')
process.nextTick(callback)
})
exercise.addProcessor(function(mode, callback) {
this.inputs.forEach(function(input) {
console.log(this.submissionModule(input))
}, this)
process.nextTick(callback)
})
exercise.addVerifyProcessor(function(mode, callback) {
this.inputs.forEach(function(input) {
assert.equal(this.submissionModule(input), this.solutionModule(input))
}, this)
process.nextTick(callback)
})
module.exports = exercise |
I'm struggling with this (writing the exercise) that works with this solution: https://github.com/ajcrites/generators-adventure/blob/master/problems/on_thunks/solution.js The solution is to export a thunk of Another thing is that the "actual" and "expected" output can't be compared since I'm using Using the old method: https://github.com/ajcrites/generators-adventure/blob/master/problems/on_thunks/setup.js Attempt at current method: https://gist.github.com/ajcrites/3c420d86967b9a6776fb |
Check out learnyounode to see the comparestdout stuff in action, since you're not executing it at all you're not doing any comparison of output (which is completely optional now fwiw). The danger with directly invoking user supplied code is that it will often behave in unpredictable ways so you'll need to do things like try/catch and run parallel timers to check if your callback has been called or not. You have a lot of power to inspect their code but you have to be prepared for all sorts of crazy. Have a look at the make_it_modular exercise in learnyounode for one of the most complicated examples of this: https://github.com/rvagg/learnyounode/tree/master/exercises/make_it_modular Note in this case I'm getting them to make a separate module file so it's not their submission file that it's verifying, we do a comparestdout but also do some inspection to find out the name of their module file and then In your case it sounds like you don't need to be running comparestdout, you really just want to inspect their code. Do the Feel free to point me at your work-in-progress code if you're needing help and you have it in a branch. I don't have a whole lot of time but I might be able to offer pointers. |
As args to exercises are passed on cmdline,
Specifically, I wanted to pass functions I worked around this in functional-javascript-workshop with my own function serialisation and serializing some wrapper code which would re-construct any complex objects (e.g. objects with prototypes setup).
How do you envision such a thing could be integrated into workshopper?
Possible solutions:
The text was updated successfully, but these errors were encountered: