karma-runner/karma

Get rid of the "base" directory

Opened this issue · 8 comments

Following a question I've asked (without success) on the mailing-list few months ago: Why a directory named "base" is prepended to all the loaded files?

With Karma all files are inside a directory named "base". I don't see the need for this added complexity.

karma

In comparison, when using Jasmine directly (gulp-jasmine-browser or by writing my own SpecRunner.html), there is no "indirection": all files are loaded from the root directory => much easier, the way it should be.

gulp-jasmine-browser

  • I have to prepend "base" to my XHRs for them to work (or add "urlRoot: 'base'" to karma.conf.js => does not work anymore). I'm not the only one in this case: https://github.com/pizzapanther/Karma-Read-JSON/blob/v1.1.0/karma-read-json.js#L27.
  • This makes it difficult to run unit tests using both Karma and (original) Jasmine.
  • Also source maps don't work (I use TypeScript) when debugging my tests using Karma singleRun: true.
    In Chrome when I click on a .ts file, I get a 404 because Karma tries to fetch /base/Hello.spec.ts instead of /Hello.spec.ts.

+1, base is making things hard, especially interoperability with different test systems.

+1, html page setup with karma 'base' will not be able to be open correctly by other web servers.

If nothing else, we should figure out what advantages (if any) the base prefix provides.

+1, this is a regular source of annoyance in XHR paths.

Seems there is now an easy way to deal with this by using the "proxies" setting. See http://karma-runner.github.io/1.0/config/files.html >> Loading Assets.

@jamesdanged Can you show an example of how to address this problem using the proxies setting?

Proposal:

  • Let Karma start two servers. One for serving the base directory and client start HTML (e.g. localhost:9876), and another for its own files and web sockets (e.g. localhost:9842).
  • The base server would essentially be a plain static file server with / relating to the base directory (e.g. no more /base path, direct root of your git project). The server would have one "virtual" file, e.g. "/" itself from which it serves the client HTML that kicks off the test. We may want to make this virtual name configurable, so that e.g. one could instruct it to be served from and opened from /test/karma.html, for even better compatibility with a real HTML one might have at /test/qunit.html in that same directory - so that any relative URLs are resolved the same way.

FWIW I don't know why base. The middleware code seems too compact and difficult to follow. We've wondered if we could rework it with express somehow.