Search code examples
javascriptdojointern

Intern4 and CDN resources


I'm testing out Intern 4 and I have some resources from a CDN that I want to test. In my intern.json I have the following.

{
  "loader": {
    "script": "dojo2",
    "options": {
      "packages": [
        { "name": "dist", "location": "dist" },
        {
          "name": "esri",
          "location": "https://js.arcgis.com/4.5/esri"
        }
      ]
    }
  },
  "environments": [
    {
      "browserName": "chrome",
      "chromeOptions": { "args": [ "headless", "disable-gpu" ] },
      "fixSessionCapabilities": false
    }
  ],
  "suites": "dist/tests/unit/app/main.js",
  "maxConcurrency": 2
}

But when I run my tests, I get the following errors with stacktrace from the @dojo/loader/loader.ts.

(ノಠ益ಠ)ノ彡┻━┻
Error: Failed to load module esri/core/promiseUtils from https://js.arcgis.com/4.5/esri/core/promiseUtils.js (parent: dist/tests/unit/app/main.js)

The file exists on the CDN, it just seems like the loader can't load it. Is this a limitation of Intern 4? I assumed running it in a headless Chrome session would work for this, but it doesn't seem to.

Thanks!


Solution

  • By default, suites in the "suites" list are run in Node as well as browser environments, and @dojo/loader doesn't support loading modules over URLs in Node. To only run suites in the browser, add them to the "browser" environment object, like:

    {
      "loader": {
        ...
      },
      ...
      "browser": {
        "suites": "dist/tests/unit/app/main.js"
      },
      "maxConcurrency": 2
    }