dalekjs / dalek

[unmaintained] DalekJS Base framework
MIT License
695 stars 63 forks source link

Macros/Functions/Modules #28

Open dscherr opened 10 years ago

dscherr commented 10 years ago

For organizing greater Tests with repetitive code, i need a possibility like macros, which you can integrate in different tests. I am not an advanced javascript developer, maybe there are existing possibilities for that. For example sometimes you need a special trick for your site for jQuery UI elements (select box?) and you want to solve this problem one time and use it over the whole tests. It would be very nice to write .selectbox-jqui('#address option[value="mister"]') to select the special option or to handle birth dates in the same way by using .type-birth('1', '1', '1970') (3 single input fields are grouped in this macro), but the main point is to define own commands.

dscherr commented 10 years ago

This is handled in https://github.com/rodneyrehm/dalek-api :+1:, thanks to rodney.

asciidisco commented 10 years ago

Yes, we will try to get this into Dalek within the next 3 to 4 weeks. That is the reason why version 0.0.9 will be left out & a big feature/bugfix release 0.1.0 will come along.

dscherr commented 10 years ago

Thanks for the hints.

rodneyrehm commented 10 years ago

As @asciidisco and me are short on time in November, the new API stuff (which isn't even sufficiently defined yet) will take till mid/end of December.

What you call macros, we call plugins. We're still tinkering with how to provide them exactly, but this should give you a pretty good idea:

dalek.addAction('myPlugin', function(done, error, arg1, arg2) {
  // plugins are strictly asynchronous, thus:
  // done is a callback to be executed once the plugin finished
  // error is a callback to be executed when you'd throw an exception
  // arg1, arg2, … are the arguments you passed at invocation

  this
    // create a new context (pretty much a new test unit instance)
    // let it control the flow (done, error)
    .pipe(done, error)
    // do whatever you would've done repeatedly in a test
    .someOtherAction()
    // declare that your plugin (or macro or whatever) is done
    // (same semantic a test unit instance has)
    .done();
});

test
  // call your plugin or macro or whatever
  .myPlugin('argument 1', 'argument 2')
  .done();
rodneyrehm commented 10 years ago

Skaro has added the concept of Macros for a set of tasks that should not be reported on, and helps with knocking together tests in cases all tasks should be reported on.