0

I am launching my Intern-based tests through the intern-runner script, like this:

<full_path>\intern\.bin\intern-runner config=unittest/intern

My unittest\intern.js configuration file contains the following:

define({
reporters: [ "junit", "console", "lcovhtml", "runner" ],
excludeInstrumentation: /(?:dojo|intern|istanbul|reporters|unittest)(?:\\|\/)/,
suites: [ "unittest/all_intern.js" ],
forDebug: console.log("Customized intern config for test runner loaded successfully!"),
loader: {
  packages: [
             { name: 'resources', location: 'abc/resources' },
             { name: 'stats', location: 'abc/resources/stats' },
             { name: 'nls', location: 'abc/nls' },
             { name: 'widgets', location: 'abc/widgets' },
             { name: 'views', location: 'abc/views' },
            ]
},

useLoader: {
  'host-browser': 'node_modules/dojo/dojo.js'
},
tunnel: 'NullTunnel',
useSauceConnect: false,
webdriver: {
  host: 'localhost',
  port: 4444
},
proxyUrl: "http://localhost:8010/",
environments: [
               {
                   browserName: 'chrome'
               }
           ]

});

Output to the terminal/command window looks hopeful:

Customized intern config for test runner loaded successfully!
Listening on 0.0.0.0:9000
Starting tunnel...
Initialised chrome 40.0.2214.111 on XP

And the Chrome browser is indeed launched, and I see my unittests running and passing in the browser contents. However, control never goes back to the terminal/command window--I don't see anything like "634/634 tests pass" or whatever, and I have to Ctrl+C to kill the intern-runner process. And of course, no code coverage files are generated. Is this due perhaps to my file structure? The Intern files are in a completely separate directory from these unit tests--I am not invoking intern-runner from a common parent directory for both Intern libraries and unit test files (and the product files they are testing).

I can create a diagram to illustrate the file/directory structure, if that is important. Note that I did change the Intern structure a bit, like:

<Dir_123>\intern\intern-2.2.2\bin\intern-runner.js
<Dir_123>\intern\intern-2.2.2\lib\<all_the_usual>
<Dir_123>\intern\intern-2.2.2\node_modules\<all_the_usual>
<Dir_123>\intern\.bin\intern-runner.cmd

i.e., what I had changed was to insert an extra "intern-2.2.2" directory after "intern", and the ".bin" directory containing intern-runner.cmd is a peer of "intern-2.2.2". Hope this is not confusing. :(

And note that the "proxyUrl" config property represents the URL that the unittest files and product files are available from the web server. Am I doing this right, by configuring the proxyUrl for this purpose? If I omit it, nothing runs because the default used is localhost:9000. I see in the "Configuring Intern" article on Github that proxyUrl is "the URL to the instrumentation proxy," but I don't really understand what that means.

sparkles
  • 33
  • 6

1 Answers1

0

It looks like you're making pretty good progress. Your directory structure is a bit non-standard (any particular reason for that?), but that shouldn't be a show-stopper. The problem you're seeing is probably due to a proxy misconfiguration. Intern is loading the test client and your unit tests, but the code in the browser is unable to communicate test results back to Intern.

As you mentioned, the proxyUrl parameter is the URL at which Intern's instrumenting proxy can be found. The "instrumenting proxy" is basically just an HTTP server than Intern runs to serve test files and to receive information from browsers under test. (It also instruments JS files as it serves them to gather code coverage data, hence the "instrumenting" part of the name.) By default, it's at localhost:9000. That means a browser under test running on localhost can GET or POST to localhost:9000 to talk to Intern.

You can also run Intern behind another server, like nginx, and have that server proxy requests to Intern. In that case, you need to 1) set Intern's proxyUrl to the address of the proxying server, and 2) setup proxying rules in the server to pass requests back to Intern at localhost:9000.

Intern also has a proxyPort parameter to control the port the instrumenting proxy serves on. The proxy listens at localhost:<proxyPort>, where proxyPort defaults to 9000. If tests are talking to Intern's proxy directly (with no intermediate nginx or Apache or anything), proxyPort will be the same as the port in proxyUrl. If an intermediate server is being used, the two can have different values.

When intern-runner runs unit tests, it tells the test browser to GET <proxyUrl>/client.html?config=.... Since you have some external server running and you've set proxyUrl to that server's address, that server will serve client.html and the other relevant Intern files, allowing the unit tests to run. However, when the unit tests are finished and the browser attempts to communicate this back to Intern at proxyUrl, it's going to fail unless you've configured the external server to proxy requests back to localhost:<proxyPort>.

jason0x43
  • 3,363
  • 1
  • 16
  • 15
  • Ooh, I did not realize that Intern started a proxy server! (Started from lib/createProxy?) I commented out the proxyUrl property in my config and ran, and while I can see that client.html is served up okay, I know there will be problems finding the product files and the Dojo modules they reference (*not* within Intern's copy)--since I don't see how these files can be served up by the Intern proxy. It sounds like I need a reverse proxy. Is it unusual to have an additional web server involved when running with intern-runner? Are there any examples of this sort of configuration out on the web? – sparkles Feb 22 '15 at 04:27
  • It's not too unusual to run Intern behind a secondary web server. However, Intern still needs to serve your application files through it's proxy to gather coverage data, since it's the instrumentation Intern inserts into files while serving them that generates this data. – jason0x43 Feb 22 '15 at 13:36
  • As I feared, I get 404s when something tries to resolve a module like "dojo/topic," referenced by a test. How does the proxy server understand how to serve the non-Intern Dojo files? I've tried adding to loader.packages in the config file { name: 'dojo', location: '../../../build/dojo/dojo'} which is a file path relative to location of the config file, and of course that doesn't work. I'm surprised that the server can find my unittest and product files; how to tell the server, "These are where the Dojo files are located?" I don't want my tests to use the Intern Dojo. – sparkles Feb 22 '15 at 20:44
  • When I read about baseUrl in the new user's guide ("Common configuration"), I understood what to do for proxy server to serve my Dojo files. Thank you, author! But now I'm back to the problem of the runner process hanging, though terminal and browser show test results. Chrome console shows " Tests complete" logged by webdriver.js, but terminal never outputs table with "% Stmts", "% Branches", etc and the process doesn't end until I kill it. I don't see any 404s like last time (when I was unnecessarily running my own web server). What else could be wrong? What in Intern ends the session? – sparkles Feb 23 '15 at 16:08