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

Cucumber + Karma #1095

Closed
lwouis opened this issue May 21, 2018 · 8 comments
Closed

Cucumber + Karma #1095

lwouis opened this issue May 21, 2018 · 8 comments

Comments

@lwouis
Copy link

lwouis commented May 21, 2018

This is a follow-up to a closed issue. I'm looking for a way to use Cucumber together with Karma runner.

A few projects exist for that purpose, but they are all outdated. The most recent one only supports cucumber 1.3.0.

It was pretty easy to integrate Cucumber with protractor thanks to the actively maintained adapter, but there seems to be nothing similar for Karma.

@lwouis lwouis changed the title Karma + Cucumber Cucumber + Karma May 21, 2018
@aslakhellesoy
Copy link
Contributor

What’s your motivation for using it with Karma? What problem are you trying to solve?

@lwouis
Copy link
Author

lwouis commented May 21, 2018

I would like to use Cucumber to test Angular components.

I already wrote e2e tests for those components using cucumber+protactor, however i think it's not the right approach. I think i should have most of those as angular unit tests so basic component functionality is fast to test (these tests should run in seconds, not minutes), and then have some truly e2e tests, potentially going with SerenityJS to describe user-centric use cases.

I love Gherkin expressiveness. I love datatables as a way to parameterize tests. I love step definition code reuse. I've been maintaining Jasmine tests for a while now and i believe having Gherkin expressiveness would be a big productivity boost!

@aslakhellesoy
Copy link
Contributor

@lwouis have you considered using cucumber-electron instead? The setup is a lot simpler. You can find a small example here: /~https://github.com/cucumber-ltd/cucumber-angular-poc/tree/cucumber-electron

@lwouis
Copy link
Author

lwouis commented May 21, 2018

@aslakhellesoy Thanks for the suggestion! I tried the demo which works. Then I tried to use it in my Angular project, but it broke:

TypeError: Cannot read property 'injector' of null

on this line, on .compileComponents():

Before(() => {
  TestBed.configureTestingModule({
    declarations: [DropdownMultiselectFieldComponent],
    imports: [FormsModule],
  })
    .compileComponents();
});

I think there is some glue code between Karma and Angular that makes the Angular TestBed work. For instance, this line in karma.conf.js:

frameworks: ['jasmine', '@angular-devkit/build-angular'],

In the end using cucumber-electron or cucumber doesn't seem to solve the problem of testing angular components because I would have to find out what kind of glue makes testing work under karma, then write something similar for cucumber, which is kind of my original question, asking about a karma adapter.

@lwouis
Copy link
Author

lwouis commented May 22, 2018

I also tried replacing karma with jest through jest-preset-angular, and using gherkin-jest to enable cucumber inside jest. I managed to get the test running, however, I had issues with TestBed. I believe this is because jest-preset-angular does some wrapping of the jasmine it, describe and other functions. This wrapping is missing for the cucumber methods. I don't know enough about angular testing package inner workings to draw conclusions but I think it's something of that sort.

In any cases, just wanted to report for other people trying to unit test their angular app using cucumber that the jest route seems also to be a deadend, unfortunately.

@mitcoding
Copy link

I just released a karma adapter that uses the latest version of cucumber-js. https://www.npmjs.com/package/karma-cucumber-js-latest/. It is setup so you can use any assertion library (so far I have only tested it with chai/sinon). It doesn't support any of the cli options yet for cucmber-js. But it does support tag expressions. And currently only uses the summary report cucumber formater.

/~https://github.com/mitcoding/karma-cucumber-js-latest

@Izhaki
Copy link
Contributor

Izhaki commented Jan 4, 2019

Closing: No activity for more than a year.

Happy to re-open if this is still relevant.

@Izhaki Izhaki closed this as completed Jan 4, 2019
@lock
Copy link

lock bot commented Jan 4, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants