viesti/cypress-clojurescript-preprocessor

Cucumber support?

mathpunk opened this issue · 4 comments

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.

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.

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?

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 :)

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.