nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

PhantomJS 2.0 Landed #175

Closed metaskills closed 7 years ago

metaskills commented 9 years ago

Just gonna drop this here:

https://github.com/ariya/phantomjs/wiki/PhantomJS-2

darky commented 9 years ago

I try to replace phantomjs binary from 1.x to 2.x And mocha-phantomjs not working with it now. Cli process simply freezes on infinite time.

nathanboktae commented 9 years ago

I downloaded the mac OS X binary and it would just die.

Yes they expliclity removed coffeescript so it won't work at all as is. We either need to just use JavaScript or compile to JavaScript as part of a distribution - I prefer the former.

Some other things to consider for a major release:

metaskills commented 9 years ago

OS X binary and it would just die

Same here.

just use JavaScript

That's cool with me.

metaskills commented 9 years ago

FYI, known issue for Mac download. I found this on their issues and am downloading it now.

https://github.com/eugene1g/phantomjs/releases

nathanboktae commented 9 years ago

Yup I got that too and ran our tests and found a bug and filed it already - ariya/phantomjs#12973. Could be some more too as there were about 5-7 failing tests. 2.1 is already being prepared.

nathanboktae commented 9 years ago

I want to talk more about splitting out the console and core parts here. For end users it doesn't matter, but it matters a lot for integrators, namely build plugin authors. Pinging all the ones I could find:

Integrators: would you be interested in moving over to a mocha-phantomjs-core module? this would save you a process fork, but also, we could revisit how the dependency to phantomjs is managed - I would imagine this core module to not declare it's dependency to phantomjs in npm (it's not a Node.js module, it's phantomjs, but there's no ppm or phantomjs package manager, so we piggyback on npm). So modules that depend on the core get to decide how it finds phantomjs - direct dependecy, peer, maybe consumed from some external config, whatever. I would imagine the CLI module, mocha-phantomjs to have a direct dependency on phantomjs (peer dependencies are a pain).

Thoughts?

bithavoc commented 9 years ago

:+1:

mrhooray commented 9 years ago

thanks @nathanboktae for taking the initiative

agree that cli/ghoul and grunt/gulp plugins are just different interfaces/frontends of core library. for example the gulp plugin only depends on lib/mocha-phantomjs.coffee

using phantomjs as peer dependency seems to be a reasonable compromise of many cases/concerns

hatched commented 9 years ago

Is there a timeline or task list for mocha-phantomjs to support phantomjs 2.0?

jokeyrhyme commented 9 years ago

Would it be possible for this core to support driving multiple versions of PhantomJS?

I actually find it useful that PhantomJS 1.9 is missing a few web platform APIs, so it would be terrific if I could run tests against both PhantomJS 1.9 and 2.x (and 3.x, etc).

rjharmon commented 9 years ago

I found that by transpiling the .coffee script to JS, and adjusting the launcher to use it, PhantomJS 2 runs my test suite without difficulty. 1.9 also works fine with that change. I'd suggest adjusting the build to use this technique short-term to fix the compatibility problem.

nathanboktae commented 9 years ago

Well a) we have no build as mocha-phantomjs.coffee is directly consumed b) we have supported phantomjs lib/phantomjs ... style execution that will break. Its a good time to do a major version to planning and executing that well is important.

rjharmon commented 9 years ago

That sounds fine - I'm a fan of good planning too. Meanwhile, it's borked :( ... Any way to include a .js version and probe phantomjs -v from the launcher? I know it's just a band-aid, but it's a band-aid with a purpose: not to replace planning for major version-bump, just to enable compatibility in short-term.

PJS2 users can always choose to use the .js version if they want direct phantomjs lib/phantomjs ... style. Their alternative to having a centrally-provided band-aid, is to hack their installation the way I described (which is its own type of bandaid, I admit).

Your call.

nathanboktae commented 9 years ago

Meanwhile, it's borked :(

What is? From your previous comment, sounds like you're fine.

I found that by transpiling the .coffee script to JS, and adjusting the launcher to use it, PhantomJS 2 runs my test suite without difficulty.

I had done this too, but a lot of tests were failing.

nathanboktae commented 9 years ago

I'd also like to remove the mochaPhantomJS global. I think we can listen on on onResourceRecieved event and monkey-patch mocha, removing the need for everyone to remember to do:

if (window.mochaPhantomJS) {
  mochaPhantomJS.run()
} else {
  mocha.run()
}
SirZach commented 9 years ago

subscribing. i need phantomjs v2 for the performance api

nathanboktae commented 9 years ago

I started work on this in the v4 branch. It's not pointing at phantomjs2 yet.

mislav commented 9 years ago

For my purposes, I've created a shim executable for phantomjs that detects if CoffeeScript files are being passed to PhantomJS 2.0 and transparently converts them to JS before they reach actual PhantomJS:

#!/bin/bash
set -e
phantomjs="$(which phantomjs)"

coffee-convert() {
  local file="${1?}"
  local dest="${file%.coffee}.js"
  [ "$dest" -nt "$file" ] || coffee -c "$file"
  echo "$dest"
}

if [[ $("$phantomjs" -v) != 1.* ]]; then
  args=()
  for arg; do
    if [[ $arg == *.coffee ]]; then
      arg="$(coffee-convert "$arg")"
    fi
    args[${#args[@]}]="$arg"
  done
  set -- "${args[@]}"
fi

exec "$phantomjs" "$@"

Use it like:

$ mocha-phantomjs --path ./my/phantomjs-shim
nathanboktae commented 9 years ago

Awesome that'll be great for people migrating or people wanting to keep writing tests in CoffeeScript.

nathanboktae commented 9 years ago

I have published 4.0.0-beta1 out now that uses mocha-phantomjs-core and phantomjs2. The biggest blocker is there are no official linux packages out for phantomjs2, so install fails on linux. If any linux users want to test this, I'd either use mocha-phantomjs-core directly or install it ignoring errors, if possible, then use the -p option to point it at your binary or have it in your path.

I need to update the readme in the v4 branch, but the breaking changes off the top of my head:

Issues:

mislav commented 9 years ago

I have published 4.0.0-beta1 out now that uses mocha-phantomjs-core

So what functionality does this project now add on top of mocha-phantomjs-core?

nathanboktae commented 9 years ago

The CLI. mocha-phantomjs-core is just phantomjs code. In fact I could make python and Ruby packages out of it for those developers, as there is no node.js code there.

nathanboktae commented 9 years ago

I unplublished 4.0.0-beta1 due to issues with phantomjs2 not working, which is a bad fork of phantomjs which properly has not gone to phantomjs 2 yet because there are no official binaries. (see Medium/phantomjs#288 and #192).

Anyone who was using 4.0.0-beta1 can use the git tag 4.0.0-beta1 or branch v4 (recommended). If you really want phantoms2, you can use that and put phantomjs in your path, use the -p flag, or use mocha-phantomjs-core and call phantomjs directly however you wish.

jonnor commented 8 years ago

Seems v4 has been merged to master now

nathanboktae commented 8 years ago

Yes, 4.0.0 is out but it is not on phantomjs2 so I didn't close this. After 9 months there's still resolution for the various linux distro binaries, and the npm bug where it does a phantomjs peerDependency of ^1.9.7-15 even though it specifies 1.9.1-1.9.7-15 was getting to be way to painful.

mwoc commented 8 years ago

https://github.com/Medium/phantomjs/issues/288 Phantomjs 2.1 is now live, so hopefully soon offered by the phantomjs npm package too

nathanboktae commented 8 years ago

Oh that's nice.

I am actually planning on moving away from depending on the npm package phantomjs due to issues like these, and I am working on support for slimerjs now and it's basically working. I want to switch to a BYOB Bring-your-own-binary style full on that mocha-phantomjs-core uses (You have been able to use phantomjs 2.0 with mocha-phantomjs-core for months now).

mmwtsn commented 8 years ago

PhantomJS v2.1.7 is out now. Any updates here?

jdcataldo commented 8 years ago

Support was added in v3.0 https://github.com/jdcataldo/grunt-mocha-phantomjs/commit/63b7ff33e3c7d0df423877ce9a9996403c3bde5e

Pomax commented 8 years ago

just ran into the SyntaxError: Parse error error (no information on what goes wrong, running in the browser shows zero console errors), is mocha-phantomjs ever updating to 2.x? Especially after a year and a half of "maybe"? =)

karlbright commented 8 years ago

Hi Mike, most likely no. This project was more an experiment in how it could work together. Nowadays testing like this is handled by other libraries in a much cleaner way. Karma is a good example of this and will run mocha tests with phantomjs, and other browsers, with just some simple configuration. On Sat, 16 Jul 2016 at 5:23 AM, Mike Kamermans notifications@github.com wrote:

just ran into the SyntaxError: Parse error error (no information on what goes wrong, running in the browser shows zero console errors), is mocha-phantomjs ever updating to 2.x? Especially after a year and a half of "maybe"? =)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nathanboktae/mocha-phantomjs/issues/175#issuecomment-233073366, or mute the thread https://github.com/notifications/unsubscribe-auth/AABQCnlUuCqnK9WkhC4Vv4BCQZgTuJb2ks5qV_pYgaJpZM4DaVuo .

nathanboktae commented 8 years ago

This project was more an experiment in how it could work together.

Don't speak on behalfof this project if your not a contributor, because that is not true at all.

mocha-phantomjs-core has been supporting phantomjs 2 for a year now and sliders as of recently. The gulp and grunt plugins got switched over too.

Long term plans are to incorporate the client functionality into core which will then eclipse this project.

mocha-phantomjs is simpler to setup than karma and gives you full control over the test runner HTML. But if you want to test other browsers beyond Firefox and phantomjs, go with Karma.

karlbright commented 8 years ago

Complete apologies. I had a similar repo with the same name at one point and got completely confused while looking at this from my phone. Sorry about that @nathanboktae. That's completely my bad. On Sun, 17 Jul 2016 at 9:43 AM, Nathan Black notifications@github.com wrote:

This project was more an experiment in how it could work together.

Don't speak on behalfof this project if your not a contributor, because that is not true at all.

mocha-phantomjs-core has been supporting phantomjs 2 for a year now and sliders as of recently. The gulp and grunt plugins got switched over too.

Long term plans are to incorporate the client functionality into core which will then eclipse this project.

mocha-phantomjs is simpler to setup than karma and gives you full control over the test runner HTML. But if you want to test other browsers beyond Firefox and phantomjs, go with Karma.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/nathanboktae/mocha-phantomjs/issues/175#issuecomment-233160472, or mute the thread https://github.com/notifications/unsubscribe-auth/AABQCqYXg7Iut0YBD1Je9ZAV6TwDSpfwks5qWYirgaJpZM4DaVuo .

nathanboktae commented 8 years ago

Ah ok thanks for the explanation

Pomax commented 8 years ago

@nathanboktae does that mean this issue doesn't need to stay open anymore?

As for my particular usecase, one of our files used ES6 syntax functions, i.e.:

...
  render() { // should have been "render: function() {" for phantom
    ...
  },
...

but mocha-phantom was only able to state the SyntaxError, not in which file it found it, or the line of code that triggered it; If that's a fixable thing that's probably worth fixing.

nathanboktae commented 8 years ago

If that's a fixable thing that's probably worth fixing.

It's not fixable. PhantomJS is based on QT3 for 1.x, and QT5 for 2.x and neither supports ES6. The JavaScriptCore, the JavaScript runtime that phantomjs uses has to be upgraded.

Pomax commented 8 years ago

I'm using fixable loosely - seeing the line in question and the file it was signalled in is just as good of course. The problem I had was seeing the equivalent of "something went wrong" without any additional information, so if phantom generates more data (file+line number for instance) but mocha-phantom right now doesn't proxy that to the console, that would be quite valueable to fix

ghost commented 7 years ago

just noticed that phantomjs is deprecated and was renamed to phantomjs-prebuilt. annoying to update dependencies and I noticed it's still at 1.9.x in the package.json.

jpgcode commented 7 years ago

Hi, can someone give an update on this one? This module is still using phantomjs 1.9.x, It is hard to upgrade it to version 2?

jpgcode commented 7 years ago

Nevermind, just read the above comments, it works with mocha-phantomjs-core. Please update this ticket or mark this project as deprecated in favor of mocha-phantomjs-core if this project will not be longer maintained.

nathanboktae commented 7 years ago

Yeah I need to move the command line parsing over to mocha-phantomjs-core before I can tell everyone to switch over. Also you can use phantomjs2 with this by pointing to the phantomjs2 binary with the-p option.

Pomax commented 7 years ago

@nathanboktae good idea to put that information prominently at the top of the README.md (probably in a short section after "Usage" titled "Using with Phantom 2.x" and then maybe even refer to that section already all the way at the start of the README.md doc?) rather than having it only as a comment in a closed issue. This information deserves some permanence, at least until the CLI parsing's been switched over.

nathanboktae commented 7 years ago

Good idea @Pomax I'll add it to the README.