jeudi 29 décembre 2016

Node, JSDOM, TinyMCE Script loading works in strange scenario only

I am running a node script with JSDOM, and attempting to load tinyMCE.

var fs = require('fs');
var jsdom = require("jsdom");
jsdom.defaultDocumentFeatures = {
  FetchExternalResources   : ['script'],
  ProcessExternalResources : ['script'],
  MutationEvents           : '2.0',
};

var tiny = fs.readFileSync("./node_modules/tinymce/tinymce.min.js", "utf-8");
var editors;
var tinyDoc = jsdom.env({
  html: "<p id='textarea'></p>",
  src: [tiny],
  scripts: ["//cdn.tinymce.com/4/tinymce.min.js"],
  done: function (err, window) {
    console.log(window.tinymce);
  }
});

According to the JSDOM documentation, http://ift.tt/t1YGLW we can either use src OR script, to grab from a url or in this case CDN. If, I do one without the other, logging window.tinymce returns undefined. Logging tiny, simply returns the string representation of the script, and therefore I cannot call any of it's methods. This implementation should not work.

What exactly is going on here. Attempting to load something like JQUERY by the way works exactly as intended and described by the JSDOM documentation.

Here is the link to the tinymce docs on how to load it under NPM. http://ift.tt/2ii1nIZ

Additonal Info- logging the window object, reveals that tinymce is added as a property to the window object twice, which at least makes sense, since the script is being included both through the, src option, and the scripts option. But again I would love to understand why it is not being added to the window object without having both.




Aucun commentaire:

Enregistrer un commentaire