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

Added cucumber-js-style Before and After hooks. #195

Merged
merged 4 commits into from
Aug 21, 2019

Conversation

visusnet
Copy link
Contributor

Cucumber.js has Before and After hooks which can be used in conjunction with tags. This PR adds the same capability to cypress-cucumber-preprocessor:

Before(() => {
  // executed before every scenario
});

Before({ tags: '@tagged'}, () => {
  // executed before every scenario tagged with @tagged
});

After({ tags: '@tagged'}, () => {
  // executed after every scenario tagged with @tagged
});

It also allows asynchronous hooks, e.g.:

Before(async () => {
  // scenario is resumed only after this callback resolves
});

After(async () => {
  // scenario is completed only after this callback resolves
});

Before(() => {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log('This will be logged before the scenario is resumed');
      resolve();
    }, 1000);
  });
});

@visusnet
Copy link
Contributor Author

This should also fix #25.

@visusnet visusnet force-pushed the feature/hooks branch 2 times, most recently from a65cf6d to 1ee34c5 Compare July 29, 2019 12:37
@visusnet visusnet changed the title Added cucumber-js-style Before and After hooks. WIP: Added cucumber-js-style Before and After hooks. Jul 29, 2019
@visusnet visusnet changed the title WIP: Added cucumber-js-style Before and After hooks. Added cucumber-js-style Before and After hooks. Jul 29, 2019
@visusnet
Copy link
Contributor Author

After some edge cases did not work, I had to do push some changes. This should work now. :)

Copy link
Collaborator

@lgandecki lgandecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work. I didn't have a chance to try it out yet or review properly, just noticed that you commented out some tests. Otherwise it makes sense. @lucetius @sawasawasawa @rcywinski @dweller23 maybe one of you would like to checkout this branch, test the functionality and review the code?

require("../cypress/support/step_definitions/basic");
resolveFeatureFromFile("./cypress/integration/Plugin.feature");
});

describe("Background section", () => {
require("../cypress/support/step_definitions/backgroundSection");
resolveFeatureFromFile("./cypress/integration/BackgroundSection.feature");
});
}); */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for commenting out this test? and the And and But below?

require("../cypress/support/step_definitions/and_and_but_steps");
resolveFeatureFromFile("./cypress/integration/AndAndButSteps.feature");
});
}); */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one as well

@visusnet
Copy link
Contributor Author

I have commented out these tests by mistake. I have force-pushed a new version without the comments.

@guiyomh
Copy link

guiyomh commented Aug 21, 2019

Good job

@lgandecki
Copy link
Collaborator

What the heck @guiyomh? I'm reviewing this PR at the very moment!
No one picked it up from our team (consequences of summer time..), so decided to finally give this a try. :) Expect an update in an hour or so.

@lgandecki
Copy link
Collaborator

Looks great. I've tweaked some tests. Still thinking how to improve the readability of BeforeAndAfterSteps (pretty meta, hard to word it nicely, I know ;) )

The only thing I'm debating is whether we should overwrite the cypress exposed before/after.
I think it might be nicer to have them import-only with capital letters. (a bit confusing, but in line with what people use when writing cucumber files in pure cucumberjs)
This way, we also don't introduce any breaking changes for people that already use the mocha before/after steps.

@lgandecki
Copy link
Collaborator

I messed up the git commit history somehow.. :D But, you can see my changes here:
b232286
and here:
ddb5a46

I will think a bit more about improving the .feature file, otherwise I will merge and release

@lgandecki
Copy link
Collaborator

@visusnet this is what I came up with for the .feature file, please take a look , if you are fine with the changes I'd merge and release.
920aeec

@visusnet
Copy link
Contributor Author

@lgandecki I‘m fine with your changes. Go ahead. :)

@lgandecki lgandecki merged commit 74b2b40 into badeball:master Aug 21, 2019
lgandecki added a commit that referenced this pull request Aug 21, 2019
@lgandecki
Copy link
Collaborator

🎉 This PR is included in version 1.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants