computmaxer / karma-jspm

Other
74 stars 52 forks source link

karma tests returning 404 #182

Closed seanrkerr closed 7 years ago

seanrkerr commented 7 years ago

I'm using systemjs & typescript, karma-jspm to run my unit tests I'm getting this 404 error below, I know that it's related to the base path but not sure how to fix.The things is, when I run the server everything is fine, it's only when I run karma the error starts appearing.

My app structure is pretty simple:

app/ 
   /tests
   /components
   /services

My systemjs configuration is, the file has been short end a little.

System.config({
  baseURL: (typeof __karma__ !== "undefined") ? "." : "./",
  defaultJSExtensions: (typeof __karma__ !== "undefined") ? false : true,
  transpiler: "typescript",
  typescriptOptions: {
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "tsconfig": true
  },
  paths: {
    "npm:*": "jspm_packages/npm/*",
    "github:*": "jspm_packages/github/*"
  },

  packages: {
    "app": {
      "main": "main",
      "defaultExtension": "ts"
    }
  },

And my karma configuration:

 module.exports = function(config) {
        config.set({

        basePath: './',

        frameworks: [
            'jspm',
            'jasmine'],

        plugins: [
            'karma-jspm',
            'karma-jasmine',
            'karma-chrome-launcher',
            'karma-phantomjs-launcher'
        ],

        jspm: {

            config: 'config.js',

            stripExtension: false,

            loadFiles: [
                'app/tests/**/*.ts'
            ],

            serveFiles: [
                'src/**/!(*.spec).ts'
            ],

            paths: {
                'systemjs': 'node_modules/systemjs/dist/system.js',
                'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
                'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js',
                'phantomjs-polyfill': 'node_modules/phantomjs-polyfill/bind-polyfill.js'
            },

            proxies: {
                "/app" : "/base/app", "/jspm_packages" : "/base/app/jspm_packages", "app/tests" : "/base/app/tests"
            }

        },

        preprocessors: {
        },

        exclude: [
        ],

        reporters: ['progress'],

        port: 9876,

        colors: true,

        logLevel: config.LOG_INFO,

        autoWatch: true,

        browsers: ['Chrome' ], // , 'Chrome'], <-- uncomment for Chrome testing

        singleRun: false,

        concurrency: Infinity
    })
}

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9876/app/tests/my.component.spec.ts Error: XHR error (404 Not Found) loading http://localhost:9876/app/tests/my.component.spec.ts Error loading http://localhost:9876/app/tests/my.component.spec.ts