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

Remove jQuery #45

Closed
wants to merge 30 commits into from
Closed

Remove jQuery #45

wants to merge 30 commits into from

Conversation

jeffjewiss
Copy link

@jeffjewiss jeffjewiss commented Sep 26, 2017

Removes jQuery as a dependency.

Fixes #37

todo:

  • get Node 4 running the tests on Travis and Appveyor
  • cleanup .travis.yml
  • confirm if Ember 1.13 can work with these changes
  • confirm Percy snapshots are the same as master branch

@@ -1,6 +1,10 @@
import Ember from 'ember';
import { getNativeXhr } from './native-xhr';
import { maybeDisableMockjax, maybeResetMockjax } from './mockjax-wrapper';
import $ from 'jquery';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

If you're interested in updating ember-cli-babel to version 6.3+ (I believe) you could also use the new Ember imports outlined here: https://github.com/ember-cli/ember-rfc176-data but that would likely be appropriate for another PR. There are tools to automate the change as well. Let me know if you're interested!

@jeffjewiss jeffjewiss changed the title [WIP] Remove jQuery Remove jQuery Oct 7, 2017
@jeffjewiss
Copy link
Author

Hi @fotinakis, this seems to be in a working state, but could use some further testing to make sure the proper snapshots are being taken. Regarding your previous instructions, should I be able to npm link this repo in the project where I have Percy setup and then run my tests with the access token present and it should upload snapshots to Percy? Then I can check to see that the snapshots look okay?

Also, I needed to change 1 test as it seems like there are still some Ember internals that use jQuery related to handling checkbox input events. I also updated some dependencies and had the tests run Node 6, and 8 instead of 4. I upgraded jshint to eslint as there is a plugin that helps with checking that jQuery isn't used in the add-on by enabling a linting rule. I used a tool called polyjuice to generate the eslint config from the preexisting jshint ones. Otherwise, I tried not to change things unrelated to removing jQuery or dependencies that could be left as is.

Please let me know when you have a chance to review this and if there are any changes you'd like to see before it's acceptable to merge. Thanks!

Copy link
Contributor

@fotinakis fotinakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffjewiss this is looking good, thanks for all the work here! Added some review comments here.

As for the tests, yes you can npm link it into a project to test (I will plan on doing that for our own projects before merging this). Also easier: just create a new project like test-ember-percy in percy, checkout master of this addon itself and run the tests pointed at that project, then checkout your branch locally and run the tests again to make sure nothing has changed. You can also run it locally with PERCY_BRANCH=test npm test to override the that Percy thinks it's coming from, which will default to master.

Let me know if that all makes sense or any questions on my comments here.

import { getNativeXhr } from './native-xhr';
import { maybeDisableMockjax, maybeResetMockjax } from './mockjax-wrapper';
import ajax from 'ember-fetch/ajax';
import run from 'ember-runloop';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of confused as to why this works, and can't find any references to doing it this way. Is there a preference for this over destructuring run off of the Ember object?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working because ember-cli-shims is included as a dependency. Destructuring from the Ember object is now generally not recommended.

Ember is slowly moving towards using separate packages, so the preference is to import from these packages so that when future improvements are added to the build process (tree-shaking with rollup) it will result in smaller build files.

import run from 'ember-runloop'; then becomes import { run } from '@ember/runloop'; and a list of these new module imports can be found here: https://github.com/ember-cli/ember-rfc176-data

The documentation and guides are also in the process of being updated as of [email protected] and you can see the beginning of this: https://emberjs.com/api/ember/2.16/classes/@ember%2Frunloop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense, thanks for the great explanation! Looks like I've been slacking on keeping my Ember knowledge up to date. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome, glad that was helpful. No worries, it's a lot of work to stay up to date. 😄

.travis.yml Outdated

install:
- mkdir travis-phantomjs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems in the testem config you updated it to not use phantomjs at all — which is 👍 , but I think this needs to be updated and cleaned up as well. You can probably just use Travis's normal method for making sure Chrome is available: https://docs.travis-ci.com/user/chrome

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay cool, looks like this was left over as I updated the Travis config in stages. I'll clean up the .travis.yml file.

.travis.yml Outdated
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-1.13
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-lts-2.4
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-lts-2.8
- PERCY_ENABLE=0 EMBER_TRY_SCENARIO=ember-lts-2.12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we have to break backwards-compatibility with Ember 1.13 as part of this change? If not, let's keep the ember-1.13 try here.

Overall, if it required to drop 1.13 support, we're probably ready for that and fine with it, just need to bump a major release of this after it is merged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look at getting Node 4 working on Travis first, and then try adding this back in.

These changes should work fine with Ember 1.13. I removed that version to use more recent versions of Ember and because there seemed to be some weird caching/installation behaviour with ember-try on Travis.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. If it ends up being a lot of work to get ember-try with 1.13 tests to work, then feel free to drop.

.travis.yml Outdated
@@ -1,19 +1,25 @@
---
language: node_js
node_js:
- "4"
- 6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd like to maintain Node 4 compatibility, especially because there are Node 4 LTS releases that don't fall out of maintenance until April 2018 (https://github.com/nodejs/Release).

Can you add back Node 4 here, and see comment below in package.json about Node 4 version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, no problem. I'll add that back in.

I initially removed it because I was able to have the add-on build and pass all the tests locally running Node 4, however Travis was throwing errors. The error seemed to be related to a missing "use strict;", but I had added it to the referenced file. So I think there may be a caching or other issue.

env: {
browser: true
},
globals: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you didn't have to have percySnapshot defined here, if eslint still passes then great.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests to use import { percySnapshot } from 'ember-percy';. This imports from the add-on instead of having to use the test helper.

I could either keep this method and remove the test helper, or revert to using the helper and add percySnapshot to the eslint globals. I thought it would be better to not use globals. Which do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah very interesting. So our current docs say to ignore it here and import our register-helpers module to install our Ember async helper, so that in acceptance tests you always rely on the global and it works well with the other async helpers like visit, click etc. This is required in normal acceptance tests so that it doesn't have to be nested in an andThen() to get into the right order.

Since you've migrated the tests here to ember-native-dom-helpers and are using await it may not matter anymore in this case, the only slightly weird part I can think of is that we like using this repository as an example of writing Percy tests the recommended way. I'm not sure of the state of grand testing unification, but we'll need to support the Ember async helpers workflow for a long while.

Just some thoughts, I don't really have strong feelings here either way — just wanted to point out the effect on our docs and our currently recommended workflow for acceptance tests. What do you think we should do here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation. I agree that consistency and being able to use this repo as an example of writing Percy tests is important. So with that in mind I added the percySnapshot global back in for tests. I think it makes sense to keep and support the async helper.

@@ -16,40 +16,46 @@
},
"repository": "https://github.com/percy/ember-percy",
"engines": {
"node": ">= 0.12.0"
"node": "^4.5 || 6.* || >= 7.*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to comment in travis.yml, we'd like to maintain backwards compatibility for Node 4.x releases if possible. Can you explain a bit more about this line change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled this engine setup from here: https://github.com/ember-cli/ember-cli/blob/master/package.json#L148

I've generally seen this mentioned as the recommendation by ember-cli and for ember projects/add-ons. I believe the idea is to support LTS versions of Node, but with the preference of a more stable version of 4.

@jeffjewiss
Copy link
Author

@fotinakis thanks for taking a look at this, I realize it's a big change.

Thanks for all the comments. I've answered each one and then added todos at the top of the PR for any outstanding tasks that came out of the comments. I'll work through them and ping you again when they're complete.

* upgrade ember-cli to 2.16
* config travis and ember-cli to test Ember 1.13
@fotinakis
Copy link
Contributor

@jeffjewiss thanks for all the hard work on this PR! Responded to a few comments above.

@jeffjewiss
Copy link
Author

@fotinakis I had to update the ajax call as the fetch API isn't the same as jQuery.ajax. In the process I also removed the mocks since jQuery isn't present and this should use native XHR by default.

I think I have all the issues fixed, however I ran out of builds on my Percy free trial. Would it be possible to get that reset or would you be able to take over confirming that the snapshots from this branch are the same as master?

@fotinakis
Copy link
Contributor

@jeffjewiss sorry for the delayed response here. Yes definitely, I've just extended your trial. We also are about to merge something in #47 that will have a tiny impact on this PR and need to be merged in.

* master:
  1.2.20
  Use afterTests to call finalize (percy#47)
  1.2.19
  Update percy-client dependency (percy#46)
@jeffjewiss
Copy link
Author

@fotinakis no problem! Okay great. Thanks for the heads up, I've merged master into this branch and made the appropriate updates to finalizeBuildOnce.

My snapshots are now uploading correctly. This revealed an issue with cloning textareas, but I was able to fix that with the last commit. I'm now seeing 37 snapshots and no visual diffs on my Percy Test Project which is just snapshots from this branch/PR.

I think this should be ready for a final review. 🎉

@jeffjewiss
Copy link
Author

Hey @fotinakis, just wanted to ping you on this and see if you had a chance to look at it. Cheers!

* master:
  1.2.21
  Upgrade pinned version of percy-client.
@jeffjewiss
Copy link
Author

Hey, just wanted to check in on this and see if anyone had a chance to take a look at it. Thanks!

@topaxi
Copy link

topaxi commented Jan 9, 2018

Ember.js is actively making jQuery optional, this would be a great time to get this landed 👍
emberjs/ember.js#16058

* master:
  TypeScript ambient type information (percy#50)
  1.2.22
  Update `ember-cli-babel` to v6.10.0 (percy#49)
@RobbieTheWagner
Copy link

How's this going @jeffjewiss @fotinakis? This is one thing keeping me from using Percy right now, since I need to remove jQuery from my apps. Do you guys need any help?

@jeffjewiss
Copy link
Author

Hey @rwwagner90, from what I remember this PR was working (tests passing, and uploading the correct snapshots) back in October when I posted the update. I didn't hear back re: feedback and haven't looked into why the most recent merge broke things.

@RobbieTheWagner
Copy link

@fotinakis what do we need to do to get this in?

@fotinakis
Copy link
Contributor

Closing in preference for #58

Thanks for pushing us to get this done @jeffjewiss. We decided on an interesting path that allows us to keep all of our current jquery-dependent behaviors in tests, while still allowing people to strip jquery from their production Ember builds.

@fotinakis fotinakis closed this Mar 20, 2018
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

Successfully merging this pull request may close these issues.

4 participants