Karma proxies are not working

2019-05-14 00:37发布

I am using Karma (v0.12.37) as test runner along with JSPM (v0.16.2). I have added following proxy config in karma so as to allow proper loading of JSPM files:

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

Bu this doesn't work out and fails on following:

PhantomJS 2.0.0 (Windows 8 0.0.0) ERROR: 'Potentially unhandled rejection [10] Error: XHR error loading http://localhost:9876/base/jspm_packages/npm/babel-core@5.8.22.js
        Error loading http://localhost:9876/base/jspm_packages/npm/babel-core@5.8.22.js
        Error loading http://localhost:9876/base/app/pages/examples/todo-example/todo.controller.test.js'

Debug Logs are giving:

proxying request - /base/jspm_packages/npm/babel-core@5.8.22.js to localhost:9876
/base/app/jspm_packages/npm/babel-core@5.8.22.js { host: 'localhost',
  port: 9876,
  baseProxyUrl: '/base/app/jspm_packages/',
  https: false }

But the following url containing 'app' in it works properly:

http ://localhost:9876/base/ app/ jspm_packages/npm/babel-core@5.8.22.js

Any clue on what is going wrong?

4条回答
放我归山
2楼-- · 2019-05-14 01:08

After having done lot of trial and error, found out the following way:

Instead of playing with proxies, alter the jspm paths config in karma.config.js

jspm: {
       ...
        paths: {
            "github:*": "app/jspm_packages/github/*",
            "npm:*": "app/jspm_packages/npm/*",
            'app/*': 'app/*.js'
        },

        ...
    },
查看更多
来,给爷笑一个
3楼-- · 2019-05-14 01:10

Try:

proxies: {
  '/app/': '/base/app/',
  '/jspm_packages/': '/base/jspm_packages/'
}
查看更多
戒情不戒烟
4楼-- · 2019-05-14 01:13

What finally did the trick for me (karma, babel, JSPM/SystemJS) was to have this:

Remove baseUrl from the karma.conf.js and have this jspm section:

 jspm: {
        config: 'config.js',
        loadFiles: [
            'www/**/*.spec.js'
        ],
        serveFiles: [
            'www/**/!(*spec).js'
        ],
        paths: {
            "github:*": "/base/jspm_packages/github/*",
            "npm:*": "/base/jspm_packages/npm/*",
            'www/*': '/base/www/*'
        }
    },
查看更多
时光不老,我们不散
5楼-- · 2019-05-14 01:34

If you have configured your jspm-config with a baseUrl of "/", try removing the baseUrl entry since karma-jspm does not support a custom baseUrl. Then you should be able to get rid of the "proxies" entry for the jspm_packages.

See: https://github.com/Workiva/karma-jspm/issues/91

查看更多
登录 后发表回答