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
Running tests depending on esri-leaflet headlessly #969
Comments
I've realized that it might be better to take this up directly with the Leaflet folks, although there seems to already have been some discussion about it. |
in our own mocha/chai/sinon test suite we pre-load the compiled versions of both leaflet and esri-leaflet via the 'files' parameter in files: [
'node_modules/leaflet/dist/leaflet.css',
'node_modules/leaflet/dist/leaflet-src.js',
'dist/esri-leaflet-debug.js',
// then start loading our actual unit tests
], this allows us to instantiate classes based on compiled UMD class dependencies instead of relying on actual ES6 imports. // https://github.com/Esri/esri-leaflet/blob/0da3cf7e17bcd4ef1abd3970bac221b3881eb86a/spec/Services/FeatureLayerSpec.js#L1beforeEach(function () {
xhr = sinon.useFakeXMLHttpRequest();
// ...
service = L.esri.featureLayerService({url: featureServiceUrl});
}); |
@jgravois Please correct me if I'm wrong or misunderstand, but the only reason this works is that your tests are running in an actual browser environment where Thanks for the answer, but my issue is regarding loading Esri-Leaflet in a headless environment. Edit: a word |
i didn't realize that PhantomJS acts like a real browser. @patrickarlt do you have any ideas/suggestions for @colbin8r? |
i'm going to go ahead and close this issue as there's nothing actionable for esri-leaflet at the moment, but i'd be more than happy to discuss the issue further and/or talk about changes in this repo down the line if anyone can recommend something. |
I'm writing a plugin that uses Leaflet and Esri-Leaflet. For my plugin, I have a reasonably large suite of unit tests powered by Mocha, Chai, Sinon, etc. My plugin is structured as a series of ES6 modules.
In my unit tests, I
import { FeatureLayerService } from 'esri-leaflet'
, but this causes the tests to break becauseesri-leaflet
depends onleaflet
, which depends upon a globalwindow
resulting in aReferenceError: window is not defined
error in a headless environment like Node. I've been able to use pieces of Leaflet itself in my tests thanks to the leaflet-headless package, which sort of hacks over the globalwindow
dependency and allows me toimport { Map } from 'leaflet-headless'
and the like.My question is: because esri-leaflet has depends on leaflet and not leaflet-headless (and it obviously should), is there any way to allow my unit tests to run, perhaps by:
window
global (I've explored this some using jsdom with no luck)Version of Leaflet (
L.version
):1.1.0, 1.0.3
Version of esri Leaflet (
L.esri.VERSION
):2.0.8
Code I want to work:
Resulting errors:
npm ls | grep leaflet
:The text was updated successfully, but these errors were encountered: