karma icon indicating copy to clipboard operation
karma copied to clipboard

Get rid of the "base" directory

Open tkrotoff opened this issue 8 years ago • 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.

tkrotoff avatar Oct 05 '15 17:10 tkrotoff

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

ghost avatar Oct 22 '15 14:10 ghost

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

victor-xiong avatar Nov 12 '15 21:11 victor-xiong

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

jcrben avatar Nov 15 '15 01:11 jcrben

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

jeremyroberts0 avatar Dec 31 '15 19:12 jeremyroberts0

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 avatar Jul 12 '17 17:07 jamesdanged

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

franktopel avatar Nov 19 '19 12:11 franktopel

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.

Krinkle avatar Nov 21 '20 00:11 Krinkle

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.

johnjbarton avatar Nov 26 '20 01:11 johnjbarton