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

Tests: Replace PhantomJS with Karma/Chrome #295

Closed
wants to merge 5 commits into from

Conversation

dmethvin
Copy link
Member

As part of this I also had to pull out the coverage code, which already seemed to be broken anyway, since it also used PhantomJS.

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

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

Is this based on Core changes?

Two things:

  1. The Travis config changes need to be migrated from Core as well.
  2. Some tests are failing in Chrome Headless, they need to be fixed before landing this.

@dmethvin
Copy link
Member Author

This is failing right now, it seems because it needs sudo set in the Travis config. @timmywil @Krinkle before just blindly doing that would you mind looking at what I've set up and see if there is anything else required? It runs locally. I think I probably need some additional incantations in the Travis file besides sudo.

@dmethvin
Copy link
Member Author

ohai @mgol ! what tests are failing? Nothing was failing locally.

@mgol
Copy link
Member

mgol commented Mar 13, 2018

As for sudo, as the Core Travis file says, it's currently required or Karma can't access the browser. You also need to add the chrome add-on:

addons:
  chrome: stable

Have a look at https://github.com/jquery/jquery/blob/master/.travis.yml, it's not that complex.

@mgol
Copy link
Member

mgol commented Mar 13, 2018

Tests are fine, false alarm. This is because our npm scripts setup is not ideal. npm install && npm test (known also as npm it) should work without further actions and currently you need to first build manually.

Core's package.json is, again, a good indication in what we may want here as well:
https://github.com/jquery/jquery/blob/365284240429d442c3fbe9f505c7b297425bc3a3/package.json#L73

@mgol
Copy link
Member

mgol commented Mar 13, 2018

Oh, the Travis ticket linked from Core's Travis config (i.e. travis-ci/travis-ci#8836) is fixed now. Perhaps you just need to add the chrome add-on now?

@mgol
Copy link
Member

mgol commented Mar 13, 2018

...and if just adding the Chrome add-on doesn't work you may want to try disabling the Chrome sandbox, here's how:
karma-runner/karma-chrome-launcher#158 (comment)

If that helps, please configure it so that on a local machine it doesn't use this sandboxless Chrome, only on Travis.

@Krinkle
Copy link
Member

Krinkle commented Mar 13, 2018

Yeah. Chrome’s sandbox doesn’t work anymore inside Docker containers as of a few releases ago. For the moment either requires VM/sudo, or disabling the sandbox via Karma. Could be conditional inside Gruntfile based on a Travis env var.

@mgol
Copy link
Member

mgol commented Mar 14, 2018

Thanks, Timo. I've tried it and it works! See the Core PR: jquery/jquery#4011

@dmethvin you can do something like what I did in Core.

@dmethvin
Copy link
Member Author

Thanks @mgol, the tests seem to be working now. Do the changes look good to you?

Gruntfile.js Outdated
@@ -100,6 +84,65 @@ module.exports = function( grunt ) {
}
}
},
karma: {
options: {
customContextFile: "karma/context.html",
Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% sure, but it seems like we don't need the custom files. With the custom things for core removed, it looks like they're just the default now. Do the tests can pass without these files?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Krinkle the standard file seems to run fine, but when i use the debug file I don't see any output on the screen. Also, on Windows although I can run the tests for debug I'm not sure how to exit the browser it launches in a way that Karma understands it was successful. If I close the browser it thinks Chrome crashed so it tries to relaunch 2 times and then hangs my command prompt.

mgol
mgol previously requested changes Mar 20, 2018
.travis.yml Outdated
addons:
chrome: stable
env:
- NPM_SCRIPT=test:browserless
Copy link
Member

Choose a reason for hiding this comment

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

We don't have such an npm script in Migrate. You might want to migrate that from Core if you want but for now it seems you can just remove the whole env block?

@dmethvin
Copy link
Member Author

I've removed the custom files. It looks like I can still debug locally and the tests pass. When I'm debugging should I actually see the QUnit tests in the window? I don't, although I can still debug and see the results from the console which is enough I suppose.

@Krinkle
Copy link
Member

Krinkle commented Mar 22, 2018

@dmethvin Yeah, the HTML is all there, so it is using the regular "Web/HTML" reporter of QUnit, but karma-qunit doesn't load the css file by default and doesn't create the <div id="qunit"> by default.

However, it will do both of those things if you set client.qunit.showUI = true in the Gruntfile/karma settings. Per karma-qunit#readme (lib/index.js#L15-L16, and src/adapter.js#L27-L31).

Should be harmless to just enable always.

@dmethvin
Copy link
Member Author

Thanks @Krinkle! That fixes the display issue. There is still a problem with Karma detecting that I've closed the debugging browser. Not sure how to deal with that, any ideas? That issue isn't blocking anything though. I really want to land this soon to finish some other PRs stuck behind it. I think @mgol is traveling now so if it looks good to you I'll land it.

@Krinkle Krinkle dismissed mgol’s stale review March 22, 2018 02:57

Issue was resolved.

@dmethvin dmethvin closed this in e4e6ee3 Mar 22, 2018
@dmethvin dmethvin deleted the karma branch May 27, 2019 02:49
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.

3 participants