Giter Site home page Giter Site logo

Coffeescript preprocessor about protractor HOT 30 CLOSED

angular avatar angular commented on May 5, 2024
Coffeescript preprocessor

from protractor.

Comments (30)

lebek avatar lebek commented on May 5, 2024 1

Thanks Julie - I've added plugin support to protractor (5147106) and built a coffeescript preprocessor (https://github.com/lebek/protractor-coffee-preprocessor).

The plugin support is loosely based on what they did with Karma. Some caveats I need to work out before submitting a pull request:

  • preprocessed files get saved into a temporary directory, not sure how this plays with require
  • no configuration option to map file patterns to preprocessors (for now this responsibility is delegated to the preprocessor itself)
  • no way to pass configurations to the preprocessor

We're going to trial protractor for new E2E tests on a large angular project, I'll let you know how it goes.

from protractor.

wizardwerdna avatar wizardwerdna commented on May 5, 2024 1

Indeed, the lack of transparent coffeescript preprocessing is a serious barrier to adoption for our team. Karma made it trivial, without even the need to modify a config file.

from protractor.

juliemr avatar juliemr commented on May 5, 2024

I'm trying to keep the project as lightweight on dependencies as possible, so this would be perfect for a plugin. I know little about coffeescript but would be happy to discuss design or make any changes to protractor that would be necessary for the plugin to work!

from protractor.

juliemr avatar juliemr commented on May 5, 2024

Also @karlgoldstein who was also interested in this.

from protractor.

searls avatar searls commented on May 5, 2024

👍 - to teams that write CoffeeScript everywhere else this is a pretty major hindrance.

from protractor.

DavidMikeSimon avatar DavidMikeSimon commented on May 5, 2024

+1

from protractor.

DavidMikeSimon avatar DavidMikeSimon commented on May 5, 2024

Also, @lebek I'm confused: Why doesn't plugin support seem to be available in any branch of protractor? The parent of 5147106 is part of master, but it itself is not.

from protractor.

jfroom avatar jfroom commented on May 5, 2024

@lebek does the coffee preprocesor work? I'm having trouble understanding how to get it running without any example code. I realize it may not be stable yet - but it would be great to be able to use coffeescript with protractor. Thanks.

from protractor.

lebek avatar lebek commented on May 5, 2024

Protractor's internals have changed a bit since I added plugin support. I'll look at merging the upstream changes this weekend and if possible I'll make a pull request.

from protractor.

bjorne avatar bjorne commented on May 5, 2024

I found a very simple way to enable basic CoffeeScript support for specs. Simply put require('coffee-script'); inside the protractor config file. Then specifying a .coffee file in specs will work. Perhaps not the most elegant solution, but it seems to work.

Another thing; by is a keyword in CoffeeScript, so it would be nice to alias it to global.by_ (or something similar) in addition to global.by.

from protractor.

jfroom avatar jfroom commented on May 5, 2024

Thanks @bjorne . I also had to run a npm install -D coffee-script for completeness sake.

from protractor.

alexurdea avatar alexurdea commented on May 5, 2024

You can alias by to something else in the config file, inside the onPrepare callback.

from protractor.

matteosister avatar matteosister commented on May 5, 2024

@alexurdea could you please provide an example?

from protractor.

matteosister avatar matteosister commented on May 5, 2024

I'm answering myself...something like:

exports.config = {
    onPrepare: function() {
        global.findBy = protractor.By;
    }
}

from protractor.

alexurdea avatar alexurdea commented on May 5, 2024

@matteosister I have:

exports.config = {
  onPrepare: function() {
    global.select = global.by;
  }
};

And then I use it like this: element(select.input("loginForm.username")).sendKeys(username)

from protractor.

daniellmb avatar daniellmb commented on May 5, 2024

Alternative workaround for "by" is to use JS escaping with backticks:

myButton = element `by`.name 'foo'

from protractor.

eddiemonge avatar eddiemonge commented on May 5, 2024

Is there any reason the project has to use by.xyz? Can it maybe instead be changed to By.xyz? Makes more since especially since the actual name and object is By:
global.by = protractor.By;

from protractor.

JakeBecker avatar JakeBecker commented on May 5, 2024

Adding require('coffee-script'); to my config file didn't work for Coffeescript 1.7.0, but it did work once I reverted to 1.6.3. With 1.7.0, the extension handler for .coffee files wasn't getting registered. I didn't investigate very much, but it appears that the extension-registering code (which is nicely annotated for the 1.6.3 version) has changed in 1.7.

from protractor.

eddiemonge avatar eddiemonge commented on May 5, 2024

yeah, they made a breaking change in 1.7 that I haven't looked at how to integrate yet. This is from CS changelog:

When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register.

Not sure why they did that or what needs to happen to make that work. Not sure if a fix for 1.7 will break previous versions. Will do some testing.

from protractor.

JakeBecker avatar JakeBecker commented on May 5, 2024

Interesting. Just tried adding require('coffee-script/register'); to my Protractor config with 1.7 and it worked, but doing CoffeeScript.register(); caused an error complaining that CoffeeScript is undefined.

from protractor.

eddiemonge avatar eddiemonge commented on May 5, 2024

require('coffee-script').register();

Seems to do it for me and works on 1.7 and 1.6.3

from protractor.

flegall avatar flegall commented on May 5, 2024

Same as @JakeBecker, the only way to use CS with protractor > 0.17 is to include require('coffee-script/register');.

And it requires upgrading to coffee-script 1.7 :(

from protractor.

eddiemonge avatar eddiemonge commented on May 5, 2024

@flegall you can't do CoffeeScript.register() unless you do try { var CoffeeScript = require('coffee-script'); CoffeeScript.register(); } catch (e) {} and then its the same thing as https://github.com/angular/protractor/pull/473/files

from protractor.

flegall avatar flegall commented on May 5, 2024

Yes, but for some odd reason, I can't use CS anymore on protractor > 0.17, the only fix that works is to upgrade to CS >= 1.7 and to require('coffee-script/register');in the protractor configuration file.

from protractor.

jtomaszewski avatar jtomaszewski commented on May 5, 2024

@flegall is correct, I also had to write require('coffee-script/register'); in protractor config file.

from protractor.

eddiemonge avatar eddiemonge commented on May 5, 2024

hmm ill take a look. maybe the 0.17 refactor has the references wrong now

from protractor.

aleks-sidorenko avatar aleks-sidorenko commented on May 5, 2024

@lebek , Is this plugin still working? I dont see 'plugins' config property in sample protractor config.

from protractor.

zweifisch avatar zweifisch commented on May 5, 2024

@aleks-sidorenko seems that no plugin is needed, just run protractor conf.coffee

from protractor.

eddiemonge avatar eddiemonge commented on May 5, 2024

now you just have to include coffee-script in your npm modules and it will work atuomatically

from protractor.

startswithaj avatar startswithaj commented on May 5, 2024

+1 @eddiemonge. If your using something like coffeify in the rest of your project it wont work and will not throw an error. Because:

// Coffee is required here to enable config files written in coffee-script.
try {
  require('coffee-script').register();
} catch (e) {
  // Intentionally blank - ignore if coffee-script is not available.
}

from protractor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.