-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
baseURL in config.js causes 404s #91
Comments
For me it actually works, so maybe I can help. I am running
config.js
We keep sources and their spec in the same folder tree. |
Thanks bjorm, but the issue is with non-empty baseURLs in config.js: e.g., "baseURL": "/js" |
Same problem. I don't understand how this could possibly work. I keep sources and specs in parallel directories. A working example would be great. |
karma-jspm currently does not support projects that use a custom I just attempted a fix that looks something like this in adapter.js: var baseURL = karma.config.baseURL ? 'base/' + karma.config.baseURL : 'base';
System.config({ baseURL: baseURL }); The idea here is that you would configure a But that doesn't work. It seems that if baseURL is set in config.js, the call to |
@maxwellpeterson-wf hey, sure it should actually be possible to know the baseURL by:
Yes there is an issue with setting the baseURL last these days as it needs to be set before any other config is loaded due to config normalization. This should be possible by moving the config file to be loaded after the adapter in the ordering at https://github.com/Workiva/karma-jspm/blob/master/src/init.js#L99. |
I second @nateabele - an example would be great. |
This seems to work okay for me in my config.js System.config({
defaultJSExtensions: true,
transpiler: "babel",
baseURL: window.__karma__ ? "base" : "/",
...
}); My file structure is like this:
Still a hack, I know. Edit: This will also run in node: baseURL: (typeof __karma__ !== "undefined") ? "base" : "/", Edit 2: |
I have created a basic working project: #98 |
I was able to resolve my problems after much trial and error with the following configuration. My file structure is like this:
This is the baseURL in my
This is the baseURL in my
Here's my
I found that all of those An example of a test file does its imports like this:
|
@zewa666 Had PR'd a fix for this in v1 that seems to have been lost. Unfortunately for Aurelia users you will need to move your baseURL setting in to your index.html or w/e view so that it is ignored while running tests until this is fixed :( |
+1 |
1 similar comment
+1 |
2 more cents, as I had a related issue when playing with Aurelia's minimal app and transform it to use a non-flat project structure. Everything went fine until I changed jspm's Replacing the jspm's config file's My temporary workaround to solve this problem was therefore to automatically generate a karma-specific jspm config file with the correct That said, with a little bit of manual debugging, I could see that, when the page is loaded in the client:
Basically, my understanding is that I hope it's clear enough, that's all I could find with my relatively shallow knowledge of jspm and node.js. |
@tkhyn I can validate your findings! After I tried a whole week to get karma-jspm to run with my React setup, I tried your approach and now all tests run smoothly. |
I'm completely lost on this. I can't even remove the baseUrl from the config.js because remapping the paths somehow adds base twice the base XHR error (404 Not Found) loading http://localhost:9876/base/base/studio I guess we can forget about a fix for this issue given the time it has been open. But I don't see what the alternatives are. What would you recomment that I move my sources and jspm_packages to /base or did some of you do a custom systemJS load (i.e. not using this library?) |
maybe try karma-systemjs |
@martinsson what I do as a workaround is have a gulp task that copies the config.js to config-test.js and modifies the baseURL on the fly before running the tests. |
For 0.17 beta users, the following has worked for us. Assuming your code lives in // <project-root>/static/jspm.browser.js
SystemJS.config({
baseURL: "/static",
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*",
}
}); // <project-root>/static/jspm.karma.js
SystemJS.config({
baseURL: "", // notice the empty baseURL, also seems to work with "/base"
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*",
}
}); // <project-root>/karma.conf.js
basePath: 'static',
jspm: {
config: 'jspm.config.js',
browser: 'jspm.karma.js', // <-- not 'jspm.browser.js'
packages: 'jspm_packages',
stripExtension: false,
// app files
serveFiles: [],
// test files
loadFiles: [],
}, |
Thank you guys for the tips I'll have to give jspm it another try |
…e on it. As I understand it the problem is that my jspm config has a baseUrl (because I serve everything up from `public`) and karam-jspm doesn't work with it. I should probably have just written my own loader, but there you go. Useful resource - computmaxer/karma-jspm#91 (comment)
If you're still experiencing the 404-issues with Karma and JSPM: Note: Previously, I used the workardound that was mentioned by NervosaX (see above):
But as the file 'config.js' will be overwritten each time as 'jspm install' is executed, this solution was abandoned. Instead, I'm using now the following proxy setting in my karma.conf.js:
FYI: my project structure is as follows:
And my full karma.conf.js:
I hope this helps you. |
Using a function to make a copy of the config-file, and make som adjustments works fine :)
|
Angular has the same problem but I don't know how to apply the jspm config to another karma.conf. |
Struggling with the lack of documentation or working example:
I can't tell if this is the same issue a bunch of people seem to be having (#68)
I have a baseURL spec in my config.js; this is my global config, so I don't want to change it for the sake of karma (I'm assuming the intent is that karma-jspm should be made to work with the same runtime config?)
So in my karma.conf.js:
But I get 404s
By trial and error changing "paths" and "proxies" I can get different errors, but no solution. E.g.,
The docs are not clear about how this is supposed to work.
The text was updated successfully, but these errors were encountered: