computmaxer / karma-jspm

Other
74 stars 50 forks source link

Error loading files #24

Closed Frikki closed 9 years ago

Frikki commented 9 years ago

Directory structure:

/
|---app
|    \---myapp.js
|---jspm-packages
|---spec
|    \---myapp-spec.js
|---config.js
\---karma.conf.js

In karma.conf.js:

jspm: {
    loadFiles: [ 'spec/**/*-spec.js' ],
    serveFiles: [ 'app/**/*.js' ]
}

When I run karma, files in the app directory are not loaded, as karma prefixes the path with base/. How do I solve this?

lewisl9029 commented 9 years ago

I'm seeing this issue too on v1.1.1.

SystemJS under karma tries to load from /base/jspm_packages/ whereas my actual modules folder is at /www/jspm_packages/ as configured in package.json.

Seems like the SystemJS baseURL for karma-jspm is hard-coded atm: c14be8ae3f5745cec542bf40ffa36eb35a5220aa

maxwellpeterson-wf commented 9 years ago

All files served by karma's built-in server need to be prefaced with /base as that is where it serves them from. The files being served must at least be included in serveFiles or loadFiles options.

If your jspm_packages are in /www/jspm_packages/ you will need to change your jspm packages configuration to www/jspm_packages/ directory like so:

jspm: {
    packages: "www/jspm_packages/"
}

It will then make a request to /base/www/jspm_packages/ which should resolve correctly.

lewisl9029 commented 9 years ago

Hi,

I do have this set in karma.conf.js:

    jspm: {
      packages: 'www/jspm_packages/',
      loadFiles: [
        'www/**/*-test.unit.js'
      ],
      serveFiles: [
        'www/**/*.js'
      ],
      config: 'www/config.js'
    },

But I still get

WARN [web-server]: 404: /base/jspm_packages/github/angular/bower-angular@1.3.8.js

when I do

import angular from 'angular';

in my test.

As a side note, the test completes properly when I change this from the generated www/config.js:

System.config({
  "paths": {
    ...
    "github:*": "jspm_packages/github/*.js"
  }
});

to

System.config({
  "paths": {
    ...
    "github:*": "www/jspm_packages/github/*.js"
  }
});

But then module loading in my application breaks down.

Looks like my issue has something to do with config.js being placed in a different location from karma.conf.js, and thus using different relative paths (and the jspm.packages config in karma.conf.js doesn't seem to be working?). Doesn't look like this is the case for Frikki though.

djindjic commented 9 years ago

Hi @lewisl9029, I've just followed your config and it has help me very much, thanks! I found an solution latest problem, so you can set karma proxies to get it work without changing config.js. Somethink like this:

proxies: {
  '/base/jspm_packages/': '/base/www/jspm_packages/'
}

Also, I want to ask @maxwellpeterson-wf are jspm.packages and jspm.config settings removed? I cant find it in issues but it seems to be true. It sounds so logical for me because package.json already has this configuration. I'm not an node expert but does it possible to eliminate need for proxies with this package.json config too?

capaj commented 9 years ago

@djindjic that proxy works for you? I have no idea why but I cannot get a proxy to a directory work at all. I always have to spin up another node server running on different port and use it as base. Like this: https://gist.github.com/capaj/8db4533c3a1cab1bf930

Could you post your full karma.conf.js?

djindjic commented 9 years ago

You can take a look to my jspm-sample project I'm very interested to hear your opinion about my workflow if it works for you.