acuminous / yadda

A BDD javascript library
412 stars 73 forks source link

Is it possible yadda with electron-spectrum? #239

Closed ZHChen8397 closed 6 years ago

ZHChen8397 commented 6 years ago

Hi, I am writing ap electron app and tried to test it with yadda. this is the original index

new Yadda.FeatureFileSearch('./test/features').each(function(file) {

featureFile(file, function(feature) {

    var libraries = require_feature_libraries(feature);
    var yadda = Yadda.createInstance(libraries);

    scenarios(feature.scenarios, function(scenario) {

        steps(scenario.steps, function(step,done) {

            yadda.run(step,done);
        });
    });
});
});

Is it possible that before every feature I can start my app? the code may be like

new Yadda.FeatureFileSearch('./test/features').each(function(file) {

    featureFile(file, function(feature) {
        beforeEach(function () {
            this.app = new Application({

              path: electronPath,

          args: [path.join(__dirname, '..')]
        })
        return this.app.start()
      })
    var libraries = require_feature_libraries(feature);
    var yadda = Yadda.createInstance(libraries);

    scenarios(feature.scenarios, function(scenario) {

        steps(scenario.steps, function(step,done) {

            yadda.run(step,done);
        });
    });
    afterEach(function () {
        if (this.app && this.app.isRunning()) {
          return this.app.stop()
        }
      })
});

});

cressie176 commented 6 years ago

I haven't any experience with electron or electron-spectrum, but I think so. Yadda isn't doing anything particularly clever in the mocha plugin - it just calls describe and it, passing them the scenario title and step text. Assuming electron-spectrum works just like mocha if you execute before or beforeAll within the feature, scenario and step callbacks I think you'll see the code executing.

There's an example here, but it only uses global setup.

One thing to watch out for - if app.start() isn't synchronous you'll need to find some say to wait until the application has actually started.

cressie176 commented 6 years ago

Any luck getting it working?

ZHChen8397 commented 6 years ago

Sure. Sorry for the late comment here. It's just like what you said, execute before, after within features, and it works. the code may like this

new Yadda.FeatureFileSearch('./test//features/mrtFeature').each(function(file) {

    featureFile(file, function(feature) {

        var library = require('./test/steps/mrt.js');
        var yadda = Yadda.createInstance(library);
        before(function () {
            this.app = new Application({
              args: [path.join(__dirname, './')]
            })
            return this.app.start()
          })

    scenarios(feature.scenarios, function(scenario) {
        steps(scenario.steps, function(step, done) {
            yadda.run(step, done);
        });
    });
    after(function () {
        if (this.app && this.app.isRunning()) {
          return this.app.stop()
        }
      })
});
});