I've started using WeakMap, a new feature available in ES6, which is well supported by WebKit core and is working on our local and review servers when testing manually in the browser. In the latest version of phantomjs though, my tests are failing with:
ReferenceError: Can't find variable: WeakMap
ReferenceError: Can't find variable: WeakMap
at http://127.0.0.1:63472/assets/application.js:61222
at http://127.0.0.1:63472/assets/application.js:61264
Minor details: Occurs in a Rails 4.2 project with Capybara and Poltergeist.
Yes, unfortunately, PhantomJS is not keeping up with Webkit at the moment - I think our version is currently about a year old.
We will eventually pick up a browser core with WeakMap support, but we're not going to start cherry-picking web platform features. I regret I don't have a time frame for you.
Any news on this? I'm having the same issue with PhantomJS 2.1.1 . Thanks! :)
+1
+1
Is there a reason this was closed? Not supporting WeakMap seems to cause problems on React.js pages.
Ended up abandoning PhantomJS and implementing a new solution using NightmareJS and Electron in a headless environment with an optional Docker wrapper: https://github.com/binarydev/dreamcatcher
Track ES6 support in #14506.
@binarydev if the issue is related to WeakMap support for PhantomJS while running tests with Karma, then in your karma.conf.js just add a line files: ['./node_modules/babel-polyfill/dist/polyfill.js', and don't forget to replace phantom-polyfill package with babel-polyfill. Then you can still use PhantomJS for tests.
@o1dnik I did what you suggested, and I am still get this error.
`
[ERROR - 2016-11-20T23:46:16.091Z] Session [80ab3180-af7b-11e6-8329-999df902fd21] - page.onError - msg: ReferenceError: Can't find variable: WeakMap
phantomjs://platform/console++.js:263 in error
[ERROR - 2016-11-20T23:46:16.092Z] Session [80ab3180-af7b-11e6-8329-999df902fd21] - page.onError - stack:
CompositeKeyWeakMap (http://localhost:19001/assets/vendor.bundle.js:56038)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:54459)
__webpack_require__ (http://localhost:19001/assets/vendor.bundle.js:51)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:73822)
__webpack_require__ (http://localhost:19001/assets/vendor.bundle.js:51)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:54382)
__webpack_require__ (http://localhost:19001/assets/vendor.bundle.js:51)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:73719)
__webpack_require__ (http://localhost:19001/assets/vendor.bundle.js:51)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:74022)
__webpack_require__ (http://localhost:19001/assets/vendor.bundle.js:51)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:117)
__webpack_require__ (http://localhost:19001/assets/vendor.bundle.js:51)
(anonymous function) (http://localhost:19001/assets/vendor.bundle.js:94)
`
On my end, the babel-polyfill trick fixed the problem.
Most helpful comment
@binarydev if the issue is related to
WeakMapsupport for PhantomJS while running tests with Karma, then in yourkarma.conf.jsjust add a linefiles: ['./node_modules/babel-polyfill/dist/polyfill.js',and don't forget to replacephantom-polyfillpackage withbabel-polyfill. Then you can still use PhantomJS for tests.