Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading dependencies outside of the Intern directory when running tests through Selenium

Tags:

intern

I have a project where Intern unit tests are supposed to be in a different directory tree than the source code under test. Somewhat like this:

projectRoot
projectRoot/src
projectRoot/tests
projectRoot/tests/intern.js
projectRoot/tests/node_modules/intern
projectRoot/tests/MyTestSuite.js

In the Intern configuration file, I define an AMD package that uses relative paths with ../ to reach src from the unit test suites. Here's an example configuration:

define({
  environments: [ { browserName: 'chrome', platform: 'WINDOWS' }],
  webdriver: { host: 'localhost', port: 4444 },
  useSauceConnect: false,
  loader: {
    packages: [
          { name: 'testSuites', location: '.' },
          { name: 'externalDep', location: '../src' }
        ]
  },
  suites: [ 'testSuites/MyTestSuite' ]
});

And a matching unit test suite

define([ "intern!tdd", "intern/chai!assert","externalDep/ExternalDep"],
  function(tdd, assert, ExternalDep) {
    tdd.suite("Suite that has external dependency", function() {
      tdd.test("Test if external dependency is loaded correctly", function() {
        assert(ExternalDep === "hello");
      });
    });
  }
);

This works fine when tested directly in the browser (client.html) or node (client.js). When fired off through a Selenium Server (with runner.js), however, the client.html running in the browser started by Selenium can't find the external dependencies. In the above example, it tries to request ExternalDep at http://localhost:9000/__intern/src/ExternalDep.js, which is a 404 because the src directory is not within intern.

I suppose that if I put intern.js at the highest common super-directory of both the tests and the source code, it would work. But our project is currently set up in a way which makes that impractical. Is there a way for configuring sources that live beyond the location of the Intern config file, or did I just make a silly mistake?

Thanks!

like image 299
joejohndoe Avatar asked Apr 03 '14 15:04

joejohndoe


1 Answers

There is no problem putting the tests in a different directory from the rest of the code, but projectRoot needs to be the working directory from which you start the runner, and you need to change your loader configuration to match.

So, instead of right now where you are starting Intern from projectRoot/tests like this:

…/projectRoot/tests$ ./.bin/intern-runner config=intern

you need to start it from projectRoot:

…/projectRoot$ ./tests/.bin/intern-runner config=tests/intern

…and change your loader configuration:

  loader: {
    packages: [
          { name: 'testSuites', location: 'tests' },
          { name: 'externalDep', location: 'src' }
        ]
  },
like image 189
C Snover Avatar answered Oct 02 '22 16:10

C Snover