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 support? #9

Open
mathpunk opened this issue Aug 31, 2021 · 4 comments
Open

Cucumber support? #9

mathpunk opened this issue Aug 31, 2021 · 4 comments

Comments

@mathpunk
Copy link

mathpunk commented Aug 31, 2021

Hello! I am implementing integration tests in Cypress at work, and we decided to use the Cucumber preprocessor. I'd love to try writing steps in ClojureScript to see what that's like; maybe something like

hello-cljs.feature

Given I can write steps in Clojure

hello-cljs/steps.cljs

(given #"I can write steps in Clojure(Script)?"
  (.should (.window cy) "have.property" "top")))

Do you think this is achievable? I don't know a lot about JavaScript -- any time I see module.exports I start sweating -- but I would try to help if this sounds like a feature worth adding.

@viesti
Copy link
Owner

viesti commented Sep 2, 2021

Hi! I haven't used cucumber myself, so I'm not familiar with it, but it would be a neat idea to support that in Clojure land :)

I wonder if a cljs cypress cucumber could a project of it's own, maybe using cypress-clojurescript-preprocessor to do the cljs -> js transform only.

@mathpunk
Copy link
Author

mathpunk commented Sep 2, 2021

It all looks like magic to me 😆 Do you think the least complex path would be, fork cypress-cucumber-preprocessor, and include your preprocessor into that?

@viesti
Copy link
Owner

viesti commented Sep 2, 2021

Re: magic :D What I was thinking was that since cypress allows to register multiple preprocessor, could the cljs-cucumber preprocessor exist separately, so that it only looks for feature files and then calls the cljs preprocessor to do cljs->js transform to produce js that can then be run inside the cypress runner?

There might be some pointers in this issue: cypress-io/cypress#5832. Also, there's this open PR (#1) which removes the bundled browserify which I just haven't yet wrapped my head around, probably because it needs a (breaking) release with instructions on how to put the conditional into the preprocessor registration (not big thing but just haven't been able to focus on doing it :)).

Sorry for the long mumble, but you could try something like the snipplet below. Just detect feature files in cypress plugin registration, delegate cljs feature implementation file transform to cljs preprocessor, skip the cljs implementation file (to not show it in cypress twice), but run cljs transform for non-feature files (plain cljs tests):

module.exports = (on, config) => {
  const cljsPreprocessor = makeCljsPreprocessor(config);
  on('file:preprocessor', file => {
    if (file.filePath.includes('.feature')) {
      // Hack to point to the cljs file that implements the feature
      file.filePath = file.filePath.replace("feature", "cljs")
      return cljsPreprocessor(file);
     } else {
       // Here we should skip the cljs files that implement the features, but should call cljsPreprocessor for "plain" cljs tests, something like: 
       if (file.filePath.includes('.feature') && fs.existsFileSync(file.filePath.replace('.feature', 'cljs'))) {
         console.log('Skipping feature implementation');
         } else {
           return cljsPreprocessor(file);
        }
     }
});
};

Now that I think about it, maybe you can just use the cljs preprocessor straight, just find a way to load the feature file in the feature implementation, but I guess you'd then need to implement the actual cucumber feature parsing also :)

@mathpunk
Copy link
Author

I keep thinking about this. In a way, I do want to implement the cucumber feature parsing because then I could extend the language. But I would want to re-use whatever is already doing the code-finding for features.

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