Skip to content
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

How does this work? #123

Open
alayek opened this issue Sep 27, 2015 · 1 comment
Open

How does this work? #123

alayek opened this issue Sep 27, 2015 · 1 comment

Comments

@alayek
Copy link

alayek commented Sep 27, 2015

Hi, I would like to know how workshopper module works. I checked the promise-it-won't-hurt nodeschool exercise, and it seems to me that workshopper takes the student's submission, and solution provided - then compares both.

Is there any way for someone to use this workshopper module without providing solutions directly, and rather just provide test cases for expected solution in, say, Mocha and Chai JS?

I know it's not an issue, but I could not find any mailing list. Apologies for posting it under issues.

@thibaudcolas
Copy link

Hey @alayek,

I only understand enough of workshopper to get by, but in that case that's enough. I'm writing a D3 workshopper, using mocha and chai to test the solutions (+ ES6, jsdom and D3, but that's less relevant).

You can have a look at the relevant code here: https://github.com/ThibWeb/testdrived3/blob/master/src/lib/runner.js#L47

This comes down to:

  1. Running the test in a addSetup hook, and capturing the failures:
    exercise.addSetup(function(mode, callback) {
        const mocha = new Mocha();
        mocha.addFile(path.join(this.dir, 'spec.js'));

        runFunction(global.submission);

        mocha.run((failures) => {
            this.failures = failures;
            callback(null, true);
        });
    });
  1. Checking if there are failures in the addVerifyProcessor hook, and emit pass or fail accordingly.
    exercise.addVerifyProcessor(function(callback) {
        const i18n = exercise.__.bind(exercise);
        const passed = this.failures === 0;

        if (passed) {
            this.emit('pass', i18n('test.pass'));
        } else {
            this.emit('fail', i18n('test.fail'));
        }

        callback(null, passed);
    });

I have no idea if those are the proper hooks for this scenario, and I'm passing a global variable around that contains the user's solution, but hey it works! I stumbled upon this pattern while creating a PR for a React workshopper: https://github.com/asbjornenge/thinking-in-react.

I intend to extract a "jsdom ES6 mocha workshopper" boilerplate from this code once I'm done with it.

Edit: done! The boilerplate is available at https://github.com/ThibWeb/workshopper-mocha-boilerplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants