0

I'm writing integration tests for purescript FFI bindings with google's API map.

The problem Google's code is meant to be loaded externally with a <script> tag in browser not downloaded and run in a node process. What I've got now will download the relevant file as gmaps.js but I don't know what to do to actually run the file.

exports.setupApiMap = function() {
  require('dotenv').config();
  const apiKey = process.env.MAPS_API_KEY;
  const gmaps = "https://maps.googleapis.com/maps/api/js?key=" + apiKey;
  require('download')(gmaps, "gmaps.js");
  // what now???
  return;
};

For my unit tests, I must later be able to run new google.maps.Marker(...). Then I can check that my setTitle, getTitle etc. bindings are working correctly.

cheezsteak
  • 2,731
  • 4
  • 26
  • 41
  • Why you don't want to mock it? – Stranger in the Q Feb 22 '19 at 15:53
  • might want to look up puppetteer for running browsers programatically. – TKoL Feb 22 '19 at 15:53
  • @StrangerintheQ I'd like to run these test as a part of gitlab CI. I don't think I can run a browser in gitlab CI. But TBH I've never used browser mocking before. It might be the best answer. – cheezsteak Feb 22 '19 at 15:55
  • I meant mock marker object behaviour – Stranger in the Q Feb 22 '19 at 16:01
  • Unit tests was the wrong description, these really are integration-tests. The code I'm testing is just purescript FFI bindings, it doesn't really do anything but call external javascript. I need to check that I've written them correctly against the canonical source. – cheezsteak Feb 22 '19 at 16:15

1 Answers1

-2

This is a duplicate question of this one. The correct code was.

exports.setupApiMap = async function() {
  require('dotenv').config();
  const apiKey = process.env.MAPS_API_KEY;
  const gmaps = "https://maps.googleapis.com/maps/api/js?key=" + apiKey;
  await require('download')(gmaps, __dirname);
  const google = require('./js');
  return;
};

The key was to download to __dirname before using require. That said my specific use cases didn't work since google's API map code just can't be run in a node process. It must be run in a browser.

cheezsteak
  • 2,731
  • 4
  • 26
  • 41