Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Coffeescript preprocessor #38

Closed
lebek opened this issue Jul 22, 2013 · 30 comments
Closed

Coffeescript preprocessor #38

lebek opened this issue Jul 22, 2013 · 30 comments

Comments

@lebek
Copy link

lebek commented Jul 22, 2013

Is this within the scope of the project or would you rather see it as a plugin?

@juliemr
Copy link
Member

juliemr commented Jul 22, 2013

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!

@juliemr
Copy link
Member

juliemr commented Jul 22, 2013

Also @karlgoldstein who was also interested in this.

@lebek
Copy link
Author

lebek commented Jul 23, 2013

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.

@wizardwerdna
Copy link

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.

@searls
Copy link

searls commented Sep 2, 2013

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

@DavidMikeSimon
Copy link
Contributor

+1

@DavidMikeSimon
Copy link
Contributor

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.

@jfroom
Copy link
Contributor

jfroom commented Oct 24, 2013

@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.

@lebek
Copy link
Author

lebek commented Oct 25, 2013

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.

@bjorne
Copy link

bjorne commented Oct 29, 2013

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.

@jfroom
Copy link
Contributor

jfroom commented Oct 29, 2013

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

@alexurdea
Copy link

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

@matteosister
Copy link
Contributor

@alexurdea could you please provide an example?

@matteosister
Copy link
Contributor

I'm answering myself...something like:

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

@alexurdea
Copy link

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

@daniellmb
Copy link

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

myButton = element `by`.name 'foo'

@eddiemonge
Copy link
Contributor

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;

@JakeBecker
Copy link

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.

@eddiemonge
Copy link
Contributor

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.

@JakeBecker
Copy link

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.

@eddiemonge
Copy link
Contributor

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

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

juliemr pushed a commit that referenced this issue Jan 31, 2014
CoffeeScript now requires a register call to be made.

Ref #38
@flegall
Copy link
Contributor

flegall commented Mar 4, 2014

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

@eddiemonge
Copy link
Contributor

@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

@flegall
Copy link
Contributor

flegall commented Mar 4, 2014

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.

jonruttan added a commit to iwastenotsystems/web-app that referenced this issue Mar 5, 2014
  - remove hardcoded *specs* paths
  - template hardcoded *`port.test`*
  - change *CoffeeScript* require from `coffee-script` to
    `coffee-script/register` -- v.1.7.0 no longer autoregisters
    `*.coffee` extensions[^1]

[^1] See: <angular/protractor#38>
@jtomaszewski
Copy link

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

@eddiemonge
Copy link
Contributor

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

@aleks-sidorenko
Copy link

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

@zweifisch
Copy link

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

@eddiemonge
Copy link
Contributor

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

@startswithaj
Copy link

+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.
}

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

Successfully merging a pull request may close this issue.